内部 div 没有推动其他 div,无法弄清楚:两者都有;上班



我对<div> s有一些问题。内部<div>(content-div)不会推送外部<div>(wrap_content)。

让我发布代码,这样你就有机会看到可能出了什么问题。

style.css

* {
    padding: 0px;
    margin: 0px;
}
body {
background: #e2e2e2;
color: #f2f2f2;
font-family: Arial;
}
#wrap_design {
width: 1139px;
}
#wrap_content { 
float: right;
max-width: 963px;
height: 100%;
border-right: 8px solid #2d2828;
border-left: 8px solid #2d2828;
border-bottom: 8px solid #2d2828;
padding-bottom: 10px;
}
#header {
height: 236px;
width: 963px;
background-color: #2d2828;
}
#headerimg{
z-index: 1;
margin-left: -26px;
}
#loggedin_box {
min-height: 230px;
width: 160px;
background: #2d2828;
float: left;
margin-top: 236px;
position: static;
padding-bottom: 5px;
}
#loggedin_box_green {
height: 30px:
width: 150px;
background: #73aa09;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
margin-left: 10px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
letter-spacing: 2px;
}
#loggedin_box ul {
border: none;
}
#loggedin_box ul li {
list-style: none;
text-align: left;
}
#loggedin_box ul li a {
font-family: Arial;
font-size: 14px;
color: #b1b2b2;
text-decoration: none;
padding-left: 5px;
}

#menu_container {
margin: 0px 0px 0px 0px;
background: #2d2828;
font-family: Arial;
    width: 100%;
    margin: 0px auto;
    height: 65px;
}
#content {
color: black;
vertical-align: top;
height: 100%;
margin-bottom: 10px;
clear: both;
}
#content-sidebar {
border-left: 2px solid #2d2828;
float: right;
width: 285px;
max-width: 285px;
height: 100%;
}

index.php

<html>
<head>
<link rel="shortcut icon" href="images/nfgico.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/style/style.css" type="text/css" />
</head>
<body>
<CENTER>
<div id="wrap_design">
<div id="loggedin_box">
<?php
    if($_SESSION['username'] == "") {
?>
    <div id="loggedin_box_green">Log ind</div>
    <div style="text-align: left; padding-left: 10px;">
        <form action="login_check.php" method="post">
            <input type="text" value="Brugernavn" name="username" style="width: 140px;" onclick="this.value=''"><br /><br />
            <input type="password" value="password" name="password" style="width: 140px;" onclick="this.value=''"><br /><br />
            <font style="font-family: Arial; font-size: 12px;">Husk mig:</font><input style="margin-left:15px;" type="checkbox" name="rememberme" class="checkbox" value="1" /><br /><br />
            <input type="submit" value="Log ind"><br /><br />
        </form>
        <ul>
            <li><a href="#">Glemt kodeord</a></li>
            <li><a href="/create_user.php">Opret bruger</a></li>
        </ul>   
    </div>
<?php   
    } else {
?>
    <div id="loggedin_box_green">Network</div>
        <ul>
            <li><a href="#">Wall</a></li>
            <li><a href="#">Profil</a></li>
            <li><a href="#">Chat</a></li>
            <li><a href="#">Achievements</a></li>
            <li><a href="#">Clanside</a></li>
            <li><a href="#">Søg modstander</a></li>
            <li><a href="#">Søg spil</a></li>
            <li><a href="/index.php?logout=yes">Log ud</a></li>
        </ul>
<?php
    }
?>
</div>
<div id="wrap_content"> <!-- This is the one that needs to be pushed -->
    <div id="header">
        <img src="/images/banner.png" id="headerimg">
    </div>
    <div id="menu_container">
                <div id="droplinetabs1" class="droplinetabs">
                    <ul>
                    <li><a href="/"><span>Forside</span></a></li>
                    <li><a href="#"><span>Nyheder</span></a>
                        <ul>
                            <li><a href="#">Seneste</a></li>
                            <li><a href="#">lol</a></li>
                            <li><a href="#">loool</a></li>
                            <li><a href="#">loool</a></li>
                        </ul>
                    </li>
                    <li><a href="#"><span>Artikler</span></a></li>
                    <li><a href="#"><span>Spil</span></a></li>
                    <li><a href="#"><span>Turneringer</span></a></li>
                    <li><a href="#"><span>Clan</span></a></li>
                    <li><a href="#"><span>Streams</span></a></li>
                    <li><a href="#"><span>Webshop</span></a></li>
                    </ul>
                </div>
    </div>      
        <!-- Content/brødtekst -->
    <div id="content">
        CONTENT GOES HERE THIS IS WHAT NEED TO PUSH
    </div>  
</div>
</CENTER>
</body>
</html>

index.php中有一些代码我没有发布,因为我希望你不需要它:)

我真的希望有人能帮助我!ps。我在互联网上做了一些研究,知道我应该使用clear: both;,但我真的无法使用它。

#wrap_content style中删除height: 100%(它会引起问题),然后为了确保它包裹住任何浮点元素,添加宽度和溢出,如下所示:

#wrap_content { 
    float: right;
    max-width: 963px;
    border-right: 8px solid #2d2828;
    border-left: 8px solid #2d2828;
    border-bottom: 8px solid #2d2828;
    padding-bottom: 10px;
    width: auto; /* Must use this for overflow to do what you want */
    overflow: hidden; /* This, plus width, causes box to stretch around floated elements inside of it */
}

需要注意的是,里面有相当多不必要的css。我鼓励你仔细阅读并修改/删除它。你可以用一半的css来完成你想要的。

删除所有的"高度:100%;"到处-如果不做你认为它会做的。

我建议删除您的CENTER,并使您的#wrap_design如下所示:

    #wrap_design
    {
        margin: 0 auto;
        width: 1139px;
    }

这会使你的包装居中——我强烈建议不要居中。如果你想更改这个包装的页边空白(即从上到下20像素),请执行以下操作:20像素auto;。

您不需要使用clear:both;必要地在一个float(或多个float)的包装中,您只需放置overflow:hidden(相同效果),不需要额外的标记:

    <style type="text/css">
    .container
    {
        background: #CCC;
        border: 1px solid #ddd;
        overflow: hidden;
        width: 400px;
    }
    .left
    {
        float: left;
    }
    .right
    {
        float: right;
    }
</style>
<div class="container">
    <div class="left">
        this will float left
    </div>
    <div class="right">
        this will float left
    </div>
</div>

如果你在这个例子中没有"溢出:隐藏",你就不会在.contacter.中看到"#CCC"背景色

这和做清楚的方法是一样的(但上面的方法更好,因为标记更少):

<style type="text/css">
    .container
    {
        background: #CCC;
        border: 1px solid #ddd;
        width: 400px;
    }
    .left
    {
        float: left;
    }
    .right
    {
        float: right;
    }
    .clear 
    {
        clear: both;
    }
</style>
<div class="container">
    <div class="left">
        this will float left
    </div>
    <div class="right">
        this will float left
    </div>
    <div class="clear"></div>
</div>

Clear方法在这种情况下很好(当你想要一个"在父母之外"的孩子时):

    <style type="text/css">
    .container
    {
        background: #CCC;
        border: 1px solid #ddd;
        margin: 50px auto;
        width: 400px;
    }
    .left
    {
        float: left;
    }
    .right
    {
        background-color: #333;
        color: #FFF;
        float: right;
        margin: -10px -40px 0 0;
    }
    .clear 
    {
        clear: both;
    }
</style>
<div class="container">
    <div class="left">
        this will float left
    </div>
    <div class="right">
        this will float left
    </div>
    <div class="clear"></div>
</div>

但是,我不建议标记,如果你的设计可能不同,你也可以使用这样的清晰:

    <style type="text/css">
    .container
    {
        background: #CCC;
        border: 1px solid #ddd;
        margin: 50px auto;
        width: 400px;
    }
    .left
    {
        float: left;
        width: 200px;
    }
    .right
    {
        background-color: #333;
        color: #FFF;
        float: right;
        margin: -10px -40px 0 0;
        width: 240px;
    }
    .full
    {
        background: #f5f5f5;
        clear: both;
        margin: 20px auto;
        text-align: center;
        width: 90%;
    }
</style>
<div class="container">
    <div class="left">
        this will float left
    </div>
    <div class="right">
        this will float left
    </div>
    <div class="full">
        this is full sized
    </div>
</div>

如果您遵循以下示例,您应该解决您的问题:)

最新更新