I have two div containers that are placed next to each other. Both have the same size. Now I have a paragraph in the left container and I don´t want the paragraph to have a line break. Also, the container shouldn´t change its size.
Around these two div containers is another one with display: flex
, so that its two children are placed next to each other. For the paragraph, I have the following CSS styles.
white-space: nowrap;
overflow: hidden;
width: 300px;
It works for me like this, but I don´t want to give the exact size in px for the width. I want that it is the normal size of the div container and that this size can´t be exceeded. If it is, the container should remain the same size and the text of the paragraph should be cut off.
3
Answers
I think what you are looking for is one of these https://www.w3schools.com/cssref/pr_pos_overflow.php
and can be shown like this
im sorry if i got this wrong but your question is very hard to understand
you can try using my approach
I have contained the width to 272px
The classes
overflow-hidden
,text-ellipsis
, andwhitespace-nowrap
I have used these classes to solve this
Not sure what exactly you’re trying to do, but have you tried the CSS
text-overflow: ellipsis;
property?Let me show you how you can implement that:
HTML
This way you don’t have to hard code a fixed width to the paragraph tag, and as a bonus, the text cut off looks neater. Lemme know if it works out or you need any more help (preferably through the comments and not a down-vote 😅)