填充浮动的左侧:全宽设计中的右侧元素
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情怎么样?为左右部分创建一个容器。提供右边距,为正确的容器腾出空间。你可以浮动它,但我绝对定位它,因为你讨厌浮动=)。
http://jsfiddle.net/Z62f2/
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/
我想尝试一下,
以下是我在您已有的 HTML 中标记它的方法。基本上我插入了另一个 div 来包含该部分和旁边。
还有CSS..
这段代码应该给你更多的视角,而且它有效,你可以在旁边放置“更多”内容,并且不会破坏布局。
祝你好运!
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.
And the CSS..
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!