[英]Twitter Bootstrap Responsive Background-Image inside Div
How i can modify #bg
image so it would be responsive, resizable and proportional in all browser? 我如何修改#bg
图像,以便它在所有浏览器中都具有响应性,可调整大小和比例?
HTML: HTML:
<div class="container">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8 col-sm-6 col-xs-12 well" id="bg">
</div>
<div class="col-md-2"></div>
</div>
</div>
css: CSS:
@import url('bootstrap.min.css');
body{
background: url('../img/bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
margin-top: 12%;
}
#bg{
background:url('../img/con_bg4.png') no-repeat center center;
height: 500px;
}
我找到了解决方案。
background-size:100% auto;
You might also try: 您也可以尝试:
background-size: cover;
There are some good articles to read about using this CSS3 property: P erfect Full Page Background Image by CSS-Tricks and CSS Background-Size by David Walsh . 有一些关于使用这个CSS3属性的好文章: 由David Walsh 通过CSS-Tricks和CSS Background-Size制作的 P erfect全页背景图像 。
PLEASE NOTE - This will not work with IE8-. 请注意 - 这不适用于IE8-。 However, it will work on most versions of Chrome, Firefox and Safari. 但是,它适用于大多数版本的Chrome,Firefox和Safari。
Try this (apply to a class you image is in (not img itself), eg 试试这个(适用于图像所在的类(不是img本身),例如
.myimage {
background: transparent url("yourimage.png") no-repeat top center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: 100%;
height: 500px;
}
I had the similar issue and i solved it using: 我有类似的问题,我使用以下方法解决了它:
background:url(images/banner1.png) no-repeat center top scroll;
background-size: 100% auto;
padding-bottom: 50%;
... here i had to add the padding: 50% because it wasn't working for me otherwise. ...这里我不得不添加填充:50%,因为它不适合我。 It allowed me to set the height of container, as per the size ratio of my banner image . 它允许我根据我的横幅图像的大小比例设置容器的高度。 and it is also responsive in my case. 在我的情况下它也是响应。
I believe this should also do the job too: 我相信这也应该做的工作:
background-size: contain;
It specifies that the image should be resized to fit within the element without losing it's aspect ratio. 它指定应调整图像大小以适合元素而不会丢失其宽高比。
The way to do this is by using background-size so in your case: 这样做的方法是使用background-size,所以在你的情况下:
background-size: 50% 50%;
or 要么
You can set the width and the height of the elements to percentages as well 您也可以将元素的宽度和高度设置为百分比
This should work 这应该工作
background: url("youimage.png") no-repeat center center fixed;
-webkit-background-size: 100% auto;
-moz-background-size: 100% auto;
-o-background-size: 100% auto;
background-size: 100% auto;
Don't use fixed: 不要使用固定的:
.myimage {
background:url(admin-user-bg.png) no-repeat top center;
background: transparent url("yourimage.png") no-repeat top center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: 100%;
height: 500px;
}
您正在寻找Mby bootstrap img-responsive
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.