0

I search a lot info about height:auto ,but I didnt find a solution for my problem. I need a full width image with dynamic height ,but that doesn't work :( Anyone can help!?

HTML:

<div id="roster">
<div class="image"></div>
</div>

CSS

#roster{}

#roster .image{
    background-image:("http://nhlawyer.net/wp-content/uploads/header-image-2.jpg");
  width:100%;
  height:auto;
}

There is my jsFiddle

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
eatmailyo
  • 670
  • 1
  • 12
  • 33

2 Answers2

1

You should use the image as <img> tag not as a background-image and by default if you make the image width:100%; its height will be auto

#roster img{
 width:100%;
}
<div id="roster">
  <img src="http://nhlawyer.net/wp-content/uploads/header-image-2.jpg">
</div>

If you are using the image as background you should give the element specific height then you can handle the height of background by background-size: cover;

#roster .image{
  height:50px;
  background-image:url("http://nhlawyer.net/wp-content/uploads/header-image-2.jpg");
  background-size:cover;
}
<div id="roster">
  <div class="image"></div>
</div>
Ahmed Salama
  • 2,795
  • 1
  • 11
  • 15
0

Please try this

#roster .image {
    background: url('https://nhlawyer.net/wp-content/uploads/header-image-2.jpg');
    width: 100%;
    height: 250px;
    background-size: 100%;
    background-repeat: no-repeat;
}
vignesh
  • 951
  • 5
  • 13