Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two div blocks on same line

Tags:

html

css

How to center on the same "line" two div blocks?

First div:

<div id=bloc1><?php echo " version ".$version." Copyright &copy; All Rights Reserved."; ?></div>   

Second div:

<div id=bloc2><img src="..."></div> 
like image 523
Bertaud Avatar asked May 04 '12 15:05

Bertaud


People also ask

Can we place two div blocks at same line?

To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values. The value left indicates the div tag will be made to float on the left and right to float the div tag to the right.

How do I make two divs display on the same line?

You can use display: inline to put the two div elements inline. Explanation: div elements are block elements, so their display style is usually display: block . You can wrap both the div elements in a span tag. Explanation: span works the same way as the div , to organize and group elements.

How do you make a div on the same line?

You can use display:inline-block . This property allows a DOM element to have all the attributes of a block element, but keeping it inline. There's some drawbacks, but most of the time it's good enough.

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

You need to set the Div to be 'display: inline' to appear next to the span element.


2 Answers

CSS:

#block_container {     text-align:center; } #bloc1, #bloc2 {     display:inline; } 

HTML

<div id="block_container">      <div id="bloc1"><?php echo " version ".$version." Copyright &copy; All Rights Reserved."; ?></div>       <div id="bloc2"><img src="..."></div>  </div> 

Also, you shouldn't put raw content into <div>'s, use an appropriate tag such as <p> or <span>.

Edit: Here is a jsFiddle demo.

like image 58
MrCode Avatar answered Sep 28 '22 11:09

MrCode


You can do this in many way.

  1. Using display: flex

#block_container {      display: flex;      justify-content: center;  }
<div id="block_container">    <div id="bloc1">Copyright &copy; All Rights Reserved.</div>    <div id="bloc2"><img src="..."></div>  </div>
  1. Using display: inline-block

#block_container {      text-align: center;  }  #block_container > div {      display: inline-block;      vertical-align: middle;  }
<div id="block_container">    <div id="bloc1">Copyright &copy; All Rights Reserved.</div>    <div id="bloc2"><img src="..."></div>  </div>
  1. using table

<div>      <table align="center">          <tr>              <td>                  <div id="bloc1">Copyright &copy; All Rights Reserved.</div>              </td>              <td>                  <div id="bloc2"><img src="..."></div>              </td>          </tr>      </table>  </div>
like image 42
Super User Avatar answered Sep 28 '22 11:09

Super User