Basickz
Basickz

Reputation: 61

How can i place 2 divs next to eachother

I try to put 2 divs next to eachother but somehow it places them under eachother.

I have looked it up on this forum and copied the css code for it but it still wont work, i think it has something to do with my php code i use in it.

<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
 <header>
<nav>
    <p><a href="index.php"><img src="img/handboeklogo.png"></a></p>
    <ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="#">Checklist</a>
            <ul>
                <li><a href="#">Desktops</a></li>
                <li><a href="#">Laptops</a></li>
                <li><a href="#">Monitoren</a></li>
            </ul>
        </li>
        <li><a href="#">Handboek</a>
            <ul>
                <li><a href="#">Desktops</a></li>
                <li><a href="#">Laptops</a></li>
                <li><a href="#">Monitoren</a></li>
                <li><a href="#">Printers</a></li>
                <li><a href="#">Mobiele Telefoons</a></li>
            </ul>
        </li>
        <li><a href="#">Classificatielijst</a><ul>
                <li><a href="#">Desktops</a></li>
                <li><a href="#">Laptops</a></li>
                <li><a href="#">Monitoren</a></li>
                <li><a href="#">Printers</a></li>
                <li><a href="#">Mobiele Telefoons</a></li>
            </ul>
        </li>


<form class='logout' method='POST' action=''>
        <button type='submit' name='logoutSubmit'>Logout</button>
    </form>
</nav>
</header>
<br><br>


<div id='maindiv'><div id='first'>





<form method='POST' action=''>
            <input type='hidden' name='uid' value='1'> 
            <input type='hidden' name='date' value='2019-07-02'> 
            <textarea name='message'></textarea><br>
            <button type='submit' name='commentSubmit'> Comment </button>
        </form></div>

<div id='second'>



<form method='POST' action=''>
            <input type='hidden' name='uid' value='1'> 
            <input type='hidden' name='date' value='2019-07-02'> 
            <textarea name='message'></textarea><br>
            <button type='submit' name='Generalcommentsubmit'> Comment </button>
        </form></div></div>
</body>
</html>

CSS code:

body {
    background-color: #edf0f2;
}

textarea {
    display: inline-block;
    width: 630px;
    height: 120px;
    background-color: #fff;
    border-color: #5bb112;
    margin-top: 10px;
    margin-left: 15px;
    position: relative;
    resize: none;
}

.Changelog {
    margin-left: 15px;
    width: 800px;
}

.logout {
    display: inline-block;
    float: right;
    position: absolute;
    margin-top: 27px;
    margin-right: 20px;
    margin-left: 680px;
}

.login {
    display: inline-block;
    float: right;
    position: absolute;
    margin-top: 27px;
    margin-right: 20px;
    margin-left: 330px;
}
/*
button {
    width: 100px;
    height: 30px;
    background-color: #5bb112;
    border: none;
    color: #e2e2e2;
    font-family: arial;
    font-weight: 400;
    cursor: pointer;
    margin-bottom: 19px;
    margin-left: 15px;
    margin-top: 3px;
}

.comment-box {
    width: 630px;
    padding-top: 5px;
    margin-bottom: 4px;
    background-color: #fff;
    border-radius: 1px;
    position: absolute;
    border: 1px solid #5bb112;
    margin-top: 8px;
    align-content: left;
}

.comment-box p {
    font-family: arial;
    font-size: 14px;
    line-height: 16px;
    color: #282828;
    font-weight: 100;
    margin-bottom: 10px;
    margin-left: 5px;
}

.edit-form {
    position: absolute;
    top: 3px;
    right: 3px;
}

.edit-form button {
    width: 40px;
    height: 20px;
    color: #282828;
    background-color: #fff;
    opacity: 0.7;
}

.edit-form button:hover {
    opacity: 1;
}

.delete-form {
    position: absolute;
    top: 3px;
    right: 58px;
}

.delete-form button {
    width: 40px;
    height: 20px;
    color: #282828;
    background-color: #fff;
    opacity: 0.7;
}

.delete-form button:hover {
    opacity: 1;
}*/

* {
    margin: 0;
    padding: 0;
}

header nav {
    width: 100%;
    height: 80px;
    background-color: #343131;
}

header nav p {
    font-family: arial;
    color: #b3b3b3;
    font-size: 24px;
    line-height: 55px;
    float: left;
    padding: 10px 20px;
}

header nav ul {
    float: left;
    z-index: 2;
}

header nav ul li {
    float: left;
    list-style: none;
    position: relative;
    margin-top: 15px;
    margin-right: auto;
    margin-left: 30px;
}

header nav ul li a {
    display: block;
    font-family: arial;
    color: #b3b3b3;
    font-size: 20px;
    padding: 21px 14px;
    text-decoration: none;
}

header nav ul li ul {
    display: none;
    position: absolute;
    background-color: #343131;
    border-radius: 0px 0px 4px 4px;
    padding: 8px;
}

header nav ul li:hover ul {
    display: block;
}

header nav ul li ul li  {
    width: 180px;
    border-radius: 4px;
}

header nav ul li ul li a {
    padding: 9px 14px;
}

header nav ul li ul li a:hover {
    background-color: #343131;
}

header nav p img {
    width: 210px;
    height: 55px;
    margin-top: 5px;
    margin-bottom: 5px;
}


header nav ul li a:hover {opacity: 1}

header nav ul li a {
    background-color: #343131;
    border: none;
    color: white;
    opacity: 0.6;
    transition: 0.3s;
}


.down {
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
}

i {
  border: solid white;
  border-width: 0 3px 3px 0;
  display: inline-block;
  padding: 3px;
  margin-left: 10px;
  margin-bottom: 3px;
  }

/*-------Changelog---------*/

#maindiv {
    display: flex;
    width: auto;
    border: 1px solid black;
    overflow: hidden;
}
#first {
    width: auto;
    float:left;

}
#second {
    float: left; 
}


I would like to place the divs next to eachother so i get 2 comment sections next to eachother.

Upvotes: 0

Views: 643

Answers (4)

L. Wolf
L. Wolf

Reputation: 86

To place 2 divs near eachother wrap them in another div and set display to 'flex'

<div id="maindiv'>
   <div id='first'>
      //content here
   </div>
   <div id='second'>
      //content here
   </div>
</div>

in css

#maindiv {
  display: flex;
  width: 500px;
  border: 1px solid black;
  overflow: hidden;
}
#first {
  width: 300px;
}
#second {

} 

Upvotes: 1

distorsium
distorsium

Reputation: 21

#first, #second, #maindiv{
  display: inline-block;
}
#maindiv {
   width: 500px;
}
#first {
  width: 300px;
}
<div id='maindiv'>
  <div id='first'>first</div>
  <div id='second'>second</div>
</div>

Upvotes: 0

Sai Manoj
Sai Manoj

Reputation: 3849

You can use display:inline-block as div element display is set to block by default

.parent {
  background: red;
  height: 50px;
  width: 50px;
  margin: 10px;
  display: inline-block
}
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>
<div class="parent">

</div>

Upvotes: 0

TOMBA
TOMBA

Reputation: 205

From your current code I could just guess that problem is with display, try this

#maindiv {
    display: inline-block;
    width: 500px;
    border: 1px solid black;
    overflow: hidden;
}

Upvotes: 0

Related Questions