You need to set the .portfolio-info
to display: block
, and set it's white-space
to no-wrap
, keeping the text in one line. You can't have block-level elements like h2
in an inline element so I changed it to a span
. You can then set a fixed or percentage-based width to keep that div in the container at a specified size. Then, all you need to do is just set the .portfolio-info
to text-overflow: ellipsis
, making the overflowing text end with an ellipsis character.
If possible, avoid using inline attributes like height
and style
, use plain CSS instead to keep the markup and the styling separate.
<div class="portfolio-wrapper">
<div class="portfolio-single">
<div class="portfolio-thumb">
<img src="http://placekitten.com/300" alt="">
</div>
</div>
<div class="portfolio-info">
<span>Very long text that will likely overflow the container, making the text too long to fit into this square, meaning to goes to a new line</span>
</div>
.portfolio-wrapper {
display: inline-block;
width: 300px;
border: 1px solid #000;
padding: 10px;
}
.portfolio-single {
margin: 0px 0px 10px;
}
.portfolio-single,
.portfolio-thumb,
.portfolio-thumb img {
height: 300px;
width: 300px;
}
.portfolio-info {
border: 1px dotted gray;
display: block;
overflow: hidden;
white-space: nowrap;
max-width: 300px;
text-overflow: ellipsis;
}
JSFiddle of this example