CSS布局:div内的Div等

时间:2011-07-13 23:55:08

标签: css layout html

所以我的CSS布局一切正常,直到我想在我的网页的内容区域添加一些。

我正在尝试添加到内容部分的是一个包装盒,其中包含左侧的图形和右侧的一堆小信息框,并且可能是这两个下面的信息区域,宽度为100%内容框。

但是一旦我添加它,它就会将我的用户信息部分推到内容之下。 = /所以我想问的是如何在我的内容部分创建div的容器,这些容器不会影响我的侧边栏这样的东西?

这是我的代码:

        <div id="wrapper">
                <div id="header"> </div><!-- #header-->
            <div id="nav"> </div>
            <div id="middle">
                <div id="container">
                    <div id="content"><!-- content -->
                        <div id='containerGraph'>
                           <div id='sngAnimals'></div>
                           <div id='graph'><img src='./lib/pChart2.1.1/examples/chartAnimalKillsPerDay.php' width='x' height='y' id='graphImg'/></div>
                           <div id='bottomCont'></div></div>
                    </div><!-- #content-->
                </div><!-- #container-->
                <div class="sidebar" id="sideLeft">
                    User info
                </div><!-- .sidebar#sideLeft -->
            </div><!-- #middle-->
        </div><!-- #wrapper -->

和css:

* {
    margin: 0;
    padding: 0;
}
html {
    height: 100%;
}
body {
    font: 12px/18px Arial, Tahoma, Verdana, sans-serif;
    width: 100%;
    height: 100%;
    background-image:url('/mcimages/bg.png');
}
#wrapper {
    width: 1000px;
    margin: 0 auto;
    min-height: 100%;
    height: auto !important;
    height: 100%;
    color: white;
}

/* Middle
-----------------------------------------------------------------------------*/
#middle {
    width: 100%;
    padding: 0 0 100px;
    height: 1%;
    position: relative;

}
#middle:after {
    content: '.';
    display: block;
    clear: both;
    visibility: hidden;
    height: 0;
}
#container {
    width: 100%;
    float: left;
    overflow: hidden;
    margin-top: 10px;
    margin-bottom: 10px;

}
#content {
    padding: 10px 0 10px 195px;
    background: #666666;

}

#containerGraph {
border-style:solid;
border-width:5px;
width: 75%;
position:relative;

}

#graph {
width: 249px;
height: 210px;
border-style:solid;
border-width:5px;
position: relative;
float:left;


}

#sngAnimals {
width:50%;
height: 210px;
border-style:solid;
border-width:5px;
position: relative;
float:right;

}

#bottomCont{
position: relative;
clear:both;
}
 }

/* Sidebar Left
-----------------------------------------------------------------------------*/

#sideLeft {
    float: left;
    width: 175px;
    margin-left: -100%;
    position: relative;
    margin-top: 10px;
    padding-left: 5px;
    padding-top: 10px;
    border-right-style: solid;
    border-right-color: black;
    border-right-width: 1px;
}

#friend {
    float: left;
    background: #B5AAFF;
    border:1px solid;
    position: relative;
    top:5px;
    left:0px;
    margin-left:10px;
    width:175px;
    height:175px;
}

enter image description here

1 个答案:

答案 0 :(得分:2)

你没有关闭div,你的CSS也有错误:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="description" content="A short description." />
        <meta name="keywords" content="put, keywords, here" />
        <title>CraftLink</title>
        <link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
    </head>
    <body>
        <div id="wrapper">
            <div id="header">HEADER CONTENT</div><!-- #header-->
            <div id="nav">
                <a href="#">Nav item 1</a>
                <a href="#">Nav item 2</a>
                <a href="#">Nav item 3</a>
                <a href="#">Nav item 4</a>
            </div>
            <div id="middle">
                <div id="container">
                    <div class="sidebar" id="sideLeft">USER INFO GOES HERE.</div><!-- .sidebar#sideLeft -->
                    <div id="content"><!-- content -->
                        <div id='containerGraph'>
                            <div id='sngAnimals'></div>
                            <div id='graph'><img src='./lib/pChart2.1.1/examples/chartAnimalKillsPerDay.php' width='x' height='y' id='graphImg'/></div>
                            <div id='bottomCont'></div>
                        </div>
                    </div><!-- #content-->
                </div><!-- #container-->
            </div><!-- #middle-->
        </div><!-- #wrapper -->

        <!-- #footer -->
        <div id="footer">
            <h1>Footer Stuff</h1>
        </div>
    </body>
</html>

CSS:

* {
    margin: 0;
    padding: 0;
}
html {
    height: 100%;
}
body {
    font: 12px/18px Arial, Tahoma, Verdana, sans-serif;
    width: 100%;
    height: 100%;
    background-image:url('/mcimages/bg.png');
}
a {
    color: white;
    outline: none;
    text-decoration: underline;
}
a:hover {
    text-decoration: none;
}
p {
    margin: 0 0 18px
}
img {
    border: none;
}
input {
    vertical-align: middle;
}
#wrapper {
    width: 1000px;
    margin: 0 auto;
    min-height: 100%;
    height: auto !important;
    height: 100%;
    color: white;
}


/* Header
-----------------------------------------------------------------------------*/
#header {
    height: 100px;
    background: #999999;
    text-align: center;
    font-size: 200%;
}
#nav {
    height: 25px;
    background: #555555;
    text-align: center;
}

/* Middle
-----------------------------------------------------------------------------*/
#middle {
    width: 100%;
    padding: 0 0 100px;
    height: 1%;
    position: relative;

}
#middle:after {
    content: '.';
    display: block;
    clear: both;
    visibility: hidden;
    height: 0;
}
#container {
    width: 100%;
    float: left;
    overflow: hidden;
    margin-top: 10px;
    margin-bottom: 10px;

}
#content {
    padding: 10px 0 10px 195px;
    background: #666666;

}

#containerGraph {
    border-style:solid;
    border-width:5px;
    width: 75%;
    position:relative;
}

#graph {
    width: 249px;
    height: 210px;
    border-style:solid;
    border-width:5px;
    position: relative;
    float:left;
}

#sngAnimals {
    width:50%;
    height: 210px;
    border-style:solid;
    border-width:5px;
    position: relative;
    float:right;

}

#bottomCont{
    position: relative;
    clear:both;
}

/* Sidebar Left
-----------------------------------------------------------------------------*/

#sideLeft {
    float: left;
    width: 175px;
    position: relative;
    margin-top: 10px;
    padding-left: 5px;
    padding-top: 10px;
    border-right-style: solid;
    border-right-color: black;
    border-right-width: 1px;
}

#friend {
    float: left;
    background: #B5AAFF;
    border:1px solid;
    position: relative;
    top:5px;
    left:0px;
    margin-left:10px;
    width:175px;
    height:175px;
}

/* Footer
-----------------------------------------------------------------------------*/
#footer {
    width: 1000px;
    margin: -100px auto 0;
    height: 100px;
    background: #BFF08E;
}

/* Progress bar
----------------------------------------------------------------------------*/

.meter-wrap{
    position: relative;
}

.meter-wrap, .meter-value, .meter-text {
    /* The width and height of your image */
    width: 155px; height: 30px;
}

.meter-wrap, .meter-value {
    background: #3D352A url(/path/to/your-image.png) top left no-repeat;
}

.meter-text {
    position: absolute;
    top:0; left:0;

    padding-top: 5px;

    color: #fff;
    text-align: center;
    width: 100%;
}