Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html css make div be on the same line as text

Tags:

html

css

My question is, how do I avoid having the text on a new row?

My code:

<html>
<body>
<p >Seating availability.</p>
<p ><div style="width: 10px; height: 10px; background-color: green; border: 0px;" ></div> There are available seats.</p>
<p ><div style="width: 10px; height: 10px; background-color: yellow; border: 0px;" ></div> Available seats are decreasing.</p>
<p ><div style="width: 10px; height: 10px; background-color: orange; border: 0px;" ></div> Less than 15% of seats available.</p>
<p ><div style="width: 10px; height: 10px; background-color: red; border: 0px;" ></div> There are no available seats.</p>
</body>
</html>

How should I code this?

like image 296
Andreas Avatar asked Oct 30 '13 11:10

Andreas


People also ask

How do I make text stay on the same 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 keep text and links on the same line in HTML?

display: inline-block; in CSS. You can also use style="display: inline-block;" directly in the HTML tag.

How do I make a div and span in one line?

If all the text has to be on one line then you have to set the div and p elements to inline or inline-block , the span and a elements are already inline.


2 Answers

add display: inline-block to div

<html>
 <head>
  <style>
   div
   {
     display: inline-block;
   }
</style>
</head>
<body>
<p >Seating availability.</p>
<p><div style="width: 10px; height: 10px; background-color: green; border: 0px;" ></div>There are available seats.</p>
<p ><div style="width: 10px; height: 10px; background-color: yellow; border: 0px;" ></div> Available seats are decreasing.</p>
<p ><div style="width: 10px; height: 10px; background-color: orange; border: 0px;" ></div> Less than 15% of seats available.</p>
<p ><div style="width: 10px; height: 10px; background-color: red; border: 0px;" ></div> There are no available seats.</p>
</body>
</html>
like image 86
Laerte Sousa Neto Avatar answered Sep 22 '22 22:09

Laerte Sousa Neto


There are so many display properties are available:

Try using display:inline-block;

div style="width: 10px; height: 10px; background-color: green; border: 0px;display:inline-block;" ></div>

Hope this helps!

fiddle-Demo

Remove <p></p> tag just use <div> as <p> is always takes new line.

Updated Fiddle

like image 44
Dhaval Marthak Avatar answered Sep 25 '22 22:09

Dhaval Marthak