通过在flexbox中使用aptive-ratio的奇怪布局
dl 是flexbox, dd 是一些内容的盒子。
dt 与 dd 相同,其内容宽度等于IT高度。
一个奇怪的结果是,当页面首次加载时, dt 的宽度不正确。
但是在回流后运行良好。发生在Chrome和Firefox中。
我不知道这是浏览器错误还是使用不正确。
section {
display: inline-block;
max-width: 100%;
margin-right: 10px;
}
dl {
display: flex;
gap: 0 5px;
background: #ddd;
border-radius: 0 10px 10px 0;
padding-right: 10px;
margin: 0;
}
dt {
flex: 0 0 auto;
width: fit-content;
}
dd {
margin: 0;
flex: 1 1 auto;
}
.tag {
height: 100%;
background: #0ff;
aspect-ratio: 1;
}
<section>
<dl>
<dt>
<div class="tag">Test1</div>
</dt>
<dd>
<p>Description 11111</p>
<p>Description 22222</p>
</dd>
</dl>
</section>
<section>
<dl>
<dt>
<div class="tag">Test2</div>
</dt>
<dd>
<p>Description 11111</p>
</dd>
</dl>
</section>
The dl is flexbox, dd is a box of some content.
The dt is expected the same height with dd, and its content width is equal to it height.
A strange result is when the page first loaded, the width of dt isn't correct.
But it works well after a reflow. Happened both in Chrome and Firefox.
I don't know whether it's a browser bug or usage incorrect.
section {
display: inline-block;
max-width: 100%;
margin-right: 10px;
}
dl {
display: flex;
gap: 0 5px;
background: #ddd;
border-radius: 0 10px 10px 0;
padding-right: 10px;
margin: 0;
}
dt {
flex: 0 0 auto;
width: fit-content;
}
dd {
margin: 0;
flex: 1 1 auto;
}
.tag {
height: 100%;
background: #0ff;
aspect-ratio: 1;
}
<section>
<dl>
<dt>
<div class="tag">Test1</div>
</dt>
<dd>
<p>Description 11111</p>
<p>Description 22222</p>
</dd>
</dl>
</section>
<section>
<dl>
<dt>
<div class="tag">Test2</div>
</dt>
<dd>
<p>Description 11111</p>
</dd>
</dl>
</section>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论