将表格转换为 CSS 层
我不太擅长 CSS、HTML 和标记,但是在阅读了很多 CSS 文章之后,我只是不知道如何将 div 元素放在正确的位置。
- 表格中的当前站点:http://daweb.nl/
- div 中的当前尝试:http://daweb.nl/daweb/
我希望将正确的菜单和内容放在正确的位置。如果您对我的 HTML 和 CSS 的当前状态有一般性意见,请随时提出。我经常使用 CSS、HTML,但从未使用 div 元素从头开始构建网站。
I am not very good with CSS, HTML and mark-up, but after having read many and many CSS articles, I just have no idea how to get the div-elements on the right place.
- Current site in tables: http://daweb.nl/
- Current attempt in div: http://daweb.nl/daweb/
I would like to have the right-menu and content in the right place. If you have general comments regarding the current state of my HTML and CSS, please feel free. I have worked with CSS, HTML much, but never built a site from scratch with div-elements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
http://jsfiddle.net/qJBpk/10/
检查预览 此处。
这是一个基本设置,您有一个包装 div,其中包含所有结构:标题、三列和页脚。
包装 div 的边距设置为自动,这将允许它在浏览器窗口中水平居中放置(及其所有内容)。
这三列的浮动属性设置为左侧,以便每一列都放置在另一列旁边。
页脚对两者都设置了明确的属性,这将允许将其放置在最高的浮动列之后,以避免布局崩溃。
Div 元素是块级元素。这意味着,除其他外,它们占用了所有可用的宽度空间,因此无需为 #header 和 #footer div 设置宽度。
编辑
为了避免跨浏览器不兼容和问题,最好重置 CSS(一组 CSS 规则,使所有元素在所有浏览器中显示尽可能相同),例如 YUI。将其放在任何其他 CSS 代码之前。
http://jsfiddle.net/qJBpk/10/
Check the preview here.
This is a basic setup, you have a wrapper div which contain all your structure: a header, three columns and a footer.
Wrapper div has margin set to auto, this will allow it to be horizontally center placed (along with all its content) in the browser window.
The three columns have the float property set to left, so that each one is placed next to the other.
The footer has a clear property set to both, this will allow it to be placed after the most tall floated column, to avoid a layout crash.
Div elements are block level elements. This means, among other things, they take up all the avaiable width space, so no need to set a width for the #header and #footer divs.
EDIT
To avoid cross browser incompatibilities and issues, it's better to have a CSS reset (a set of CSS rules which will make all elements shows as much as possible the same across all browsers), like the YUI. Place it first before any other CSS code.
这是开始学习 CSS 定位的好地方。
另外,在查看代码后,您可能希望将某些元素包装在包装器 div 中,以便可以使用一条 CSS 规则将所有内容放置在其中。
而不是:
尝试类似:
这样,如果您想移动菜单及其中的所有内容,您可以编写如下 CSS 规则:
This is a good place to start learning about css positioning.
Also, after looking at your code, you may want to wrap certain elements in a wrapper div so you can position everything inside it with one CSS rule.
Instead of:
Try something like:
That way if you want to move the menu and everything in it you can write a CSS rule like this:
只是另一个! ;-)
完整工作演示: http://so.devilmaycode.it/converting-tables-to-css-layers" rel="nofollow">http:// /so.devilmaycode.it/converting-tables-to-css-layers
希望这有帮助!
just another one! ;-)
full-working-demo: http://so.devilmaycode.it/converting-tables-to-css-layers
hope this help!
看起来像一个简单的 3 div 布局。您需要创建 3 个 div。一个用于左侧、中间和右侧内容。这三个 div 将被放置在一个包装 div 中。
因此,获取 left_menu、content 和 right_menu div,给它们一个宽度并将它们设置为 float: left;所以它们都会被放置在彼此旁边。将它们放在比所有三个都大的包装 div 中。你完成了!
Looks like a simple 3 div layout. You need to create 3 divs. One for the left, middle, and right-hand content. These three divs will be placed in a wrapper div.
So take your left_menu, content, and right_menu divs, give them a width and set them to float: left; so they will all be placed beside each other. Place them inside a wrapper div that is larger than all three. You're done!