Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set size of background image fit to the div

Tags:

html

css

image

I want to set div background image div(w:932, h:148) and the image size is 1524*587
whan I trying to set it image is not getting fit to the div size what should i do? my code-

.header .logo { width:932px; height:148px; background:url(images/logo.jpg) no-repeat center;}
like image 949
piku Avatar asked Sep 06 '10 17:09

piku


People also ask

How do I make my background image fit the size of a div?

How do I make an image fit in a div? Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.

How do I autofit an image in a div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How do I make the background image fit my screen size?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.

How do I resize my background image to fit CSS?

You can use the CSS background-size: cover; to stretch and scale an image in the background with CSS only. This scales the image as large as possible in such a way that the background area is completely covered by the background image, while preserving its intrinsic aspect ratio.

How can I get div height to auto adjust to background-size?

Set the background-image property with the URL of the image as its value for the <div> element. Set the background-repeat property of the the <div> element. to “no-repeat” so as not to repeat the image. Set the visibility to “hidden” for the <img> tag.


1 Answers

You could use the CSS3 background-size property for this.

.header .logo {
    background-size: 100%;
}

But then you still have the problem of wide (or not) browser support. Your best bet is then really to use a "plain vanilla" <img> element whose width/height is set to 100%.

like image 177
BalusC Avatar answered Oct 28 '22 01:10

BalusC