Vertically Stretch Background Image - Css - Stack Overflow

Just browsing Stack Overflow? Help us improve your experience. Sign up for research
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs Vertically stretch background image Ask Question Asked 12 years, 2 months ago Modified 3 years ago Viewed 57k times 33

I am trying to figure out how to stretch a background image vertically. I am using CSS3 with 3 images in the following way:

background-image: url("left.png"), url("right.png"), url("center.png") background-repeat: no-repeat, no-repeat, repeat-x background-position: top left, top right, top

Now I want to stretch these images vertically to that they extend all the way to the bottom. Is there a way to do this?

Share Improve this question Follow edited Oct 2, 2012 at 16:56 user1539137 asked Oct 2, 2012 at 16:40 user1539137's user avatar user1539137user1539137 3691 gold badge4 silver badges5 bronze badges 3
  • I don't think so. You can resize (stretch/squish) <img> tags, though: the solution may involve putting an <img> in the background, positioned absolutely and such. – KRyan Commented Oct 2, 2012 at 16:42
  • 1 This might be a good place to look: stackoverflow.com/questions/1150163/… – MikeB Commented Oct 2, 2012 at 16:42
  • 1 Also, pretty sure you're not supposed to put quotes around your urls like that. – KRyan Commented Oct 2, 2012 at 16:43
Add a comment |

3 Answers 3

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 54

I'm late to the party here, but this is what worked for me:

background-size: auto 100%;

This will fit the image vertically and let the width do whatever it needs to do (i think it repeats by default). You can also set:

background-repeat: no-repeat;

for it to not repeat the image in the horizontal direction.

Share Improve this answer Follow answered Nov 18, 2013 at 19:48 mr_mariusz's user avatar mr_mariuszmr_mariusz 6648 silver badges12 bronze badges 2
  • 1 I also needed to set background-position: center; – KIC Commented May 4, 2015 at 15:59
  • 2 background-size: cover; is worth exploring – nu everest Commented Oct 19, 2017 at 23:37
Add a comment | 32

Try:

background-size: 100% 100%;

first 100% is for the width and the second for the height. In your case you need the second set to 100%

Share Improve this answer Follow edited Oct 7, 2013 at 19:16 LihO's user avatar LihO 42k11 gold badges101 silver badges168 bronze badges answered Oct 2, 2012 at 16:45 Erind Dollaku's user avatar Erind DollakuErind Dollaku 3692 silver badges9 bronze badges 2
  • 1 How do I just set the height to 100%? If I do background-size: 100%, it sets both width and height to a 100%. – user1539137 Commented Oct 8, 2012 at 12:37
  • 2 This was pretty handy. In my case, I set "background-size: 960px 100%;" to get the desired effect. – Jason Champion Commented Jul 15, 2013 at 20:04
Add a comment | 0

Thank you for bringing up this question. Below is what worked for me

background-size: cover; background-color: #a8dadc; background-repeat: no-repeat; background-size: 100vw 100vh; Share Improve this answer Follow edited Nov 8, 2021 at 4:40 Dharman's user avatar Dharman 33.1k27 gold badges99 silver badges146 bronze badges answered Nov 8, 2021 at 4:34 Nadine Amanda's user avatar Nadine AmandaNadine Amanda 11 bronze badge Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • Your docs are your infrastructure
  • Featured on Meta
  • More network sites to see advertising test [updated with phase 2]
  • We’re (finally!) going to the cloud!
Visit chat

Linked

939 Stretch and scale a CSS image in the background - with CSS only -1 How to stretch background from top to bottom? 1 background sizing to screen without image distortion 192 Stretch background image css? 2 stretching background image 0 CSS vertical stretch to background 0 Need help stretching background image vertically 7 CSS Stretched Background Image 1 CSS - Background Image Stretch 0 Background-image stretch 1 Stretch a part of background image 0 Stretch CSS Background Image 0 CSS3 background image doesn't vertically stretch

Hot Network Questions

  • Deutsche Bahn Berlin: can I use a different departure station?
  • What was the significance of Mount Doom's eruption?
  • Understanding the definition of the covariant derivative
  • A roulette wheel? An AC Milan kit? Darth Maul's face?
  • Why is Ukraine's conscription age (still) so high (25)?
  • Does ambigous license without a version refer to most recent? Is 'AGPL' currently equivalent to 'AGPL-3.0-only'?
  • What mechanism could cause a person not to cast a reflection?
  • Why is Anarchism not considered fundamentally against the "democratic order" in Germany?
  • How do I go about rebranding a fully deleted project that used to have a GNU General Public License v3.0 but is now fully inaccessible
  • How much do ebikes actually benefit from ebike specific wheels, tires, and forks?
  • Is there a symbol for the Hyper key?
  • What's the Purpose of the IRQ on a 6502
  • Find the Smallest Data Type for a Number
  • Can a ML model learn the hyperparameters landscape?
  • If scent means a pleasant smell, why do we say "lovely scent" or "sweet scent"?
  • BIOS drive order is inverse of Windows'
  • What happens when a ranger uses Favored Foe with Hunter's Mark?
  • Conditional Definition of a Mathematical Operator
  • Why does Jesus tell the Jews to follow the Pharisees teaching while elsewhere He speaks of them creating unnecessary rules?
  • Can Martial Characters use Spell Scrolls in D&D 2024?
  • Is there a commonly used expression for adjusting a training or form of support to a person's specific situation and needs?
  • Shell Script to Normalize the data
  • Is there evidence that Kurt Gödel took his proof of the existence of God to be conclusive?
  • A fantasy story with an imp in a box that paints pictures
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

default

Từ khóa » Html Background Image Stretch Vertically