'How to fit a paragraph element inside its parent container?
Solution 1:[1]
The word-break CSS property is used to specify whether to break lines within words.
div {
width: 50px;
border: 1px solid black;
word-break: break-all;
}
<div>Loremipsumdolorsit.</div>
The word-wrap property is used to specify whether or not the browser may break lines within words in order to prevent overflow when an otherwise unbreakable string is too long to fit in its containing box.
div {
width: 50px;
border: 1px solid black;
}
div a {
word-wrap: break-word;
}
<div>
<a href="">Loremipsumdolorsit.</a>
</div>
Solution 2:[2]
You can try text-overflow: ellipsis;
Learn more on MDN.
p {
width: 400px;
border: 1px solid aqua;
}
a {
display: inline-block;
white-space: nowrap;
width: 100%;
overflow: hidden; /* "overflow" value must be different from "visible" */
text-overflow: ellipsis;
}
<p><a href="#">http://stackoverflow.com/questions/34754716/how-to-fit-a-paragraph-tag-inside-its-parent-container</a></p>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |