Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - how to put div right to another div?

<body>
        <div class="main-div">
            <table id="gameboard-table"></table>
        </div>
        <div class="main-div">
            Waiting for X players to join
            <div> Player 1 - </div>
            <div> Player 2 - </div>
            <div> Player 3 - </div>
            <div> Player 4 - </div>
        </div>
</body>

The first div has a table that is being created dynamically, that second one is static.

I've tried to use

.main-div {
    float: left;
}

but the divs are still one beneath the other.

Of course I didn't forget to include the CSS file in the html :)

How can I solve it?

thanks!!!

like image 662
user3364652 Avatar asked Sep 21 '14 11:09

user3364652


People also ask

How do I put a div on the right side of another div?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

How do I put div next to each other in CSS?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How do I align two divs side by side in CSS?

To position the divs side by side, we are using the float property to float each . float-child element to the left. Since they are both floating to the left, they will display side by side if there's enough space for both to fit.


1 Answers

You need to set their width, because otherwise they just fill to 100%.

.main-div {
    float: left;
    width: 50%;
}
like image 156
Scimonster Avatar answered Oct 03 '22 07:10

Scimonster