如何在同一行中创建div

时间:2014-09-09 15:55:17

标签: html alignment

我创建了3个div:

  • 菜单
  • 显示区域

我创建了三个标签,我需要在同一行中对齐两个div - 左边的菜单div和右边的显示。

我收到错误,因为我尝试了很多例子,但没有一个能够正常运作。

  • 标题应固定在顶部
  • 和其他人应该一样

可能是什么问题,我该如何解决?

HTML

<html lang="en" class="no-js">
<head>
    <meta charset="UTF-8" />
    <title>Blueprint: Vertical Icon Menu</title>
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" type="text/css" href="css/leftmenu.css" />
    <link rel="stylesheet" type="text/css" href="flaticon.css" />
    <script src="js/modernizr.custom.js"></script>
    <style>
        body {position: relative;font-family: 'Lato', Calibri, Arial, sans-serif;    color: #47a3da;}
        body, html { font-size: 100%; height: 100%; padding: 0; margin: 0;}
        a {color:#f0f0f0;text-decoration: none;}
        a:hover {color: #000;}
        #footer{height: 50px;background-color: #ddd;width: 100%;}
        #header{z-index: 1;top: 0;margin-top: 0px;position: fixed;height: 90px;width: 100%;background-color: #ddd;}
        .dis123{width: 500px;height: 500px;background-color: #ddd;text-align: left;

                display: block;
                margin-left: auto;
                margin-right: auto;}
        </style>
    </head>
    <div id="header">
    Head
</div>
<body>
    <div class="postleftmen">
        <ul class="cbp-vimenu">
            <li><a href="#" class="">SELECT CATEGORY</a></li>
            <li><a href="#" class="flaticon-smart">MOBILE&nbsp;&&nbsp;TABLET</a></li>
            <li><a href="#" class="flaticon-pc6">ELECTRONICS&nbsp;&&nbsp;COMPUTER</a></li>
            <li><a href="#" class="flaticon-car95">Vehicles</a></li>
            <li><a href="#" class="flaticon-livingroom6">Home&nbsp;&&nbsp;Furniture</a></li>
            <li><a href="#" class="flaticon-pets3">Pets</a></li>
            <li><a href="#" class="flaticon-cd">Books,&nbsp;CDs&nbsp;&&nbsp;Hobbies</a></li>
            <li><a href="#" class="flaticon-black276">Clothing&nbsp;&&nbsp;Accessories</a></li>
            <li><a href="#" class="flaticon-baby23">Kids&nbsp;&&nbsp;Baby</a></li>
            <li><a href="#" class="flaticon-bicycle14">Sports&nbsp;&&nbsp;Health</a></li>
            <li><a href="#" class="flaticon-tools6">Services</a></li>
            <li><a href="#" class="flaticon-businessman221">Jobs</a></li>
            <li><a href="#" class="flaticon-house111">Real&nbsp;Estate</a></li>
        </ul>
    </div>
    <div class="dis123">
        display
    </div>
    <div id="footer">
        footer
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要使用float:left属性,在行中显示两个 DIVS 。然后使用clear:both div来放置页脚。

<强> HTML

    <div id="header">
    Head
</div>
    <div class="postleftmen">
        <ul class="cbp-vimenu">
            <li><a href="#" class="">SELECT CATEGORY</a></li>
            <li><a href="#" class="flaticon-smart">MOBILE&nbsp;&&nbsp;TABLET</a></li>
            <li><a href="#" class="flaticon-pc6">ELECTRONICS&nbsp;&&nbsp;COMPUTER</a></li>
            <li><a href="#" class="flaticon-car95">Vehicles</a></li>
            <li><a href="#" class="flaticon-livingroom6">Home&nbsp;&&nbsp;Furniture</a></li>
            <li><a href="#" class="flaticon-pets3">Pets</a></li>
            <li><a href="#" class="flaticon-cd">Books,&nbsp;CDs&nbsp;&&nbsp;Hobbies</a></li>
            <li><a href="#" class="flaticon-black276">Clothing&nbsp;&&nbsp;Accessories</a></li>
            <li><a href="#" class="flaticon-baby23">Kids&nbsp;&&nbsp;Baby</a></li>
            <li><a href="#" class="flaticon-bicycle14">Sports&nbsp;&&nbsp;Health</a></li>
            <li><a href="#" class="flaticon-tools6">Services</a></li>
            <li><a href="#" class="flaticon-businessman221">Jobs</a></li>
            <li><a href="#" class="flaticon-house111">Real&nbsp;Estate</a></li>
        </ul>
    </div>
    <div class="dis123">
        display
    </div>
    <div style="clear:both"> </div>
<div id="footer">
    Footer
</div>

<强> CSS

body {position: relative;font-family: 'Lato', Calibri, Arial, sans-serif;    color: #47a3da;}
body, html { font-size: 100%; height: 100%; padding: 0; margin: 0;}
a {color:#f0f0f0;text-decoration: none;}
a:hover {color: #000;}
#header{height: 90px;width: 100%;background-color: #ddd;}
#footer
{
  height: 50px;width: 100%;background-color: #ddd;
}
.dis123
{
    width:60%;
    float:left; height: 500px;background-color: #ddd;text-align: left;
}
.postleftmen
{
    width:40%;
    float:left;
}

<强> DEMO