CSS 以相反顺序水平放置 Div

发布于 2024-08-17 02:10:45 字数 487 浏览 2 评论 0原文

我有一个看起来像

<div id="content">
   <p> blah </p>
</div>

<div id="menu">
   <p> blah2 </p>
</div>

<div id="footer">
   <p> Copyright </p>
</div>

内容 div 位于菜单 div 之后的文档,但是是否可以像这样显示布局:

-------------------
| Menu  | Content |
|       |         |
|       |         |
-------------------
| Footer          |
-------------------

如何交换它们的顺序?我宁愿不使用绝对定位。

I have a document that looks like

<div id="content">
   <p> blah </p>
</div>

<div id="menu">
   <p> blah2 </p>
</div>

<div id="footer">
   <p> Copyright </p>
</div>

The content div is after the menu div, but is it possible to have the layout displayed like so:

-------------------
| Menu  | Content |
|       |         |
|       |         |
-------------------
| Footer          |
-------------------

How do you swap their order? And I'd rather not use absolute positioning.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

流星番茄 2024-08-24 02:10:45

float:right/float:left 解决方案的一个问题是您必须处理的元素之间的间隙,以及额外的容器 div。

另一种方法是:

#content, #menu{
  position: relative;
  float: left;
}
#menu    { right: 500px; }
#content { left: 100px; }
#footer  { clear: both; }

其中 500px 是内容的宽度,100px 是菜单的宽度。该解决方案需要相对定位和固定宽度的 div。

One problem with the float:right/float:left solutions is the gap between the elements you have to take care of, plus the extra container div.

Another way to do it is:

#content, #menu{
  position: relative;
  float: left;
}
#menu    { right: 500px; }
#content { left: 100px; }
#footer  { clear: both; }

Where 500px is the width of the content, and 100px is the width of the menu. That solution requires relative positioning and fixed width divs.

违心° 2024-08-24 02:10:45

尝试一些像这样的CSS:

#menu {
  float:left;
}
#content {
  float:right;
}
#footer {
  clear:both;
}

Try some css like this:

#menu {
  float:left;
}
#content {
  float:right;
}
#footer {
  clear:both;
}
风尘浪孓 2024-08-24 02:10:45

对它们中的每一个尝试 float:right;

try float:right; on each of them.

二货你真萌 2024-08-24 02:10:45

我会在菜单和内容上进行浮动,然后在将宽度设置为 100% 后在页脚上清除两者。

I would do the float right on menu and content then a clear both on the footer after setting the width to 100%.

情仇皆在手 2024-08-24 02:10:45

你能改变 HTML 代码吗?如果可能的话,我会这样做:

<div id="wrapper">
   <div id="menu">
     <p>Blah</p>
   </div>
   <div id="content">
     <p>Blah</p>
   </div>
</div>
<div id="footer">
   <p>Blah</p>
</div>

并将其样式设置为:

#wrapper { overflow: hidden; }
#menu { float: left; width: 40%; /* Any size u want */ }
#content { float: left; width: 60%; /* Any size u want */ }

我猜你不能,因此你会问,那么我会按照其他人的说法做:

#menu { float:right; }
#content { float: left; }
#footer { clear: both; }

Can you alter the HTML code, if that is possible I would do:

<div id="wrapper">
   <div id="menu">
     <p>Blah</p>
   </div>
   <div id="content">
     <p>Blah</p>
   </div>
</div>
<div id="footer">
   <p>Blah</p>
</div>

And style it with:

#wrapper { overflow: hidden; }
#menu { float: left; width: 40%; /* Any size u want */ }
#content { float: left; width: 60%; /* Any size u want */ }

I guess you cant and it is therefore you ask, then I would do as the others say:

#menu { float:right; }
#content { float: left; }
#footer { clear: both; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文