html - html中根据li标签高度调整div高度的问题

标签 html css

我正在尝试为我的导航菜单设置导航 div 的高度。但我不明白为什么它没有根据 li 标签高度进行调整。

HTML:

<!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>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Journeycook</title>
        <link href="style.css" type="text/css" rel="stylesheet" />
    </head>
    <div class="wrapper">
        <div class="header">
            <div class="header-top">
                <a href="#" class="logo">
                    <img src="logo.png" />
                </a>
                <div class="header-right">
                    <div class="call">
                        <img src="call.png" />
                        1-877-708-1505
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="navigation">
                <ul>
                    <li>
                        <a href="#" class="act">Home</a>
                    </li>
                    <li>
                        <a href="#">Flights</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <body></body>
</html>

CSS:

body {
    margin: 0px;
    padding: 0px;
    font-family: Arial, Helvetica, sans-serif;
}
* {
    margin: 0;
    padding: 0;
}
ul, li {
    list-style: none;
    margin: 0;
    padding: 0;
}
h1, h2, h3, h4, h5, h6 {
    font-weight: normal;
    font-family: Arial, Helvetica, sans-serif;
}
img {
    max-width: 100%;
}
a img {
    outline: 0;
    border: 0;
    max-width: 100%;
}
.clearfix {
    clear: both;
}
a img {
    max-width: 100%;
}
ul, li {
    list-style: none outside none;
    margin: 0;
    padding: 0;
}
.wrapper {
    position: relative;
    width: 100%;
}
.wrapper .header {
    margin: 0 auto;
    width: 1024px;
}
.header-top {
    margin: 3px 0;
}
.header-top a.logo {
    display: block;
    float: left;
    height: 71px;
    width: 215px;
}
.header-right {
    float: right;
}
.call {
    color: #ffc620;
    font-size: 39px;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: right;
}
.header-right .call img {
    vertical-align: top;
    width: 48px;
}
.navigation {
    background: #04498E;
    border: 1px solid #002E73;
    border-radius: 6px;
}
.navigation ul {
}
.navigation ul li {
    border-right: 1px solid #1C61A6;
    float: left;
}
.navigation ul li a {
    color: #FFFFFF;
    display: block;
    padding: 10px 20px;
    text-decoration: none;
}
.navigation ul li a:hover {
    background: #ff8c04;
}
.navigation ul li .act {
    background: #ff8c04;
}

请专家告诉我哪里错了

谢谢

最佳答案

你的导航 DIV 没有调整到你的 ul 的原因是你放在它上面的 float ,在 ul 标签 float 之后使用 clear:both 这样你的导航 div 就知道自己调整

你不需要在你的导航上声明高度,如果你这样做,它将是固定的高度

关于html - html中根据li标签高度调整div高度的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581507/

相关文章:

javascript - 使用 z-index 和 jquery 显示内联 block

html - 网格问题

html - 每个按钮顶部带有标签的按钮组

javascript - localStorage onload 显示我选择的 div?

python - 在python中从html中获取2个部分

javascript - WordPress 插件添加构造的样式表,在类中不显示任何内容

html - 具有固定背景附件的非矩形 block

html - 2 Div 向右浮动 - 顺序不正确

html - 如何使用 html/css 使表格只有一行高?

javascript - 将 html 移动到 php include 后事情发生了变化