填充浮动的左侧:全宽设计中的右侧元素

发布于 2024-12-31 23:34:31 字数 1583 浏览 0 评论 0原文

我正在使用 HTML5/CSS3 进行新设计,自从我上次使用 html 进行工作(而不是编写内容而不是布局)以来已经有一段时间了。

我想要实现的是“全宽”或更确切地说“80% 宽度”设计,以便它适合浏览器尺寸小至 800px。 (最小宽度)。

内容的一部分将包含放置在右侧的导航块(固定大小,例如 300px),我通过使用浮动实现了这一点,尽管由于“clearfix”问题我已经学会讨厌浮动,但由于缺乏更好的解决方案。

在它的左侧,我希望内容占据右侧浮动元素的空间。

但是,如果该内容增长超出宽度,则会将右侧浮动元素向下推。

因此,类似于:

   -----------------------------------------------------------
          |                 Header                    |
          |                <header>                   |
          |-------------------------------------------|
   <-10%->|         <- Fill ->            |<- 300px ->|<-10%->
          |                               |           |
          |         <section>             |  <aside>  |
   -----------------------------------------------------------

Section (id=articles) 设置为:

margin: 0 0 0 30px;
display: inline-block;
float: left;

Aside (id=sidebar) 设置为:

margin: 0 30px 10px 30px;
width: 290px;   

border:1px solid #6B6B6B;

border-radius: 6px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;

box-shadow: 0px 0px 2px 1px #6B6B6B inset;

display: inline-block;
float: right;

Ways of修复它:

  • 显示:表格和表格单元格,有效,但它添加了我想避免的额外标签,也不确定是否在任何地方都有效?
  • Flexbox?好吧,我是这么想的,但有问题,但无论如何它都没有得到广泛支持。
  • 让所有的宽度都固定。
  • 让所有的都有动态宽度。 (哦天哪)
  • 表格,但我们知道讨论一切都很顺利。

现在我将正确处理该列表中的第一个,因为这是目前唯一能让我实现目标的方法,但我想看看是否有更干净的方法。

I am working on a new design in HTML5/CSS3 and it has been a while since I last worked with html more than for writing content, not layout.

The thing I am trying to achieve is a "full-width" or rather "80% width" design so that it fits the browser size down to 800px. (min-width).

A part of the content will contain a navigation block placed to the right (fixed size, say 300px), I have achieved this by using float although I have learned to hate float because of the "clearfix" issue, bur for the lack of better.

To the left of it I wanted the content to take up space to the right floating element.

However if that content grows beyond the width then it pushes the right floated element down.

So something like:

   -----------------------------------------------------------
          |                 Header                    |
          |                <header>                   |
          |-------------------------------------------|
   <-10%->|         <- Fill ->            |<- 300px ->|<-10%->
          |                               |           |
          |         <section>             |  <aside>  |
   -----------------------------------------------------------

Section (id=articles) is set to:

margin: 0 0 0 30px;
display: inline-block;
float: left;

Aside (id=sidebar) is set to:

margin: 0 30px 10px 30px;
width: 290px;   

border:1px solid #6B6B6B;

border-radius: 6px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;

box-shadow: 0px 0px 2px 1px #6B6B6B inset;

display: inline-block;
float: right;

Ways of fixing it:

  • display: table and table-cell, works but it adds extra tags I would like to avoid, also not sure that works everywhere?
  • flexbox? well so I thought but having issues with it, but it is not widely supported anyways.
  • Let all have fixed width.
  • Let all have dynamic width. (ohh boy)
  • Tables, but we know that discussion all to well.

Now ill properly work on with the first one on that list as that is the only thing that currently let me achieve the goal, but I would like to see if there wasn't a more clean way.

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

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

发布评论

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

评论(2

葵雨 2025-01-07 23:34:31

像这样的事情怎么样?为左右部分创建一个容器。提供右边距,为正确的容器腾出空间。你可以浮动它,但我绝对定位它,因为你讨厌浮动=)。

http://jsfiddle.net/Z62f2/

div { border: 1px solid gray; width: }
#container { width: 80%; min-width: 600px; margin: 0 auto;  }
#header { height: 100px; }
#content { position: relative; }
#left { margin-right: 300px; height: 1000px; }
#right { width: 300px; height: 500px; position: absolute; top: 0px; right: 0px; }

<div id="container">
    <div id="header">Header</div>
    <div id="content">
        <div id="left">Left</div>
        <div id="right">Right</div>
    </div>
</div>

How about something like this? Create a container for the left and right pieces. Provide a right margin to make room for the right container. You could float it, but I absolutely positioned it because you hate floats =).

http://jsfiddle.net/Z62f2/

div { border: 1px solid gray; width: }
#container { width: 80%; min-width: 600px; margin: 0 auto;  }
#header { height: 100px; }
#content { position: relative; }
#left { margin-right: 300px; height: 1000px; }
#right { width: 300px; height: 500px; position: absolute; top: 0px; right: 0px; }

<div id="container">
    <div id="header">Header</div>
    <div id="content">
        <div id="left">Left</div>
        <div id="right">Right</div>
    </div>
</div>
江城子 2025-01-07 23:34:31

我想尝试一下,

以下是我在您已有的 HTML 中标记它的方法。基本上我插入了另一个 div 来包含该部分和旁边。

<div id="contentContain">
    <div id="section"></div>
    <div id="aside"></div>
</div>

还有CSS..

#contentContain {width: 80%; }
#section {float:left; width: 60%;}
#aside {float:left; width: 40%; }

这段代码应该给你更多的视角,而且它有效,你可以在旁边放置“更多”内容,并且不会破坏布局。

祝你好运!

I'd like to take a stab at this,

Here's how I would mark it up within the HTML you already have. Basically I inserted another div to contain the section and the aside.

<div id="contentContain">
    <div id="section"></div>
    <div id="aside"></div>
</div>

And the CSS..

#contentContain {width: 80%; }
#section {float:left; width: 60%;}
#aside {float:left; width: 40%; }

This code should give you some more perspective, and It works, you can have "more" content in aside and it won't break the layout.

Best of luck!

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