html - Css 无法应用于子 div

标签 html css

我正在创建一个简单的页面。当我在父 div 中创建子 div 时,它继承了背景,但是当我尝试将子 div 向右浮动时,它失去了继承的背景并变成白色。我可能会错过什么?我的 fiddle 是 here

我的CSS代码在这里

#fullwidth{
   width: 100%;
   /* background: url(../images/bg.jpg);*/
   background-color: black;
   background-repeat: repeat;
   position: relative;
   top: 0;
}

#fullwidth .container{
   width: 994px;
   position: relative;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
   background: transparent;
}

#fullwidth .test{
   float: right;
}

我的div在这里

<div id="fullwidth">
        <div class="container">
            <div class="test">
                <ul id='header_nav'>
                    <!--li><img src="images/home-icon.png" /></li-->
                    <li><a href="../design.php">Design</a>
                        <ul>
                            <li><a href="../designproducts.php">Products</a></li>
                        </ul>
                    </li>
                    <li><a href="../events.php">Events</a>
                        <ul>
                            <li><a href="../eventsservices.php">Services</a></li>
                            <li><a href="../eventsgallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../pr.php">Public Relations</a>
                    </li>
                    <li><a href="../outdoor.php">Media and Outdoor</a>
                        <ul>
                            <li><a href="../outdoorservices.php">Services</a></li>
                            <li><a href="../outdoorgallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../production.php">Production</a>
                        <ul>
                            <li><a href="../productionservices.php">Services</a></li>
                            <li><a href="../productiongallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../login.php">Login</a>
                        <ul>
                            <!--li>Register</li-->
                        </ul>
                    </li>
                </ul>

            </div>
        </div>
    </div>

最佳答案

添加这个

HTML

<html>
<head>

</head>
<body>
    <div id="fullwidth">
        <div class="container">
            <div class="test">
                <ul id='header_nav'>
                    <!--li><img src="images/home-icon.png" /></li-->
                    <li><a href="../design.php">Design</a>
                        <ul>
                            <li><a href="../designproducts.php">Products</a></li>
                        </ul>
                    </li>
                    <li><a href="../events.php">Events</a>
                        <ul>
                            <li><a href="../eventsservices.php">Services</a></li>
                            <li><a href="../eventsgallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../pr.php">Public Relations</a>
                    </li>
                    <li><a href="../outdoor.php">Media and Outdoor</a>
                        <ul>
                            <li><a href="../outdoorservices.php">Services</a></li>
                            <li><a href="../outdoorgallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../production.php">Production</a>
                        <ul>
                            <li><a href="../productionservices.php">Services</a></li>
                            <li><a href="../productiongallery.php">Gallery</a></li>
                        </ul>
                    </li>
                    <li><a href="../login.php">Login</a>
                        <ul>
                            <!--li>Register</li-->
                        </ul>
                    </li>
                </ul>

            </div>
        </div>

        <div class="cler"></div>
    </div>

</body>

CSS

.cler{
    clear:both;
}

在你的最后一个 div 子端

demo


------------ 第二个选项是

写这个css

#fullwidth:after{
content:'';
    clear:both;
    overflow:hidden;
    display:table;
}

Demo-2

关于html - Css 无法应用于子 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13835955/

相关文章:

html - 如何设置行与行之间的间隙

asp.net - 将 CSS 模板应用于包含内容/控件的 ASP 页面

javascript - 如何在html中将组件的高度设置为父组件的百分比?

javascript - 如何在从 firebase 检索的字符串中设置单词的样式?

javascript - 自动滑出导航加载?

javascript - bootstrap slider /旋转木马如何在 div 上最大化?

jQuery fadeIn 和 fadeOut - 交换 div

javascript - 检查 "-ms-expand"支持

css - 使用自动换行 : break-word on two consecutive long words

html - 如何使用 CSS 定位跟随 HTML 元素?