我需要使屏幕左側的導航條和文本div才能從導航欄旁邊開始。我只設法使文本div一直走到屏幕的右側。 到目前爲止,我有這樣的:如何讓2個div彼此相鄰?
HTML
<head>
<link rel = "stylesheet" type = "text/css" href = "styles.css">
<title>Homepage</title>
</head>
<body>
<div id = "header">
<h1>Homepage - origins of World Wide Web and the Internet</h1>
</div>
<div id = "wrapper">
<div id = "navbar">
<ul>
<li><a class = "active" href="index.html">HOMEPAGE</a></li>
<li><a href="news.asp">INTERNET PIONEERS</a></li>
<li><a href="contact.asp">HTTP</a></li>
<li><a href="about.asp">TERMINOLOGY</a></li>
<li><a href="about.asp">REFERENCES</a></li>
</ul>
</div>
<div id = "text">
<h2>World Wide Web</h2>
</div>
</div>
CSS:
#header {
width: 97%;
height: 70px;
background: black;
position: relative;
border: 5px solid white;
margin: 20px;
}
#header:after {
content: '';
position: absolute;
top: -15px;
left: -15px;
right: -15px;
bottom: -15px;
background: #600202;
z-index: -1;
}
#header h1 {
font-family: Arial;
color: white;
text-align: center;
}
#navbar {
padding-left: 8px;
margin:5px;
}
#navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 15%;
background-color: #f1f1f1;
position: fixed;
overflow: auto;
border: 5px solid black;
border-radius: 3%;
font-family: Arial;
font-weight: bold;
}
#navbar li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
#navbar li a:hover {
background-color: #555;
color: white;
}
#navbar li a.active {
background-color: #600202;
color: white;
}
#navbar li {
text-align: center;
border-bottom: 5px solid black;
}
#navbar li:last-child {
border-bottom: none;
}
#text {
border:1px solid black;
}
您不應該使用'position:absolute;'這裏,float或display可以更加高效。 –
但是那個位置:絕對的;是爲頭部div,不應該有任何與它下面的內容?或者我錯了 –
你是對的,我有一個太快的樣子,你也可以使用盒子陰影,並放棄這個絕對的僞造:)(我只是注意到我錯過了你的CSS的一部分,我的壞連接) –