创建适用于一列和两列布局的 CSS 规则
这就是我想做的:
示例 http://img689.imageshack .us/img689/5761/cssautowidth.th.jpg (大图。)
当
我希望 #content
在第一个示例中具有百分比值的原因是因为我在 #body
中有一个背景图像,它会产生外部发光的错觉。
编辑:我只是通过使用边距来消除使用宽度百分比的需要。
This is what I'm trying to do:
Example http://img689.imageshack.us/img689/5761/cssautowidth.th.jpg
(Larger image.)
When the <nav>
element is present in the design, I want it to look like the example below. Is it possible to do this while the #content
div has got a percentage value set? I'm just curious to see whether this is possible without using two different styles for the #content
(both with different width values.)
Just floating doesn't seem to do it.
The reason I want the #content
to have a percentage value in the first example is because I have a background image in #body
that creates the illusion of an outer glow.
Edit: I just removed the need for using the width percentage by using margins instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查此处的示例: http://css.maxdesign.com.au/floatutorial/tutorial0816 .htm
您应该做的是在
然后,如果您隐藏
这是示例代码:
现在,如果您从容器元素中删除了
class="double"
,您将看到内容已正确调整大小以占据给定空间的 90%。如果你想获得 100% - 只需在 style 中的 #content 之前添加 .double 即可。Check the example here: http://css.maxdesign.com.au/floatutorial/tutorial0816.htm
What you should do is to set
float:right
andwidth
on your<nav>
element, and leave#content
without any float or width, just set margin. This way content will try to occupy all given space and wont 'fall' into navigation.Then, if you hide
<nav>
element, content will automatically resize (but also you will need to remove padding from the right).This is example code:
Now, if you removed
class="double"
from container element you will see content is correctly resized to take 90% of given space. If you want to take 100% - just add .double before #content in style.