简体   繁体   English

自适应Div中的垂直对齐文本

[英]Vertical align text in a Responsive Div

I'm trying to create promotional boxes for our website which is using the Bootstrap framework. 我正在尝试为使用Bootstrap框架的网站创建促销框。

I want a div with a background image to house vertically aligned content. 我希望具有背景图像的div可以容纳垂直对齐的内容。 I believe I've succeeded partially, the problem happens when the width of the div becomes larger than the amount I set for the background-image size to appear. 我相信我已经部分成功了,但当div的宽度变得大于我为背景图像大小设置的显示量时,就会出现问题。 Is there any work around for this? 有什么解决办法吗?

For instance at a column width of 6 the div is 455px wide but during some breakpoints the div becomes wider than that but the text content still thinks it's 455px. 例如,当列宽为6时,div的宽度为455px,但在某些断点处,div的宽度会变宽,但文本内容仍认为其为455px。

Here is my html: 这是我的html:

<div class="col-md-6 col-sm-6">
    <div class="promo-box01">
        <div class="promo-text">
            <h3>CTA</h3>
            <p>Limited time sale $45.00</p>
            <a href="#" class="btn btn-primary">Shop Now</a>
        </div>    
</div>
</div>

And here is my css: 这是我的CSS:

.promo-box01 {
background-image:url('../images/promo1.jpg');
background-size: cover;
width:100%;
height:150px;
background-repeat:none;
text-align: center;
border-radius:3px;
box-shadow: 0 0 4px #888;
}

.promo-box01 .promo-text {
font-family:'Roboto',arial,sans-serif;
color:#FFF;
vertical-align: middle;
width:450px;
height:150px;
line-height:1.5em;
display: table-cell;
}

.promo-text h3 {
font-family:'Anton',arial,sans-serif;
color:#FFF;
font-size:28px;
}

尝试将这些类添加到“ promo-box01”:
-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;

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

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