CSS 布局 : Div's within divs etc

标签 css layout html

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

我想添加到内容部分的是一个包装盒,它包含左侧的图表和右侧的一堆小信息框,并且可能在这两个框下方有一个 100% 宽度的信息区域内容框。

但是一旦我将其添加进去,它就会将我的用户信息 div 推到内容下方。 =/所以我想问的是如何在我的内容部分中创建不会影响我的侧边栏之类的 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

最佳答案

您没有关闭 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%;
}

关于CSS 布局 : Div's within divs etc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687038/

相关文章:

html - 3 div middle centered sides zoomable all in one vertically centered div

javascript - 网络套件 3D CSS。像第一人称射击游戏一样旋转相机

html - 在页脚中使用 float <li> 元素

html - 在通过 PHP 添加内容时移动 div

MVC/Backbone.js 应用程序的 JavaScript 布局管理?

java - 如何在 Android 中设置来自不同类的类的背景/布局

html - 我如何使用 div 而不是使用 table、tr 和 td 来实现这种确切的行为?

Bootstrap 中的 Javascript 元素不起作用

css - border-image 在 Chrome 和 FireFox 之间呈现不同

java - Android 结合两个 LayoutParams