html – 防止元素伸展到其Flex容器的100%宽度

html – 防止元素伸展到其Flex容器的100%宽度,第1张

概述我有内联块元素,其宽度可扩展到IE11和Safari中Flexbox容器的100%.但是,在Chrome和Firefox中,宽度是内容的宽度. 这个jsfiddle说明了这个问题. 使用max-width:-webkit-max-content;在Safari中,内联块元素的宽度将恢复为内容的宽度.根据caniuse.com,IE11中没有max-content. 有没有办法在IE11中实现这种行 我有内联块元素,其宽度可扩展到IE11和Safari中FlexBox容器的100%.但是,在Chrome和firefox中,宽度是内容的宽度.

这个jsfiddle说明了这个问题.

使用max-wIDth:-webkit-max-content;在Safari中,内联块元素的宽度将恢复为内容的宽度.根据caniuse.com,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 >  <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 >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 >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 >This is an<br>inline-block too</a>  </section></div>
解决方法 显示:所有浏览器都会忽略内联块规则.

由于.btn是d性项,因此其显示属性由d性容器控制.因此,没有理由在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;}

Revised Fiddle

重要的澄清

IE存在问题,但它不是显示属性.

您的.btn元素已与flex auto margin对齐:

margin: auto auto 10px 0px;

margin-right:auto组件是在大多数浏览器中将按钮向左移动的内容.这应该是你所需要的.

但IE11不尊重这一规则.这就是align-self:flex-start作为后备需要的原因.

总结

以上是内存溢出为你收集整理的html – 防止元素伸展到其Flex容器的100%宽度全部内容,希望文章能够帮你解决html – 防止元素伸展到其Flex容器的100%宽度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083146.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存