header
元素位於容器div
內。我將header
設置爲fixed
。它導致2個問題:使固定標題的寬度與容器div相同大小
- 寬度
header
溢出了div
元素的寬度。它應該匹配div
。 - 其他元素
nav
和article
在我修復header
時不可見。
這裏是我的代碼片段:
<!DOCTYPE html>
<html>
<head>
<style>
div.container {
width: 100%;
border: 1px solid gray;
}
header{
position:fixed;
width:100%;
right:0px;
}
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
nav {
float: left;
max-width: 160px;
margin: 0;
padding: 1em;
}
nav ul {
list-style-type: none;
padding: 0;
}
\t \t \t
nav ul a {
text-decoration: none;
}
article {
margin-left: 170px;
border-left: 1px solid gray;
padding: 1em;
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>City Gallery</h1>
</header>
<nav>
<ul>
<li><a href="#">London</a></li>
<li><a href="#">Paris</a></li>
<li><a href="#">Tokyo</a></li>
</ul>
</nav>
<article>
<h1>London</h1>
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
</article>
<footer>Copyright © W3Schools.com</footer>
</div>
</body>
</html>
你不能有一個非固定高度的固定頭,所以你可以給頭部固定高度? ...否則你需要一個不同的解決方案,如果你希望標題保持不變,並且內容可見和可滾動......那麼該走哪條路? – LGSon
我想都;頭部被固定,並且內容(物品)如果其大內容可見並且可滾動。 – Mitali
你在說什麼?是否需要修改標題的高度 – Mitali