我在html中搞亂了,我希望這篇文章在該部分的中心是水平和垂直的。我在網上看過不同的論壇,沒有人在工作。這是代碼。 如何將一個容器在另一個容器內水平和垂直居中?
/* Style */
#section {
\t width: 70%;
\t height: 800px;
\t background: #555;
\t margin-left: auto;
\t margin-right: auto;
\t margin-top: 50px;
\t margin-bottom: 50px;
}
#nav {
\t height: 100px;
}
#article {
\t width: 90%;
\t height: 400px;
\t background-color: #fff;
}
#footer {
\t width: 100%;
\t height: 200px;
\t background-color: #fff;
}
/* Nav */
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 20px 50px 150px;
font-size: 13px;
text-align: center;
background: #E3CAA1;
}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
ul li:hover {
background: #555;
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
ul li ul li:hover { background: #666; }
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
HTML
<!DOCTYPE html>
<html>
\t <head>
\t \t <meta charset="UTF-8">
\t \t <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
\t \t <link rel="stylesheet" type="text/css" href="stylesheets/nav.css">
\t \t <title>Alec Grogan | Home</title>
\t </head>
\t <body>
\t \t <header id="header">
\t \t \t <h1>Alec Grogan</h1>
\t \t </header>
\t \t <nav id="nav">
\t \t \t <ul>
\t \t \t \t <li>Home</li>
\t \t \t \t <li>About</li>
\t \t \t \t <li>Resume</li>
\t \t \t \t <li>Portfolio
\t \t \t \t \t <ul>
\t \t \t \t \t \t <li>Web Design</li>
\t \t \t \t \t \t <li>Photoshop</li>
\t \t \t \t \t </ul>
\t \t \t \t </li>
\t \t \t \t <li>Blog</li>
\t \t \t \t <li>Contact</li>
\t \t \t </ul>
\t \t </nav>
\t \t <section id="section">
\t \t \t <article id="article">
\t \t \t </article>
\t \t </section>
\t \t <footer id="footer">
\t \t </footer>
\t </body>
</html>