英文:
How to vertically center navbar link in UL tag in CSS?
问题
Sure, here's the translated code part:
#nav_link {
background: orange;
display: flex;
justify-content: center;
outline: 2px solid white;
margin-top: 30px;
width: 12%;
height: 15rem;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
And the translated HTML part:
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
If you have any further questions or need additional translations, feel free to ask.
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
#nav_link {
background: orange;
display: flex;
justify-content: center;
outline: 2px solid white;
margin-top: 30px;
width: 12%;
height: 15rem;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
<!-- language: lang-html -->
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
<!-- end snippet -->
How to anchor tag inside a li in ul tag in CSS
i centered ul in div tag but how to vertically center li in ul tag.
答案1
得分: 1
ul
的内边距影响了设计。
包括 nav_link ul
#nav_link {
background: orange;
display: flex;
align-items: center;
justify-content: center;
outline: 2px solid white;
margin-top: 30px;
width: 20%;
height: 15rem;
}
#nav_link ul {
padding:0;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">主页</a></li>
<li><a href="">关于</a></li>
<li><a href="">联系我们</a></li>
<li><a href="">服务</a></li>
<li><a href="">定价</a></li>
</ul>
</div>
</nav>
英文:
The padding of ul is messing with the design
Include the nav_link ul
<!-- begin snippet: js hide: false console: true babel: null -->
<!-- language: lang-css -->
#nav_link {
background: orange;
display: flex;
align-items: center;
justify-content: center;
outline: 2px solid white;
margin-top: 30px;
width: 20%;
height: 15rem;
}
#nav_link ul {
padding:0;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
<!-- language: lang-html -->
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
<!-- end snippet -->
答案2
得分: 1
为了在<ul>标签内垂直居中导航链接,您可以使用CSS flexbox以及align-items: center属性。以下是您的CSS代码的更新版本:
<!DOCTYPE html>
<html>
<head>
<style>
#nav_link {
background: orange;
display: flex;
justify-content: center;
align-items: center; /* 添加的属性 */
outline: 2px solid white;
margin-top: 30px;
width: 37%;
height: 15rem;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
</body>
</html>
英文:
To vertically center the navbar links within the <ul> tag, you can use CSS flexbox along with the align-items: center property. Here's an updated version of your CSS code:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<!DOCTYPE html>
<html>
<head>
<style>
#nav_link {
background: orange;
display: flex;
justify-content: center;
align-items: center; /* Added property */
outline: 2px solid white;
margin-top: 30px;
width: 37%;
height: 15rem;
}
#nav_link li {
display: table;
text-align: center;
font-size: 20px;
}
</style>
</head>
<body>
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
</body>
</html>
<!-- end snippet -->
答案3
得分: -1
以下是您要翻译的内容:
#nav_link { background: orange; display: flex; justify-content: center; outline: 2px solid white; margin-top: 30px; width: 50%; height: 15rem; align-items: center; } #nav_link ul{ padding: 0px; text-align: center; } #nav_link li {
list-style: none; text-align: center; font-size: 20px; }
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
#nav_link { background: orange; display: flex; justify-content: center; outline: 2px solid white; margin-top: 30px; width: 50%; height: 15rem; align-items: center; } #nav_link ul{ padding: 0px; text-align: center; } #nav_link li {
list-style: none; text-align: center; font-size: 20px; }
<!-- language: lang-html -->
<nav>
<div id="nav_link">
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Contact Us</a></li>
<li><a href="">Services</a></li>
<li><a href="">Pricing</a></li>
</ul>
</div>
</nav>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论