Prevention of stretching of elements to 100% of the width of their flexible container

I have inline elements whose width is 100% of their flexbox containers in IE11 and Safari. However, in Chrome and Firefox, width is the width of the content.

This jsfiddle illustrates the problem.

Using max-width: -webkit-max-content;in Safari, the widths of inline-block elements are restored to the width of the content. max-contentunavailable IE11 according to caniuse.com .

Is there a way to achieve this behavior in 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 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>
Run codeHide result
+4
source share
1 answer

display: inline-block .

.btn , display flex. display flex.

, 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 .

+5

Source: https://habr.com/ru/post/1649169/


All Articles