html - 垂直居中 CSS/HTML 文本

标签 html css

我在使用 CSS 制作网页时遇到了问题。我的菜单栏没有将链接在栏中垂直居中。它应该很简单,但我需要帮助。抱歉拖了这么久,我只是不想遗漏任何东西。

HTML:

<html>
<head>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<title>noobyDev</title>
<style>
body {
    background-color: CCFFFF; 
    text-align: center; 
}
div.background
{
    width: 90%;
    height: 200px;
    background color: #00FF66;
    border: 2px solid black;
    margin: 0 auto;
    text-align: left;  
}
div.background h3
{
    margin: 0px 40px;
}
div.logo
{
    width: 350px;
    height: 75px;
    background: url(logo.png);
    margin: 30px 40px;
}
div.nav
{
    background-color: #00CC66;
    border: 2px solid black;
    width: 90%;
    margin: 0 auto;
    text-align: left; 
    height: 30px;
    border-top: 0px solid black;
}
.menu
{
    margin: 5px 10px;
    background: #00CC66;
    color: black;
    -webkit-transition: color;
}
.menu:hover
{
    color: red;
}
div.center
{
    width: 90%;
    height: 700px;
    background color: white;
    border: 2px solid black;
    border-top: 0px solid black;
    margin: 0 auto;
    text-align: left;   
}
div.column1 h1
{
    margin: 30px 40px;
}
div.column1 p
{
    margin: 30px 40px;
}
div.column1
{
    width: 70%;
    height: 100%;
    float: left;
    display: block;
    border-right: 2px solid black;
}
div.column2
{
    width: 30%
    height: 100%;
    float: left;
    display: block;
    text-align: left;
}
div.column2 a
{
    margin: 30px 40px;
    display: block;
    text-decoration: none;
    font-size: 30px;
    font-color: black;
}
div.legal
{
    width:90%;
    height: 50px;
    background color: white;
    border: 2px solid black;
    border-top: 0px solid black;
    margin: 0 auto;
    text-align: center;
}
</style>
</head>
<body>
<div class="background">
<div class="logo">
</div>
<h3>Have you failed today?</h3>
</div>
<div class="nav">
<a style=text-decoration="none" href="index.html" class="menu">Home</a>
<a style=text-decoration="none" href="html.html" class="menu">HTML</a>
<a style=text-decoration="none" href="javascript.html" class="menu">Javascript</a>
<a style=text-decoration="none" href="css.html" class="menu">CSS</a>
<a style=text-decoration="none" href="java.html" class="menu">Java</a>
<a style=text-decoration="none" href="news.html" class="menu">News</a>
<a style=text-decoration="none" href="games.html" class="menu">Games</a>
<a style=text-decoration="none" href="other.html" class="menu">Other</a> 
</font>
</div>
<div class="center">
<div class="column1">
<h1>Home</h1>
<br>
<p>Welcome to noobyDev.com! This is my site where I document all of my fails and successes worth sharing. Feel free to use them unless otherwise instructed to do so. Check back often and admire my awesomeness!</p>
</div>
<div class="column2">
<a href="news.html#viral_video">Video?</a>
</div>
</div>
<div class="legal">
<p>This site is heavily protected with a gargantuan army of mutant cotton balls; I would recommend not stirring trouble up. Just so you know, this site looks the best in Internet Explorer.</p>
</div>
</body>
</html>

最佳答案

只需将 line-height 添加到 div.nav 即可:

div.nav
{
    background-color: #00CC66;
    border: 2px solid black;
    width: 90%;
    margin: 0 auto;
    text-align: left; 
    height: 30px;
    line-height: 30px;
}

这是要测试的 JS Bin:http://jsbin.com/oliwit/1/

关于html - 垂直居中 CSS/HTML 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16680867/

相关文章:

javascript - 如何根据单个类属性值获取页面上的多个跨度项内容

javascript - scrollTop 不适用于 -webkit-overflow-scrolling : touch

javascript - 使用 Webkit/jQuery 将外部页面加载到当前页面的最佳方式

javascript - 仅使用 Jquery 跳转到页面的各个部分

javascript - 我如何获得文本区域的高度

html - 在没有背景附件的情况下跨 body 扩展背景渐变 : fixed

javascript - 如何获得两个日期(以表格形式)之间的差异(以天为单位)

javascript - MDBootstrap 步进器

html - 设置相邻两个图像之间的边距或填充

html - 使用 R 抓取亚马逊评论