[英]BootStrap Responsive Background image with text on it is not working
I'm getting started with BootStrap 3 and trying to use a background image with text on it. 我开始使用BootStrap 3,并尝试使用带有文字的背景图片。 At same time I want it to be reponsive but it seems there is some issue with the way I implemented it.
同时,我希望它具有响应能力,但是我实现它的方式似乎存在一些问题。 I'm able to get it work for normal desktop but when I try to emulate on a mobile device, text goes outside of background image.
我能够在普通台式机上使用它,但是当我尝试在移动设备上进行仿真时,文本超出了背景图像。
http://jsfiddle.net/cn5guyt4/2/ http://jsfiddle.net/cn5guyt4/2/
<div id="front-landing">
<div class="container jumbotron hero-unit">
<h2 class="h1"><span>"Sample Test"</span></h2>
<h3 class="-sub-title">
<span>"Sample Test text 2"</span>
</h3>
</div>
</div>
.hero-unit {
position: relative;
margin-bottom: 0;
margin-top: 15px;
background: url('http://1.bp.blogspot.com/-P5uqUWLgZmA/UtQDdtahipI/AAAAAAAAF3E/IgvARwfxAlw/s1600/seamless-stone-background.jpg') 50% 80% no-repeat;
background-size: 100%;
min-height: 700px;
}
.h1 {
font-size: 2.625em;
font-weight: 700;
letter-spacing: -0.03em;
margin-bottom: 0.571em;
margin-top: 2em;
text-align: center;
}
.-sub-title {
font-weight: 400;
text-align: center;
}
h2 span {
background-color: white;
}
h3 span {
background-color: white;
}
Can someone help me to figure out what am I doing wrong here ? 有人可以帮我弄清楚我在做什么错吗?
Thanks 谢谢
In your hero-unit class
, the background-size
set to 100%
but it should be cover
instead. 在您的
hero-unit class
, background-size
设置为100%
但是应该cover
它。 That made a huge difference: see bootply . 那产生了巨大的变化: 请参阅bootply 。
I think what you are really trying to do is get the jumbotron of bootstrap to have a background picture. 我认为您真正想做的是让bootstrap的超大屏幕拍有背景图片。 Why is your jsfiddle code different from the code you posted here?
为什么您的jsfiddle代码与您在此处发布的代码不同? there is a wild margin of difference.
存在巨大的差异。 My fix is using the code above.
我的解决方法是使用上面的代码。
<div id="front-landing">
<div class="container jumbotron ">
<h2 class="h1"><span>"Sample Test"</span></h2>
<h3 class="-sub-title">
<span>"Sample Test text 2"</span>
</h3>
</div>
</div>
.h1 {
font-size: 2.625em;
font-weight: 700;
letter-spacing: -0.03em;
margin-bottom: 0.571em;
margin-top: 2em;
text-align: center;
}
.jumbotron{
background-image: url('http://1.bp.blogspot.com/-P5uqUWLgZmA/UtQDdtahipI/AAAAAAAAF3E/IgvARwfxAlw/s1600/seamless-stone-background.jpg');
background-size: cover;
}
.-sub-title {
font-weight: 400;
text-align: center;
}
h2 span {
background-color: white;
}
h3 span {
background-color: white;
}
you can set image as a background-image 您可以将图像设置为背景图像
.imageAndText img{
width: 100%;
background: no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
for text you can use col-xs-12 or work write individual media query 对于文本,您可以使用col-xs-12或工作编写单个媒体查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.