我正在尝试为网站形成标题。有一个div,在这个div中有一个标志和链接。
我无法弄清楚如何在此div中垂直和水平居中徽标/链接。我怀疑这与链接不好有关。
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="all.js"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<img id="Logo" src="images/.png" alt="">
<div id="nav">
<a href="index.html">Home</a>
<a href="#.html">text</a>
<a href="#.html">text</a>
<a href="#.html">text</a>
</div>
</div>
</div>
<footer>
</footer>
</body>
</html>
CSS:
html, body{
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
}
body {
background-color: #383838;
background-image: url("images/bkg.png");
}
#wrapper {
min-height: 100%;
height: auto !important;
margin: 0px auto -25px;
}
footer {
height: 25px;
text-align: center;
margin: 0px auto;
}
a:link, a:visited {
text-decoration: none;
color: white;
}
#header {
width: 80%;
margin: 0 auto;
padding-top: 10px;
text-align: center;
position: relative;
}
#Logo {
width: 230px;
position: relative;
display: inline-block;
margin: 0 auto;
color: white;
}
#nav {
width: 450px;
position: relative;
display: inline-block;
margin: 0 auto;
}
#nav a:link {
font-size: 26px;
padding-left: 10px;
width: 10%;
min-width: 50px;
}
答案 0 :(得分:0)
我用你的代码做了一个小改动(仅针对css),**白色边框用于澄清元素位置(你可以删除它们)**,现在垂直对齐。
#Logo {
border: 1px solid #fff;
top: 10px;
left: 0;
height: 50px;
width: 90px;
position: absolute;
color: white;
}
#nav {
margin-top: 10px;
border: 1px solid #fff;
width: 450px;
}
水平对齐另一个小编辑:
#Logo {
border: 1px solid #fff;
top: 10px;
left: 50%; /* Notice the 50% */
margin-left: -45px; /* Should always be half the logo width. */
height: 50px;
width: 90px;
position: absolute;
color: white;
}
#nav {
margin-top: 10px;
border: 1px solid #fff;
width: 450px;
}