我有内联块元素,其宽度在IE11和Safari中延伸到其flexbox容器的100%。但是,在Chrome和Firefox中,宽度是内容的宽度。
此jsfiddle说明了这个问题。
在Safari中使用max-width: -webkit-max-content;
,内联块元素'宽度恢复到内容的宽度。根据{{3}},IE11中不提供max-content
。
有没有办法在IE11中实现这种行为?
.row {
display: flex;
}
section {
display: flex;
flex-direction: column;
flex: 1 1 0px;
}
.btn {
display: inline-block;
position: relative;
background: black;
color: white;
padding: 10px 40px 20px 15px;
text-decoration: none;
border: 1px solid black;
margin: auto auto 10px 0px;
}
.btn:after {
display: block;
height: 10px;
width: 10px;
border-radius: 5px;
position: absolute;
right: 11px;
bottom: 11px;
content: "";
background: white;
}

<div class="row">
<section>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
<a href class="btn">inline-block</a>
</section>
<section>
<p>p into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum pa</p>
<a href class="btn">inline-block</a>
</section>
<section>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.
Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<a href class="btn">This is an<br>inline-block too</a>
</section>
</div>
&#13;
答案 0 :(得分:8)
所有浏览器都会忽略display: inline-block
规则。
由于.btn
是弹性项,因此其display
属性由弹性容器控制。因此,没有理由在flex项目上使用display
属性。
由于您位于列方向灵活容器中,因此使用align-self: flex-start
可以在IE中使用布局。
.btn {
/* display: inline-block; */
align-self: flex-start /* new */
position: relative;
background: black;
color: white;
padding: 10px 40px 20px 15px;
text-decoration: none;
border: 1px solid black;
margin: auto auto 10px 0px;
}
重要说明
IE存在问题,但它不是display
属性。
您的.btn
元素已与flex auto
页边距对齐:
margin: auto auto 10px 0px;
margin-right: auto
组件是大多数浏览器中按钮向左移动的部分。这应该是你所需要的一切。
但IE11并不尊重这一规则。这就是为什么align-self: flex-start
需要作为后备的原因。