How to leave one div next to the other?

0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">

    * {
        margin: 0;
        padding: 0;
        vertical-align: baseline;
        }
    body {
        width: 100%;
        background-color: black;
    }
    .loren{
        display: block;
        left: 0;
        width: 50%;
    }
    .ipsulum{
        display: block;
        left: 0;
        width: 50%;
    }
    p {
        margin: 5px;
        font-family: Arial;
        font-size: 15pt;
        font-weight: bold;
        background-color: gray;
        color: white;
    }

</style>
</head>
<body>

<div class="loren">
<p>Loren</p>
</div>
<div class="ipsulum">
<p>Ipsulum</p>
</div>

</body>
</html>
    
asked by anonymous 13.11.2017 / 01:52

1 answer

1

One way to put them side by side is with float:left . I take it to say the property left has no effect for elements statically positioned as is your case, and that display:block is the display by default for a <div>

Example with float:left :

* {
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}
body {
    width: 100%;
    background-color: black;
}
.loren{
    float:left; /*<---*/
    width: 50%;
}
.ipsulum{
    float:left; /*<---*/
    width: 50%;
}
p {
    margin: 5px;
    font-family: Arial;
    font-size: 15pt;
    font-weight: bold;
    background-color: gray;
    color: white;
}
<div class="loren">
    <p>Loren</p>
</div>
<div class="ipsulum">
    <p>Ipsulum</p>
</div>

Another way of doing the same is with display:flex which implies creating an element that encompasses the two divs:

* {
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}
body {
    width: 100%;
    background-color: black;
}
.loren{
    width: 50%;
}
.ipsulum{
    width: 50%;
}
p {
    margin: 5px;
    font-family: Arial;
    font-size: 15pt;
    font-weight: bold;
    background-color: gray;
    color: white;
}

.conteudo {
    display:flex; /*<--*/
}
<div class="conteudo"> <!--div para conter os dois já existentes-->
  <div class="loren">
      <p>Loren</p>
  </div>
  <div class="ipsulum">
      <p>Ipsulum</p>
  </div>
</div>

Documentation:

13.11.2017 / 02:01