Html css:内联块div的垂直对齐问题
我需要在一个div中集中一条信息,比如 父div的宽度为100%,将消息水平居中没有问题。此外,正如您所见,图标也垂直居中,但我无法垂直居中文本。到目前为止,我唯一应用于该div的css是Html css:内联块div的垂直对齐问题,html,css,Html,Css,我需要在一个div中集中一条信息,比如 父div的宽度为100%,将消息水平居中没有问题。此外,正如您所见,图标也垂直居中,但我无法垂直居中文本。到目前为止,我唯一应用于该div的css是 .content { height: 100% ; display: inline-block ; } 任何关于.container中消息div向下移动的建议。这是正确的跨浏览器方法吗?您可以使用 .parent { background-color: lightgrey ;
.content {
height: 100% ;
display: inline-block ;
}
任何关于.container中消息div向下移动的建议。这是正确的跨浏览器方法吗?您可以使用
.parent {
background-color: lightgrey ;
width: 100% ;
height: 50px ;
text-align: center ;
display: inline-block;
}
.content {
height: 100%;
display: inline-block;
margin-top: -15px; //so that text lies at the center level of icon
vertical-align: middle;
}
你可以用像
.parent {
background-color: lightgrey ;
width: 100% ;
height: 50px ;
text-align: center ;
display: inline-block;
}
.content {
height: 100%;
display: inline-block;
margin-top: -15px; //so that text lies at the center level of icon
vertical-align: middle;
}
.container高度是一个问题,您可以将.container高度设置为100%,以使其调整到其父级。添加垂直对齐后:中间对齐;到了。内容
.container高度是一个问题,您可以将.container高度设置为100%,以使其调整到其父级。添加垂直对齐后:中间对齐;到了。内容
像这样改变你的css
.content {
height: 100% ;
display: inline-block ;
vertical-align:middle;
line-height:5px;
}
.container {
display: inline-block ;
height: 100% ;
}
像这样改变你的css
.content {
height: 100% ;
display: inline-block ;
vertical-align:middle;
line-height:5px;
}
.container {
display: inline-block ;
height: 100% ;
}
对DOM和CSS的更改最少,并且不固定任何高度/线条高度 添加垂直对齐:中间对齐;到。图标和替换高度:100%垂直对齐:中间;内容
查看此,对DOM和CSS的更改最少,并且不固定任何高度/线条高度 添加垂直对齐:中间对齐;到。图标和替换高度:100%垂直对齐:中间;内容
看这个这应该会起作用。 基本上,我添加了以下内容: 加价
<div class="parent">
<div class="container">
<div class="content">
<div class="icon">
<p class="tocenter">some message here</p>
</div>
</div>
</div>
</div>
希望这能有所帮助,这应该能起到一定的作用。 基本上,我添加了以下内容: 加价
<div class="parent">
<div class="container">
<div class="content">
<div class="icon">
<p class="tocenter">some message here</p>
</div>
</div>
</div>
</div>
希望这有帮助
我更喜欢将消息和图标“相关”放在带有子span的span中。这种方法有两个关键点:
将容器div与父容器div垂直对齐。使用这两个类中的position和container中的margin,可以实现这一点
将跨度与父跨度内的消息垂直对齐,该跨度与使用图标消息类的图标垂直对齐。请参阅css代码中的注释
它适用于所有浏览器
HTML
我更喜欢将消息和图标“相关”放在带有子span的span中。这种方法有两个关键点:
将容器div与父容器div垂直对齐。使用这两个类中的position和container中的margin,可以实现这一点
将跨度与父跨度内的消息垂直对齐,该跨度与使用图标消息类的图标垂直对齐。请参阅css代码中的注释
它适用于所有浏览器
HTML
.parent {
background-color: lightgrey ;
width: 100% ;
height: 70px ;
text-align: center ;
position: relative;
}
.container {
position: absolute;
display: inline-block;
height: 40px ;
top: 0;
bottom: 0;
margin: auto;
border: 1px solid #000;
}
.icon-message {
background: url( "http://upload.wikimedia.org/wikipedia/commons/8/88/Red_triangle_alert_icon.png" ) no-repeat;
display: inline-block;
background-size: 40px 40px; /* image's size */
height: 40px; /* image's height */
padding-left: 50px; /* image's width plus 10 px (margin between text and image) */
}
.icon-message span {
height: 40px; /* image's height */
display: table-cell;
vertical-align: middle;
}