admin管理员组文章数量:1289582
I want to know how I can set the width of an element to fit-content
, but I also want to add some more width. I cannot use padding, I only want to use width. Maybe something like width: fit-content + 50px
or something like that?
EDIT: Example:
.element{
width: fit-content + 50px;
}
I want to know how I can set the width of an element to fit-content
, but I also want to add some more width. I cannot use padding, I only want to use width. Maybe something like width: fit-content + 50px
or something like that?
EDIT: Example:
.element{
width: fit-content + 50px;
}
Share
Improve this question
edited Apr 19, 2022 at 13:53
acharb
asked Apr 19, 2022 at 13:46
acharbacharb
1532 silver badges10 bronze badges
3
- 1 Can you give a minimal example ? – Cédric Commented Apr 19, 2022 at 13:49
-
1
Could you not create a chide element to provide the extra width, then set the parent to
fit-content
? – Alicia Sykes Commented Apr 19, 2022 at 13:51 -
1
Not possible. You're looking for
calc()
but you can't bine intrinsic and extrinsic units. As in,calc(fit-content + 50px)
isn't valid CSS. Some kind of padding or margin is probably your best bet. – Brandon Hill Commented Apr 19, 2022 at 13:56
1 Answer
Reset to default 8It's not possible to use calc()
to bine intrinsic and extrinsic units. The only option here is to use padding. Since you said you cannot apply padding to your element, you would need to create a child element to carry these styles.
Here's an example (I've added background to each to visualize)
.acharb-outer {
width: fit-content;
margin: 1rem 0;
background: #ffd166;
}
.acharb-inner {
padding: 0 2rem;
background: #ef476f;
}
span {
background: #06d6a0;
}
<div class="acharb-outer">
<div class="acharb-inner">
<span>Quisque ut dolor gravida.</span>
</div>
</div>
<div class="acharb-outer">
<div class="acharb-inner">
<span>Fabio vel iudice vincam, sunt in culpa qui officia.</span>
</div>
</div>
<div class="acharb-outer">
<div class="acharb-inner">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed.</span>
</div>
</div>
本文标签: javascriptHow to set width to quotfitcontentquot with additional widthStack Overflow
版权声明:本文标题:javascript - How to set width to "fit-content" with additional width? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741410666a2377214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论