responsive background image problem

by Arcsn
8 replies
Hi guys!

I have a problem with responsive background images.
I used the <div> but they collapse and the background image cannot be seen. I'll try to explain...

my html code is following:

HTML Code:
<div id="company">
    <article></article>
  </div>	
<div id="mission">
    <article> some text here </article>
  </div>	
<div id="products">
    <article> some text here </article>
  </div>	
<div id="contacts">
    <article> some text here </article>
  </div>
as you can see only the first <div> has no text at all, I fill it with an image only.

my css code is following:

Code:
#company {
width:100%;
padding-bottom: 54.20%; /* calc made according to a project, my image is 1024x555px*/
border-bottom: 3px solid #000000;
background-image: url(../img/company.jpg);
background-repeat: no-repeat;
-webkit-background-size, -moz-background-size, -o-background-size: contain;
background-size: contain;
background-position: center top;
}
#mission{
width:100%;
padding-bottom: 90.82%; /* calc made according to a project, this image is 1024x930px*/
rest of the code same as above, background image obviously different
}
#products{
width:100%;
padding-bottom: 76.17%; /* calc made according to a project, this image is 1024x780px*/
rest of the code same as above, background image obviously different
}
#contacts{
width:100%;
padding-bottom: 27.54%; /* calc made according to a project, this image is 1024x282px*/
rest of the code same as above, background image obviously different
}

now: if I eliminate the "width and padding bottom", the first <div> collapses as there is nothing inside and the background image cannot be seen. the others <div> "crop" my background images and show only enough for the text.
if I leave those values (width and padding) my first <div> (the empty one) fits perfectly with a background image, but the other <div> are "longer" than the size of my image and you can see the background color under the image...

any clues how to fix it?
#background #image #problem #responsive
  • Profile picture of the author Arcsn
    I thought even not to use a background image, and simply place an image into the <div>, but I need to place it somehow "behind" the text. The only problem is.... I do not know how to... maybe "z-index" can help? how?
    {{ DiscussionBoard.errors[10265880].message }}
  • Profile picture of the author Himanshu1988
    For responsive image you will do

    img{
    max-width : 100%;
    width: 100%
    }

    Not sure if this will help.
    Signature

    Web Design | SEO | WordPress | Mobile App @ ZOTO Solutions

    {{ DiscussionBoard.errors[10266951].message }}
    • Profile picture of the author Arcsn
      thanx for trying.

      in this moment I am trying to modify my HTML and CSS codes hoping to get lucky, no result yet...

      any suggestions welcome.
      {{ DiscussionBoard.errors[10267338].message }}
  • Profile picture of the author webcosmo
    Use <img /> tag instead or scale it with css.
    {{ DiscussionBoard.errors[10269292].message }}
  • Profile picture of the author Arcsn
    thanks. still working on it... no success yet...
    {{ DiscussionBoard.errors[10271462].message }}
  • Profile picture of the author Arcsn
    solved. using an <img> tag.
    {{ DiscussionBoard.errors[10280184].message }}
  • Profile picture of the author yasar
    in responsive View you need to add the below code

    background-size :100% 100% ;
    {{ DiscussionBoard.errors[10284763].message }}
  • Profile picture of the author bm2ilabs
    just use max-width: 100%
    {{ DiscussionBoard.errors[10285366].message }}

Trending Topics