Html 在中间和中间对齐div内的跨距
我有一个div,里面有很多跨距。div相当大,跨度无法填满它。我希望跨距对齐,使生成的文本在垂直和水平方向上都位于div区域的中心。我不想每次都要计算像素数,我必须把它设置好。我可以在中心垂直对齐,但不能水平对齐Html 在中间和中间对齐div内的跨距,html,css,Html,Css,我有一个div,里面有很多跨距。div相当大,跨度无法填满它。我希望跨距对齐,使生成的文本在垂直和水平方向上都位于div区域的中心。我不想每次都要计算像素数,我必须把它设置好。我可以在中心垂直对齐,但不能水平对齐 <div class="Container"> <div class="InnerContainer"> <b><span class="large">Hi</span><span class="
<div class="Container">
<div class="InnerContainer">
<b><span class="large">Hi</span><span class="normal">How're you doing</span>
<br/>
<span style="font-family: Arial; font-size: medium">Answer Here</span>
</div>
</div>
.Container {
/*Set surroundings of the div*/
padding: 0;
/* Set size of the div */
width: 400px;
height: 350px;
/* Set position of the div */
position: relative;
margin: 0 auto;
margin-left: -200px;
margin-top: -175px;
left: 50%;
top: 50%;
align-content: center;
vertical-align: middle;
}
.InnerContainer{
/*Set surroundings of the div*/
padding: 0;
/* Set size of the div */
width: 400px;
height: 350px;
/* Set position of the div */
position: relative;
margin: 0 auto;
margin-left: -250px;
margin-top: -175px;
left: 50%;
top: 50%;
/*align-content: center;*/
vertical-align: middle;
display: table-cell;
}
你好吗
回答这里
.集装箱{
/*设置div的周围环境*/
填充:0;
/*设置div的大小*/
宽度:400px;
高度:350px;
/*设置div的位置*/
位置:相对位置;
保证金:0自动;
左边距:-200px;
利润上限:-175px;
左:50%;
最高:50%;
对齐内容:居中对齐;
垂直对齐:中间对齐;
}
.InnerContainer{
/*设置div的周围环境*/
填充:0;
/*设置div的大小*/
宽度:400px;
高度:350px;
/*设置div的位置*/
位置:相对位置;
保证金:0自动;
左边距:-250px;
利润上限:-175px;
左:50%;
最高:50%;
/*对齐内容:居中对齐*/
垂直对齐:中间对齐;
显示:表格单元格;
}
您应该将display:table cell
添加到.Container
中,并将display:inline block
添加到.innercainer
(因为除非指定宽度,否则div往往会占用所有可用的水平空间)
然后添加文本对齐:居中;垂直对齐:中间对齐代码>到容器
如下所示:您应该对父组件使用“显示:表格单元格”和“垂直对齐:中间;”。并且不要设置子组件的大小。这样做:
.Container{
背景颜色:绿色;
宽度:400px;
高度:200px;
文本对齐:居中;
垂直对齐:中间对齐;
显示:表格单元格;
}
.InnerContainer{
背景颜色:蓝色;
显示:内联块;/*仅用于包装内容*/
}
你好吗
回答这里
您能提供一份详细的报告吗?顺便说一句,如果要将.InnerContainer
设置为display:table cell
,我认为需要将父(.Container
)设置为display:table
。