html - 将 div 拟合到多行文本跨度
问题描述
我遇到了这个问题:
span {
width: fit-content;
background-color: yellow;
}
div {
width: fit-content;
border: black 1px solid;
max-width: 100px;
}
<div>
<span>Fooooo Barrrrrrrr</span>
</div>
<p>The right side border should be touching the right side of the longest line.</p>
我希望 div 尽可能接近跨度的大小。我已经放在width: fit-content;
那里,但它似乎只适合它自己的max-width
. 我不是要求让 div 适合每一行的边界,但它应该与span
. 我该如何解决这个问题?
解决方案
试试这个:
.customblk span {
background-color: yellow;
}
.customblk div {
border: black 1px solid;
max-width: max-content;
}
<section class="customblk">
<div>
<span>Fooooo Barrrrrrrr </span>
</div>
<p>The right side border should be touching the right side of the longest line.</p>
</section>
推荐阅读
- javascript - 根据输入值调用特定的 div
- node.js - MS Bot 框架 v4 - 无法将 QnA 制造商添加到 bot - 主机名加密值不是有效格式
- git - 意外合并错误分支后如何修复 Git 主分支?
- python - 空字符串的索引与切片
- android - 我们可以在 android 中以编程方式启动互联网(移动数据和 WIFI)吗?
- javascript - 如何检测网络摄像头正在被 js/ts 中的另一个应用程序用于 chrome 浏览器
- python - 如何查看 pipenv 安装的软件包的当前版本?
- mysql - SQL如何计算每个字段的表
- google-apps-script - OAuth2 同意屏幕警告 - 谷歌需要验证范围 https://www.googleapis.com/auth/script.external_request
- node.js - 如何防止节点 js 文件使用其 url 访问(读取)?