简体   繁体   English

拉伸div背景图片的宽度并设置高度

[英]Stretch width of div background image with set height

I am trying to stetch a div background image but not keep the aspect ratio. 我正在尝试拉伸div背景图像,但保持宽高比。 So I want a fixed height of 270px and a width 100% of the screen. 因此,我希望屏幕高度固定为270px,宽度为100%。 It works perfectly in chrome but not in IE or Firefox. 它在chrome中可以完美运行,但在IE或Firefox中则不能。 Here is what I have now: 这是我现在所拥有的:

CSS: CSS:

#container {
background-image: url(images/blur.jpg);
background-repeat:no-repeat;
background-size:100% 270px;
width:100%;
height:270px;
margin:0px;
padding:0px;
}

HTML: HTML:

<div id="container">content</div>

I'm a little new to all this so sorry if I am asking a really simple question! 我对这一切有点陌生,如果要问一个非常简单的问题,对不起!

*Update: It's all working now. *更新:现在一切正常。 I'm really not sure what happened. 我真的不确定发生了什么。 I checked this over and over but closing everything and then opening my source code showed that it had changed the css from background size: 100% 270px; 我一遍又一遍地检查了一下,但是关闭所有内容,然后打开我的源代码,发现它已经更改了背景大小的css:100%270px; to just 100%. 到100% Absolutely bizarre! 绝对离奇! Sorry for wasting your time. 很抱歉浪费您的时间。

This might be because you need to include the 这可能是因为您需要包括

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "w3.org/TR/html4/strict.dtd">

element 元件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM