Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make div background image responsive

Tags:

How to make this image responsive

HTML:

<section id="first" class="story" data-speed="8" data-type="background">     <div class="smashinglogo" id="welcomeimg" data-type="sprite" data-offsetY="100" data-Xposition="50%" data-speed="-2"></div> </section> 

CSS:

#first .smashinglogo {background: url(../images/logo1.png)  50% 100px no-repeat fixed;} 
like image 916
User1038 Avatar asked Feb 25 '14 06:02

User1038


People also ask

How do I make a background image responsive?

Here's how to create responsive background images with CSS: Use the background-size property to encompass the viewport. Give this property a cover value that will tell a browser to scale the background image's heights and width so that they always remain equal to or greater than the height/width of the device viewport.

How do I make a div image responsive?

To make an image responsive, you need to give a new value to its width property. Then the height of the image will adjust itself automatically. The important thing to know is that you should always use relative units for the width property like percentage, rather than absolute ones like pixels.

Can you give a div a background image?

Say you want to put an image or two on a webpage. One way is to use the background-image CSS property. This property applies one or more background images to an element, like a <div> , as the documentation explains.


1 Answers

Use background-size property to the value of 100% auto to achieve what you are looking for.

For Instance,

#first .smashinglogo{    background-size:100% auto; } 

Hope this helps.

PS: As per your code above, you can remove fixed and add 100% auto to achieve the output.

like image 55
Nitesh Avatar answered Nov 01 '22 11:11

Nitesh