简体   繁体   English

如何将宽度设置为具有额外宽度的“fit-content”?

[英]How to set width to "fit-content" with additional width?

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.我想知道如何将元素的宽度设置为fit-content ,但我还想增加一些宽度。 I cannot use padding, I only want to use width.我不能使用填充,我只想使用宽度。 Maybe something like width: fit-content + 50px or something like that?也许像width: fit-content + 50px类的东西?

EDIT: Example:编辑:示例:

.element{
   width: fit-content + 50px;
}

It's not possible to use calc() to combine intrinsic and extrinsic units.不可能使用calc()来组合内部单位和外部单位。 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.既然你说你不能对你的元素应用填充,你需要创建一个子元素来携带这些 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM