Advertisement
Advertisement


Two div blocks on same line


Question

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>
2012/05/04
1
54
5/4/2012 3:18:30 PM

Accepted Answer

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.

2012/05/04
80
5/4/2012 3:48:59 PM


I think now, the best practis is use display: inline-block;

look like this demo: https://jsfiddle.net/vjLw1z7w/

2016/06/21

You can use a HTML table:

<table>
<tr>
<td>
<div id="bloc1">your content</div>
</td>
<td>
<div id="bloc2">your content</div>
</td>
</tr>
</table>   
2014/01/15

Try an HTML table or use the following CSS :

<div id="bloc1" style="float:left">...</div>
<div id="bloc2">...</div>

(or use an HTML table)

2012/05/04

diplay:flex; is another alternative answer that you can add to all above answers which is supported in all modern browsers.

#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>

2017/04/15

Use a table inside a div.

<div>
   <table style='margin-left: auto; margin-right: auto'>
        <tr>
           <td>
              <div>Your content </div>
           </td>
           <td>
              <div>Your content </div>
           </td>
        </tr>
   </table>
</div>
2015/09/14