我在div中有:before
个内容,我的宽度为40%
,它在chrome,firefox中效果很好但是当我在IE10中尝试它时它不起作用。
以下是我的代码:
*,
*:before,
*:after {
box-sizing: border-box;
}
.Table-row {
border: 0.5px solid #cccccc;
}
.Table-row-item {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: -ms-flex;
display: flex;
-webkit-flex-flow: row nowrap;
-moz-flex-flow: row nowrap;
-ms-flex-flow: row nowrap;
flex-flow: row nowrap;
-webkit-flex-grow: 1;
-moz-flex-grow: 1;
-ms-flex-grow: 1;
flex-grow: 1;
-webkit-flex-basis: 0;
-moz-flex-basis: 0;
-ms-flex-basis: 0;
flex-basis: 0;
word-wrap: break-word;
word-break: break-word;
-webkit-box-flex: 1;
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 0.5em;
}
.Table-row-item:before {
content: attr(data-header);
width: 40%;
font-weight: 700;
}
<div class="head">
<div class="Table-row">
<div class="Table-row-item" data-header="First Name">Gyandeep</div>
<div class="Table-row-item" data-header="Last Name">Singh</div>
<div class="Table-row-item" data-header="Job Title">Software Engineer</div>
</div>
</div>
答案 0 :(得分:3)
::before
伪元素默认情况下为display:inline
,因此添加display:inline-block
会修复IE10 / 11。
修改强>
感谢@Alochi解释为什么它在Chrome中有效。父元素是一个flex项,它是blockified(即元素的显示类型被更改为阻塞,因为父元素是display:flex
)。
答案 1 :(得分:0)
See this answer to not use flex on IE10 yet
以下是IE10的一个工作示例:
*,
*:before,
*:after {
box-sizing: border-box;
}
.Table-row {
border: 0.5px solid #cccccc;
}
.Table-row-item {
word-wrap: break-word;
word-break: break-word;
padding: 0.5em;
}
.Table-row-item:before {
content: attr(data-header);
width: 40%;
font-weight: 700;
display: inline-block;
}