HTML+CSS:如何移动不关闭的div来创建右列?
我有一个我认为很简单的问题,但花了我很多时间来解决它。如果有一个简单的解决方案(并且我不太了解CSS),请指出我,我会立即关闭这个问题。
我的问题如下。
我有 6 个 div 一个在另一个之上,类似于:
<div id="header">header content</div>
<div id="sidebar1">sidebar1 content</div>
<div id="maincontent">maincontent content</div>
<div id="maincontent2">maincontent2 content</div>
<div id="sidebar2">sidebar2 content</div>
<div id="footer">footer content</div>
我想要的是类似于:
-----------------------------------------------------------
| header content |
-----------------------------------------------------------
-------------------------------------- -------------------
| maincontent content | | sidebar1 content|
| | -------------------
| | -------------------
| | | sidebar2 content|
| | -------------------
--------------------------------------
--------------------------------------
| maincontent2content |
| |
| |
| |
| |
--------------------------------------
-----------------------------------------------------------
| footer content |
-----------------------------------------------------------
换句话说,有没有办法创建一个右列,即使这些 div 不是一个接一个仅使用 CSS 并且不移动代码中的div?
我尝试对 sidebar1 使用以下 css
position:absolute;
top:3em;
right:0;
,对 sidebar2 使用以下 css,
position:absolute;
top:9.5em;
right:0;
但我的印象是这不是正确的方法。
一个简单的方法可能是将 top
属性大小定义为 Heather 高度的函数,但我找不到任何仅使用 CSS 来实现的方法。
谢谢!
I have a problem that I thought was pretty simple but that is taking me a lot of time to solve it. If there is a simple solution (and I don't know CSS enough), please point me there and I'll close this question immediately.
My problem is the following.
I have 6 divs one on top of another, something like:
<div id="header">header content</div>
<div id="sidebar1">sidebar1 content</div>
<div id="maincontent">maincontent content</div>
<div id="maincontent2">maincontent2 content</div>
<div id="sidebar2">sidebar2 content</div>
<div id="footer">footer content</div>
What I want to have is something like:
-----------------------------------------------------------
| header content |
-----------------------------------------------------------
-------------------------------------- -------------------
| maincontent content | | sidebar1 content|
| | -------------------
| | -------------------
| | | sidebar2 content|
| | -------------------
--------------------------------------
--------------------------------------
| maincontent2content |
| |
| |
| |
| |
--------------------------------------
-----------------------------------------------------------
| footer content |
-----------------------------------------------------------
In other words, is there a way to create a right column even if the divs are not one after another using only CSS and without moving the divs in the code?
I tried to use for sidebar1 the following css
position:absolute;
top:3em;
right:0;
and for sidebar2 the following css
position:absolute;
top:9.5em;
right:0;
but I have the impression that this is not the right way to do it.
A simple way could be to define the top
attribute size as a function of the height of heather, but I couldn't find any way to do it only with CSS.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...作为您问题的直接答案,您可以使用浮点数和%宽度的组合来完成此任务。您还可以使用固定宽度,但您必须确定这些尺寸。这是一个简单的实现:
演示
CSS
HTML
Well... as a direct answer to your question, you can use a combination of floats and % widths to accomplish this. You can also use fixed widths, but you'll have to determine what those sizes are. Here's a simple implementation:
Demo
CSS
HTML