我最近开始进行一些网络编程/设计,但遇到了这个问题。
在 HTML5 中,你有这些很酷的标签,比如 section
和 header
和 footer
和一切。
- 我的第一个问题在这里提出:它们的行为(在 CSS 上下文中)完全像
div
吗?是吗?
转向更具体的问题,我必须创建一个带有简单 header -> content (section) -> footer
的网站结构(注意:我对 IE 兼容性不感兴趣)。我希望中央部分尽可能地(垂直)扩展,直到它遇到页脚。
“直到遇到页脚”部分可以通过一些 padding-bottom
来实现。但是“尽可能扩展”部分呢?请注意,在调整页面大小时,当页脚遇到该部分时,页脚应该停止。
我的意思是,我知道一些 div
我的生活会更轻松,但是否有可能按照今天的标准,我仍然必须将整个页面包装在 <div id="container">
中?标签?
于是第二个问题出现了……
- 我不能通过同时使用
html
来达到我想要的效果吗?和body
作为div#container
的容器通过制作html
成为html + body
部分和body
成为div#container
?
我希望我的问题很清楚,我知道我在写作时倾向于离题。
注意 为了清楚起见,我将在此处添加我的 HTML 结构和我的 CSS 中的一些亮点,但我不知道它们是否与问题相关。
HTML:
<html>
<head...>
<body>
<header id="page_header">
stuff in the header...
</header>
<section id="page_content">
stuff in the main section...
</section>
<footer id="page_footer">
an almost-sticky footer...
</footer>
</body>
</html>
CSS:
* {
margin: 0;
}
html {
background-image: url('../res/img/bg-light.png');
height: 100%;
position: relative;
}
body {
width: 900px;
height: 100%;
margin: 0 auto 20px auto;
padding: 0;
}
section#page_content {
min-height: 400px; // ? does this stop the footer from being dragged over the content when resizing?
width: 80%;
margin: 0 auto;
}
footer#page_footer {
position: absolute;
height: 20px;
width: 100%;
left: 0;
bottom: 0;
}
微记 为啥我的body
不是从页面的确切顶部开始,而是从顶部开始几个像素?只是问问。
最佳答案
是的,大多数标签,例如 <section>
, <header>
, 和 <footer>
行为与 <div>
非常相似的。它们在很大程度上取决于您来决定如何使用它们。但是,您不应忽视使用 <div>
的重要性。 s,尤其是造型。我见过一些 CSS 框架(我想到了 twitter Bootstrap 和 Blueprint),它们为您提供 <div class="container">
造型。不过为了便于阅读,<section>
, <footer>
, <header>
, 还有 <article>
可能非常有益。
一定要在可能和兼容的情况下使用 HTML5,但我相信您总能找到一种有用且有益的方式来使用 <div>
现在就在您的网络代码中。
这只是我的看法。
我找到了 this link当我搜索时。它可能比我能更好地阐明这个问题。它指出了几个不同的地方可以使用 <div>
超过较新的 HTML5 标签。
您可以使用<html>
或 <body>
标签代替 div 容器。它肯定没有什么错误,它甚至可以使您的代码稍微更干净一些。不过,我个人总是使用某种容器。我找到了 this question我相信可以很清楚地回答这个问题。
另外,正文应该填满屏幕。如果不是,请检查您的 CSS。
关于html - 讨厌容器 div 并尝试使用 HTML5 方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15559962/