gpt4 book ai didi

html - 我怎样才能拉伸(stretch)我的导航栏高度?

转载 作者:行者123 更新时间:2023-11-28 13:53:09 25 4
gpt4 key购买 nike

我在拉伸(stretch)导航栏的高度时遇到问题。我已经为属性高度添加了值,但它使导航栏稍微移到容器外。我该如何解决这个问题?

*{
margin:0;
padding:0;
}

body {
background-image: url("/images/ilhas.jpg");
background-size: cover;
}


nav {
width: 100%;
background-color:rgb(3, 129, 14);
text-align: center;
position:relative;
padding:0 0 10% 0;
}

nav ul {
float: left;
text-align: center;
width:70%;
position:absolute;
bottom:0;
right:5%;
}

nav ul li { /*DROPDOWN*/
float: left;
list-style:none;
position: relative;
width:10%;
background-color:rgb(230, 179, 179);
}

nav ul li a{
display:block;
font-family: arial;
color: #222;
font-size:70%;
padding:22px 14px;
text-decoration: none;
margin-right: auto;
margin-left: auto;
}

nav ul li ul{
display:none;
position:block;
background-color:#fff;
border-radius:20px 20px;
}

nav ul li:hover ul {
display:block;
}

nav ul li ul li{
width:100%;
}

nav ul li ul li a{
padding:8px 4px;
}

nav ul li ul li a:hover {
background-color:#f3f3f3;
}

#home {
background-color:#00c3ff;
}

#ilhaSantaMaria {
background-color:#fffb00;
}

#ilhaSaoMiguel {
background-color:#33ff00;
}

#ilhaTerceira {
background-color:#ff00d4;
}

#ilhaGraciosa {
background-color:#ffffff;
}

#ilhaSaoJorge {
background-color:#f593c4;
}

#ilhaPico {
background-color:#5a5a5a;
}

#ilhaFaial {
background-color:#004458;
}

#ilhaFlores {
background-color:#00ff2a;
}

#ilhaCorvo {
background-color:#4e3300;
}
        <nav> 
<ul>
<li id="home"><a class="active" href="index.html">Home</a></li>
<li id="ilhaSantaMaria"><a href="ilhaSantaMaria.html">Santa Maria</a>
<ul>
<li><a href="ilhaSantaMaria.html">Digital art</a></li>
<li><a href="ilhaSantaMaria.html">Video production</a></li>
<li><a href="ilhaSantaMaria.html">Web development</a></li>
</ul>
</li>
<li id="ilhaSaoMiguel"><a href="ilhaSaoMiguel.html">São Miguel</a>
<ul>
<li><a href="ilhaSaoMiguel.html">Digital art</a></li>
<li><a href="ilhaSaoMiguel.html">Video production</a></li>
<li><a href="ilhaSaoMiguel.html">Web development</a></li>
</ul>
</li>
<li id="ilhaTerceira"><a href="ilhaTerceira.html">Terceira</a>
<ul>
<li><a href="ilhaTerceira.html">Digital art</a></li>
<li><a href="ilhaTerceira.html">Video production</a></li>
<li><a href="ilhaTerceira.html">Web development</a></li>
</ul>
</li>
<li id="ilhaGraciosa"><a href="ilhaGraciosa.html">Graciosa</a>
<ul>
<li><a href="ilhaGraciosa.html">Digital art</a></li>
<li><a href="ilhaGraciosa.html">Video production</a></li>
<li><a href="ilhaGraciosa.html">Web development</a></li>
</ul>
</li>
<li id="ilhaSaoJorge"><a href="ilhaSaoJorge.html">São Jorge</a>
<ul>
<li><a href="ilhaSaoJorge.html">Digital art</a></li>
<li><a href="ilhaSaoJorge.html">Video production</a></li>
<li><a href="ilhaSaoJorge.html">Web development</a></li>
</ul>
</li>
<li id="ilhaPico"><a href="ilhaPico.html">Pico</a>
<ul>
<li><a href="ilhaPico.html">Digital art</a></li>
<li><a href="ilhaPico.html">Video production</a></li>
<li><a href="ilhaPico.html">Web development</a></li>
</ul>
</li>
<li id="ilhaFaial"><a href="ilhaFaial.html">Faial</a>
<ul>
<li><a href="ilhaFaial.html">Digital art</a></li>
<li><a href="ilhaFaial.html">Video production</a></li>
<li><a href="ilhaFaial.html">Web development</a></li>
</ul>
</li>
<li id="ilhaFlores"><a href="ilhaFlores.html">Flores</a>
<ul>
<li><a href="ilhaFlores.html">Digital art</a></li>
<li><a href="ilhaFlores.html">Video production</a></li>
<li><a href="ilhaFlores.html">Web development</a></li>
</ul>
</li>
<li id="ilhaCorvo"><a href="ilhaCorvo.html">Corvo</a>
<ul>
<li><a href="ilhaCorvo.html">Digital art</a></li>
<li><a href="ilhaCorvo.html">Video production</a></li>
<li><a href="ilhaCorvo.html">Web development</a></li>
</ul>
</li>
</ul>
</nav>
Output of my code

已经使用 height 属性尝试拉伸(stretch),但它什么也没做。有人可以帮我解决这个问题吗?

最佳答案

它没有按照您想要的方式扩展,因为您的 child ul 是绝对定位的,将其从文档流中分离出来。您可以通过将 ul float 到右侧并使用它的边距将其放置在远离右侧的位置来纠正此行为,就像我在下面所做的那样。您可能想在此处进一步调整样式,但由于我不确切知道您要做什么,所以我坚持关于为什么高度不适合您的具体问题:

/*WILSON*/

* {
margin: 0;
padding: 0;
}

body {
background-image: url("/images/ilhas.jpg");
background-size: cover;
}

nav {
float: left;
width: 100%;
background-color: rgb(3, 129, 14);
text-align: center;
padding: 0 0 10% 0;
}

nav ul {
float: right;
margin-right: 5%;
text-align: center;
width: 70%;
}

nav ul li {
/*DROPDOWN*/
float: left;
list-style: none;
position: relative;
width: 10%;
background-color: rgb(230, 179, 179);
}

nav ul li a {
display: block;
font-family: arial;
color: #222;
font-size: 70%;
padding: 22px 14px;
text-decoration: none;
margin-right: auto;
margin-left: auto;
}

nav ul li ul {
display: none;
position: block;
background-color: #fff;
border-radius: 20px 20px;
}

nav ul li:hover ul {
display: block;
}

nav ul li ul li {
width: 100%;
}

nav ul li ul li a {
padding: 8px 4px;
}

nav ul li ul li a:hover {
background-color: #f3f3f3;
}

#home {
background-color: #00c3ff;
}

#ilhaSantaMaria {
background-color: #fffb00;
}

#ilhaSaoMiguel {
background-color: #33ff00;
}

#ilhaTerceira {
background-color: #ff00d4;
}

#ilhaGraciosa {
background-color: #ffffff;
}

#ilhaSaoJorge {
background-color: #f593c4;
}

#ilhaPico {
background-color: #5a5a5a;
}

#ilhaFaial {
background-color: #004458;
}

#ilhaFlores {
background-color: #00ff2a;
}

#ilhaCorvo {
background-color: #4e3300;
}
<!DOCTYPE html>
<html>

<head>
<meta name="author" content="João Lopes, Wilson Lima, Cristina Santos">
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" lang="pt">
<meta name="viewport" content="width=device-width" initial-scale="1.0">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="O que conhecer e fazer no arquipelago dos Açores">
<meta name="keywords" content="Açores, Gastronomia, Transportes...">
<!--TODO-->

<link rel="stylesheet" type="text/css" href="CSS/styles.css">
<link rel="shortcut icon" type="image/jpeg" href="icons/azoresIcon.jpeg" />
<!--
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
-->

<title>Esquecidos no Atlântico</title>

</head>

<body>
<script type="text/javascript" src="js/javascript.js"></script>





<nav>
<ul>
<li id="home"><a class="active" href="index.html">Home</a></li>
<li id="ilhaSantaMaria"><a href="ilhaSantaMaria.html">Santa Maria</a>
<ul>
<li><a href="ilhaSantaMaria.html">Digital art</a></li>
<li><a href="ilhaSantaMaria.html">Video production</a></li>
<li><a href="ilhaSantaMaria.html">Web development</a></li>
</ul>
</li>
<li id="ilhaSaoMiguel"><a href="ilhaSaoMiguel.html">São Miguel</a>
<ul>
<li><a href="ilhaSaoMiguel.html">Digital art</a></li>
<li><a href="ilhaSaoMiguel.html">Video production</a></li>
<li><a href="ilhaSaoMiguel.html">Web development</a></li>
</ul>
</li>
<li id="ilhaTerceira"><a href="ilhaTerceira.html">Terceira</a>
<ul>
<li><a href="ilhaTerceira.html">Digital art</a></li>
<li><a href="ilhaTerceira.html">Video production</a></li>
<li><a href="ilhaTerceira.html">Web development</a></li>
</ul>
</li>
<li id="ilhaGraciosa"><a href="ilhaGraciosa.html">Graciosa</a>
<ul>
<li><a href="ilhaGraciosa.html">Digital art</a></li>
<li><a href="ilhaGraciosa.html">Video production</a></li>
<li><a href="ilhaGraciosa.html">Web development</a></li>
</ul>
</li>
<li id="ilhaSaoJorge"><a href="ilhaSaoJorge.html">São Jorge</a>
<ul>
<li><a href="ilhaSaoJorge.html">Digital art</a></li>
<li><a href="ilhaSaoJorge.html">Video production</a></li>
<li><a href="ilhaSaoJorge.html">Web development</a></li>
</ul>
</li>
<li id="ilhaPico"><a href="ilhaPico.html">Pico</a>
<ul>
<li><a href="ilhaPico.html">Digital art</a></li>
<li><a href="ilhaPico.html">Video production</a></li>
<li><a href="ilhaPico.html">Web development</a></li>
</ul>
</li>
<li id="ilhaFaial"><a href="ilhaFaial.html">Faial</a>
<ul>
<li><a href="ilhaFaial.html">Digital art</a></li>
<li><a href="ilhaFaial.html">Video production</a></li>
<li><a href="ilhaFaial.html">Web development</a></li>
</ul>
</li>
<li id="ilhaFlores"><a href="ilhaFlores.html">Flores</a>
<ul>
<li><a href="ilhaFlores.html">Digital art</a></li>
<li><a href="ilhaFlores.html">Video production</a></li>
<li><a href="ilhaFlores.html">Web development</a></li>
</ul>
</li>
<li id="ilhaCorvo"><a href="ilhaCorvo.html">Corvo</a>
<ul>
<li><a href="ilhaCorvo.html">Digital art</a></li>
<li><a href="ilhaCorvo.html">Video production</a></li>
<li><a href="ilhaCorvo.html">Web development</a></li>
</ul>
</li>
</ul>
</nav>


</body>

</html>

关于html - 我怎样才能拉伸(stretch)我的导航栏高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59347379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com