Jump to content

Make the background image of the header responsive


Stefany93

Recommended Posts

Howdy,

 

I want to make this background image in the header responsive - www.studyingthepast.com/mobile

 

I kept trying and trying and trying and trying to no avail.

 

Here is my code:

#header_container{
	background-image:url('../images/studyingthepast_smaller_banner.png');
	background-repeat: no-repeat;
	background-attachment: fixed;
	background-size: 100% auto;
	color:#F3F3F3;
}

header{

	width:950px;
	height:339px;
}

Many Thanks!

Link to comment
Share on other sites

The image is scaling - what results are you expecting to see? You've got a set pixel width on your header and footer elements that need to be either turned into a percentage width or adjusted manually with media queries.

  • Like 1
Link to comment
Share on other sites

In your case a media query may look like this:

 

#header_container{
    background-image:url('../images/studyingthepast_smaller_banner.png');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: 100% auto;
    color:#F3F3F3;
}

header{
    width:950px;
    height:339px;
}
 
@media screen and (max-width:760px){
   header{
       width:475px;
       height:170px;
   }
}
 

See: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

 

 

*** Due to the size of your original image you may want to change the size at which the media query kicks in... Oh, you can have multiple media queries.

Edited by IThinkMyBrainHurts
  • Like 1
Link to comment
Share on other sites

Thank you. What about the header height? Should I use media queries for it too? Or is there a another trick? Because now the background image is scaling, but the header is always 339px. Cannot remove it because then my background image will not appear.

Link to comment
Share on other sites

In your case a media query may look like this:

 

#header_container{
    background-image:url('../images/studyingthepast_smaller_banner.png');
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: 100% auto;
    color:#F3F3F3;
}

header{
    width:950px;
    height:339px;
}
 
@media screen and (max-width:760px){
   header{
       width:475px;
       height:170px;
   }
}
 

See: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

 

 

*** Due to the size of your original image you may want to change the size at which the media query kicks in... Oh, you can have multiple media queries.

 

 

Many thanks. I will try this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.