最近,我正在学习如何为Upskills开发网站。到目前为止,我试图通过开始建立我想要的网站来增强我对HTML和CSS的了解。令我沮丧的一个障碍是设计适合标头部门的链路按钮被未对准。除此之外,每个链接按钮之间都有很小的空间,这不是我想要的。
这是你们要理解的代码:
html
<!DOCTYPE HTML>
<html>
<head>
<title>AntsHUD</title>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="ndt.ttf"/>
</head>
<body>
<div id="header">
<h1 class="header-logo">AntsHUD</h1>
<a class="header-button" href="index.html">Home</a>
<a class="header-button" href="index.html">Downloads</a>
<a class="header-button" href="index.html">FAQ</a>
</div>
</body>
</html>
CSS
* {
margin: 0px;
font-family: arial;
}
#header {
width: 100%;
height: 40px;
line-height: 40px;
background-color: rgba(0,0,0,0.8);
border-bottom: 4px solid rgb(0,191,255);
}
.header-logo {
display: inline-block;
width: 150px;
height: 40px;
padding: 0px 14px;
color: white;
text-shadow: 3px 3px rgba(0,0,0,0.8);
}
#header>.header-button:link, #header>.header-button:visited {
display: inline-block;
vertical-align: middle;
height: 40px;
padding: 0px 16px;
color: white;
text-decoration: none;
}
#header>.header-button:hover, #header>.header-button:active {
display: inline-block;
vertical-align: middle;
height: 40px;
padding: 0px 16px;
background-color: rgb(0,191,255);
color: white;
text-decoration: none;
}
jsfiddle
我很感谢您的帮助,甚至可以解释为什么会发生这种情况。
首先,我建议您寻找概念" flexbox Design"。我选择解决您的问题的方式如下:
* {
margin: 0px;
font-family: arial;
}
#header {
width: 100%;
background-color: rgba(0,0,0,0.8);
border-bottom: 4px solid rgb(0,191,255);
display: flex;
justify-content: flex-start;
}
.header-logo {
width: 150px;
height: 40px;
padding: 0px 14px;
color: white;
text-shadow: 3px 3px rgba(0,0,0,0.8);
}
a.header-button {
padding: 10px;
margin: auto 10px;
color: #fff;
text-decoration: none;
}
#header>.header-button:visited,
#header>.header-button:hover,
#header>.header-button:active {
background-color: rgb(0,191,255);
color: white;
text-decoration: none;
}
<!DOCTYPE HTML>
<html>
<head>
<title>AntsHUD</title>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="ndt.ttf"/>
</head>
<body>
<div id="header">
<h1 class="header-logo">AntsHUD</h1>
<a class="header-button" href="index.html">Home</a>
<a class="header-button" href="index.html">Downloads</a>
<a class="header-button" href="index.html">FAQ</a>
</div>
</body>
</html>
希望它有帮助。