admin管理员组文章数量:1394066
I want my text to go back to line when it goes outside the box but just can't find how to.
Right now it goes back to line only when it would be outside the screen, not the box I want to put it in.
I know it's a lot of CSS for what I'm trying to do, but I'm trying to show what I've done until now.
h6 {
color: #89CFF0;
font-size: x-large;
text-align: center;
margin-top: 100px;
padding-top: 50px;
padding-bottom: 50px;
background-color: white;
border: 5px solid white;
border-radius: 10px;
box-sizing: content-box;
overflow-wrap: normal;
width: 80vw;
}
.h6Box {
width: 80vw;
overflow: hide;
position: block;
margin: 0 auto;
box-sizing: content-box;
overflow-wrap: normal;
}
<div class="h6Box">
<h6 style="text-align: left; padding-left: 2vw;">
text here
</h6>
</div>
<div class="h6Box">
<h6 style="text-align: left; padding-left: 2vw;">
text here
</h6>
</div>
I want my text to go back to line when it goes outside the box but just can't find how to.
Right now it goes back to line only when it would be outside the screen, not the box I want to put it in.
I know it's a lot of CSS for what I'm trying to do, but I'm trying to show what I've done until now.
h6 {
color: #89CFF0;
font-size: x-large;
text-align: center;
margin-top: 100px;
padding-top: 50px;
padding-bottom: 50px;
background-color: white;
border: 5px solid white;
border-radius: 10px;
box-sizing: content-box;
overflow-wrap: normal;
width: 80vw;
}
.h6Box {
width: 80vw;
overflow: hide;
position: block;
margin: 0 auto;
box-sizing: content-box;
overflow-wrap: normal;
}
<div class="h6Box">
<h6 style="text-align: left; padding-left: 2vw;">
text here
</h6>
</div>
<div class="h6Box">
<h6 style="text-align: left; padding-left: 2vw;">
text here
</h6>
</div>
Share
Improve this question
edited Mar 14 at 19:04
rozsazoltan
11.2k6 gold badges20 silver badges59 bronze badges
asked Mar 14 at 19:00
NoraNora
111 bronze badge
0
2 Answers
Reset to default 3overflow-wrap: normal;
does not force line breaks. Instead, you should use overflow-wrap: break-word;
.
overflow-wrap
CSS property - MDN Docs
Note: I simplified the example a bit. I added a background color so you can see when a word is too long and overflows the div, and when it breaks properly.
p {
display: inline-block;
margin: 0 3rem;
width: 100px;
background-color: black;
color: #89CFF0;
word-wrap: break-word;
overflow-wrap: break-word;
}
p.original {
overflow-wrap: normal;
}
p.new {
overflow-wrap: break-word; /* working */
}
<p class="original">
Most words are short & don't need to break. But Antidisestablishmentarianism is long. The width is set to min-content, with a max-width of 11em.
</p>
<p class="new">
Most words are short & don't need to break. But Antidisestablishmentarianism is long. The width is set to min-content, with a max-width of 11em.
</p>
.text-container {
word-wrap: break-word;
overflow-wrap: break-word;
}
本文标签: Text won39t go back to line html cssStack Overflow
版权声明:本文标题:Text won't go back to line html css - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744636560a2616856.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论