gpt4 book ai didi

css - 垂直对齐响应模板的 div

转载 作者:行者123 更新时间:2023-11-28 12:09:55 25 4
gpt4 key购买 nike

如何使 div 中的文本:“grid2”和“section2”在中间垂直对齐?

这是我的 HTML 中的问题还是我的问题出现在 css 中?谁能指出我正确的方向?

我尝试查看其他问题,但答案并没有让我更进一步。

我的 HTML:

<html>
<head>
<title></title>
</head>
<body>
<div id="background">
<div id="template">
<div class="grid2">
<div class="section2">
<h2 style="text-align: center;">New 2014 Model</h2>
<p>Latest model forced air (with a fan) fully automatic 48 egg incubator.</p>
<p>This new design uses a sophisticated program for automated hatching process that produces one of the highest hatching rates of any model, yet is incredibly easy to use. Perfect for small hatchers, self sufficient households, or families incubating in the backyard.</p>
</div>
</div>
</div>

<!--responsive-->

我的 CSS:

body {
margin:0px;
padding:0px;
}
.clear {
clear:both;
}
#background {
background-color:#FFFFFF;
background-position:top;
width:100%;
max-width:1000px;
margin:auto;
}
#template {
padding:10px;
font-family:Arial, Helvetica, sans-serif;
color:#000;
font-size:16px;
}
.responsive {
width:100%;
}
.grid2 {
float: left;
width:50%;
min-width:280px;
}
.grid3 {
float: left;
width:33.3%;
min-width:280px;
}
.grid4 {
float: left;
width:16.66%;
min-width:160px;
}
.section4 {
padding:1px;
}
.section3 {
padding:5px;
}
.section2 {
padding:10px;
}
.shrinkable {
clear: both;
padding: 0px;
margin: 0px;
text-align:center;
}
.shrinkable img {
width:60%;
height: auto;
}
.shrinkable p {
text-align:center;
}
.column {
display:block;
float:left;
margin: 1% 0 1% 1.6%;
}
.column:first-child {
margin-left: 0;
}
.box {
width: 32.2%;
}
.row:before,.row:after {
content:"";
display:table;
}
.row:after {
clear:both;
}

这是 the working example

最佳答案

这将使文本垂直和水平居中

.grid2 {height: 100%; display:table; text-align: center}
.section2 {display: table-cell; vertical-align: middle}

关于css - 垂直对齐响应模板的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19560783/

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