Like leaving a div next to each other?

Asked

Viewed 3,440 times

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>
  • You should elaborate more on the question, show what you tried, explain the question better, don’t just put code and wait for an answer. You should use float:left

1 answer

1

One way to place them side by side is with float:left. I take this opportunity to say the property left has no effect on static positioned elements such as yours, 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 to do the same is with display:flex which involves creating an element comprising the two Ivs:

* {
    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:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.