嵌套DIV不服从自动

时间:2012-06-05 20:47:13

标签: css html height

见下图。请注意,左右边框未填充可用空间。这些是嵌套的div。我如何让它服从汽车?

CSS类MiddleLeftBorder和MiddleRightBorder未按预期工作。

下面的CSS代码:

html, body
{
    height: 100%;
    margin: 0 0 0 0;
    padding: 0 0 0 0;
}
body
{
    background-color: #000000;
    background-image: url('/CatwalkCloset/App_Themes/Default/Images/Background.jpg');
    background-repeat: repeat;
    color: #FFFFFF;
}
/* TEMPLATE */
container
{
    height: auto;
    margin: auto;
    width: 100%;
}
div.content
{
    clear: both;
    height: auto;
    margin: 0px auto;
    text-align: center;
    width: 1024px;
}
div.rows div.row
{
    clear: both;
    width: 1024px;
}
div.rows div.column
{
    float: left;
}
div.rows div.clear-row
{
    line-height: 0px;
    font-size: 0px;
    clear: both;
}
div.logo
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/Logo.jpg');
    height: 150px;
    width: 510px;    
}
div.logoSpace
{
    background-color: #000000;   
}
div.menu
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/MenuBackground.jpg');
    background-repeat: repeat;
    height: 40px;
    width: 1024px;
}
div.topLeftBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/TopLeftBorder.jpg'); 
    float: left;
    height: 40px;
    width: 40px;   
}
div.topMiddleBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/TopMiddleBorder.jpg');
    background-repeat: repeat;
    float: left;
    height: 40px;
    width: 944px;
}
div.topRightBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/TopRightBorder.jpg'); 
    float: left;
    height: 40px;
    width: 40px;   
}
div.middleLeftBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/MiddleLeftBorder.jpg');
    background-repeat: repeat;
    float: left;
    height: 100%;
    width: 40px;
}
div.middleContent
{
    float: left;
    height: 100%;
    width: 944px;    
}
div.middleRightBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/MiddleRightBorder.jpg');
    background-repeat: repeat;
    float: left;
    height: 100%;
    width: 40px;
}
div.bottomLeftBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/BottomLeftBorder.jpg'); 
    float: left;
    height: 40px;
    width: 40px;   
}
div.bottomMiddleBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/BottomMiddleBorder.jpg');
    background-repeat: repeat;
    float: left;
    height: 40px;
    width: 944px;
}
div.bottomRightBorder
{
    background: url('/CatwalkCloset/App_Themes/Default/Images/BottomRightBorder.jpg'); 
    float: left;
    height: 40px;
    width: 40px;   
}

下面的HTML代码使用上面的CSS代码:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="cphMasterHead" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
    <form id="fMaster" runat="server">
    <div id="container">
        <div class="content">
            <div class="rows">
                <div class="row">
                    <div class="logo"></div>
                    <div class="logoSpace"></div>   
                    <div class="clear-row">&nbsp;</div>
                </div>
                <div class="row">
                    <div class="menu"></div>    
                    <div class="clear-row">&nbsp;</div>
                </div>
                <div class="row">
                    <div class="topLeftBorder"></div>
                    <div class="topMiddleBorder"></div>
                    <div class="topRightBorder"></div>  
                    <div class="clear-row">&nbsp;</div>
                </div>
                <div class="row">
                    <div class="middleLeftBorder"></div>
                    <div class="middleContent"><asp:ContentPlaceHolder id="cphMasterBody" runat="server"></asp:ContentPlaceHolder></div>
                    <div class="middleRightBorder"></div>   
                    <div class="clear-row">&nbsp;</div>
                </div>
                <div class="row">
                    <div class="bottomLeftBorder"></div>
                    <div class="bottomMiddleBorder"></div>
                    <div class="bottomRightBorder"></div>   
                    <div class="clear-row">&nbsp;</div>
                </div>
             </div>
        </div>
    </div>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

为什么使用图像做可以用纯CSS(border-radius)完成的事情?我的意思是#content中的那个框架。但好吧..

首先确保图像在您编写的路径中(使用F12和Network选项卡查看是否没有任何错误),因为CSS类和HTML标记看起来是正确的。不是,只是正确

由于您使用.row.middleContent.middleLeftBorder.middleRightBorder的固定宽度,因此无需使用3张图片来构建背景 - 您可以将它们组合使用作为.row的一个背景。在[{1}}

div.clear-row时,也无需使用clear: both;

我认为这里有太多改进......


好的,关于圆角。您可以使用此代码(与您的代码松散相关)实现我认为您想要的东西:

.row

你应该在黑色背景上得到带圆角的白色矩形。