如何在CSS中并排放置两个div?

时间:2017-03-20 18:08:25

标签: html css

.navbar {
  overflow: hidden;
  background-color: antiquewhite;
  position: absolute;
  top: 0;
  width: 100%;
}

.navbar a {
  float: right;
  display: block;
  color: Black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 22px;

}
.container {
    width: 80%;
    background: aqua;
    margin: auto;
    padding: 10px;
}

.main {
  padding: 16px;
  margin-top: 30px;
  width:1000px;
  margin-left:15px;
}

#navbarItem {
   list-style-type: none;
   margin: 0;
   padding:0;
}

li a:hover {
    background-color: #b6ff00;
    color: white;
}


.main{
    padding-top:100px;
    padding-left:100px;
    padding-right:100px;
    border: 1px solid green;
}

.navbar2{
    width:15%;
    float:left;
    border: 2px solid red;
}

如何在容器div中放置两个div(.main和.navbar2)?我想把main和navbar div放在容器中。我将导航栏固定,这样当我向下滚动它将保持其位置。稍后我可能会在网站右侧添加第3个div。

1 个答案:

答案 0 :(得分:0)

HTML:

    <div id="wrapper">
        <div id="leftcolumn">
            Left
        </div>
        <div id="rightcolumn">
            Right
        </div>
    </div>

CSS:

    body {
        background-color: #444;
        margin: 0;
    }    
    #wrapper {
         width: 1005px;
         margin: 0 auto;
    }
    #leftcolumn, #rightcolumn {
        border: 1px solid white;
        float: left;
        min-height: 450px;
        color: white;
    }
    #leftcolumn {
         width: 250px;
         background-color: #111;
    }
    #rightcolumn {
         width: 750px;
         background-color: #777;
    }