gpt4 book ai didi

html - 使 Div 适合其内容

转载 作者:行者123 更新时间:2023-12-03 09:06:13 26 4
gpt4 key购买 nike

我试图强制 div 适合里面的文本。无论我尝试什么,似乎都有多余的空白。这是我的代码:

body {
background-color: #000;
}

.holding {
width: 500px;
background-color: red;
height: 500px;
padding: 40px 100px;
max-width: 400px;
width: fit-content;
}

.childone {
background-color: white;
display: inline;
padding: 20px;
float: left;
clear: both;
}

.clear {
clear: both;
}

.childtwo {
background-color: white;
display: inline-block;
float: left;
padding: 10px;
}
<body>

<div class="holding">
<div class="childone">This is the Title and I really the div to end here with.no.extra.white.space </div>
<div class="clear"></div>
<div class="childtwo">This is the next child div with a bund of stuff.</div>
</div>

</body>

最佳答案

使用word-break: break-all,例如:

.childone {
word-break: break-all;
}

看看下面的代码片段:

body {
background-color: #000;
}

.holding {
width: 500px;
background-color: red;
height: 500px;
padding: 40px 100px;
max-width: 400px;
width: fit-content;
}

.childone {
background-color: white;
display: inline;
padding: 20px;
float: left;
clear: both;
word-break: break-all;
}

.clear {
clear: both;
}

.childtwo {
background-color: white;
display: inline-block;
float: left;
padding: 10px;
}
<body>

<div class="holding">
<div class="childone">This is the Title and I really the div to end here with.no.extra.white.space </div>
<div class="clear"></div>
<div class="childtwo">This is the next child div with a bund of stuff.</div>
</div>

</body>

希望这有帮助!

关于html - 使 Div 适合其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47008126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com