[英]CSS not working in IE and Chrome, but works in CodePen via Chrome
我們有CSS和html,它們在IE或Chrome中打開時不起作用。 文本未居中對齊。
但是,當通過Chrome- > CodePen運行時,它可以工作,文本居中對齊。
<html>
<head>
<style>
div {
float:left;margin-left:10px;word-wrap:break-word;overflow:hidden;
width:150px;
height:150px;
line-height: 150px;
background:red;
color: #fff;
}
div p {
display: inline-block;
vertical-align: middle;
line-height: normal;
width: 100%;
text-align: center;
}
</style>
</head>
<body>
<div>
<p>
hello is the the testhello is the the testhello is the the testhello
</p>
</div>
</body>
</html>
我的本地計算機Chrome:
如果要對元素使用垂直對齊 ,則該顯示必須是表格單元。
檢查一下。 工作正常。
div {
float:left;
margin-left:10px;
word-wrap:break-word;
overflow:hidden;
width:150px;
height:150px;
line-height: 150px;
background:red;
color: #fff;
display:table;
}
div p {
display: table-cell;
vertical-align: middle;
line-height: normal;
width: 100%;
text-align: center;
height:100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.