gpt4 book ai didi

html - 如何垂直居中文本并让深蓝色条横跨整个屏幕

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:29 27 4
gpt4 key购买 nike

我想将文本“New from Subaru”垂直和水平居中。另外,我的文字有深蓝色背景。我希望深蓝色背景在整个 div 上水平延伸。我该怎么做?

J fiddle : http://jsfiddle.net/huskydawgs/eL7rwLx3/21/

wrapper-promo { background-color: #3862ad; border: 2px solid #2251a4; margin: 10px 0; width: 500px; }

.title-top {
background-color: #2251a4;
display: table;
height: 40px;
overflow: hidden;
}


.title-top-cell {
display: table-cell;
vertical-align: middle;
}


.promo-content {
margin: 20px;
}

h2 {
font-family:SegoeBold;
font-size:1.4em;
color:#fff;
margin: 10px 0 -10px 0;
}

h2.block-title {
margin: 0;
text-align: center;
}

h3 {
font-family:SegoeBold;
font-size:1em;
color:#fff;
}
.promo-content p {
font-family: helvetica, Arial,sans-serif;
font-size: 14px;
color: #fff;
line-height: 20px;
}
<div class="wrapper-promo">
<div class="title-top">
<div class="title-top-cell">
<h2 class="block-title">New from Subaru</h2></div></div>
<div class="promo-content">
<h2>
Subaru Guide for Small Business</h2>
<h3>
Starts at $45/month</h3>
<p>
Adventure has a stylish side. The 2015 Subaru Outback was designed to allow you to experience the world like you never have before.</p>
</div>
</div>

最佳答案

如果您这样做,它会在您的 title-pop div 中一直延伸您的 block title div。

h2.block-title {
margin: 0 auto;
text-align: center;
width: 100%;
}

关于html - 如何垂直居中文本并让深蓝色条横跨整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29853164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com