gpt4 book ai didi

css - 如何在css中对齐背景图片的文本中间

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:45 26 4
gpt4 key购买 nike

我想在 css 中将内容对齐到背景图片的中间。我使用了这样的代码

 section.center_content {
background: url(../images/center_bg.jpg) center no-repeat;
border-bottom: 1px solid #e5e5e5;
font-family:Arial, Helvetica, sans-serif;
margin-bottom: 40px;
background-size:100%;
height:190px;
}
.ticker-content {
vertical-align:middle;
}
.ticker-content h1 {
color:#FFFFFF;
font-size:45px;
}
.ticker-content h2 {
color:#BFBFBF;
font-size:35px;
}
.ticker-content p {
color:#BFBFBF;
font-size:20px;
}

请给出解决方案。非常感谢

最佳答案

将以下属性添加到您的 section.center_content:

section.center_content {
background:blue;
border-bottom: 1px solid #e5e5e5;
font-family:Arial, Helvetica, sans-serif;
margin-bottom: 40px;
height:190px;
width:100px;

/*Vertically center*/
display:table-cell; /*This makes the div behave like a table cell*/
vertical-align:middle; /*This property is only available on table cells*/

/*Horizontal center*/
text-align:center; /*This you know centers text horizontally*/
}

.ticker-content{
/*Remove vertical-align:middle; from here*/
}

DEMO

附言并保留这个 wonderful article以备将来引用。

关于css - 如何在css中对齐背景图片的文本中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22780594/

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