Two div blocks on same line

后端 未结 11 1165
小蘑菇
小蘑菇 2020-11-30 21:09

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

First div:

相关标签:
11条回答
  • 2020-11-30 21:51

    What I would first is make the following CSS code:

    #bloc1 {
       float: left
    }
    

    This will make #bloc2 be inline with #bloc1.

    To make it central, I would add #bloc1 and #bloc2 in a separate div. For example:

    <style type="text/css">
        #wrapper { margin: 0 auto; }
    </style>
    <div id="wrapper">
        <div id="bloc1"> ... </div>
        <div id="bloc2"> ... </div>
    </div>
    
    0 讨论(0)
  • 2020-11-30 21:53

    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.

    0 讨论(0)
  • 2020-11-30 21:53

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

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

    0 讨论(0)
  • 2020-11-30 22:01

    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>   
    
    0 讨论(0)
  • 2020-11-30 22: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>

    0 讨论(0)
提交回复
热议问题