Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML+CSS: How to force div contents to stay in one line?

Tags:

html

css

I have a long text inside a div with defined width:

HTML:

<div>Stack Overflow is the BEST!!!</div> 

CSS:

div {     border: 1px solid black;     width: 70px; } 

How could I force the string to stay in one line (i.e. to be cut in the middle of "Overflow")?

I tried to use overflow: hidden, but it didn't help.

like image 607
Misha Moroshko Avatar asked Mar 08 '11 12:03

Misha Moroshko


People also ask

How do I force text to stay on one line in CSS?

If you want to limit the text length to one line, you can clip the line, display an ellipsis or a custom string. All these can be done with the CSS text-overflow property, which determines how the overflowed content must be signalled to the user.

How do I make a div not break a line?

Set size and make inline Because they're block elements, when reducing the size of Div one to make room for the other div, you're left with space next to Div one and Div two below Div one. To move the div up to the next line both div's need to have the inline-block display setting as shown below.

How do you make elements stay on the same line in HTML?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do I show a div element in one line?

Approach 1: In this approach, we have set the display: flex and flex-direction: row to the parent div of all the div elements. Due to the flex-direction: row property all the elements inside the parent div will be shown in a single row.


1 Answers

Try this:

div {     border: 1px solid black;     width: 70px;     overflow: hidden;     white-space: nowrap; } 
like image 118
Bazzz Avatar answered Sep 21 '22 03:09

Bazzz