创建适用于一列和两列布局的 CSS 规则

发布于 2024-08-11 08:45:19 字数 640 浏览 5 评论 0原文

这就是我想做的:

示例 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 技术交流群。

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

发布评论

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

评论(1

谁对谁错谁最难过 2024-08-18 08:45:19

检查此处的示例: http://css.maxdesign.com.au/floatutorial/tutorial0816 .htm

您应该做的是在

然后,如果您隐藏

这是示例代码:

<style type="text/css">
    #container { width:700px; margin:0 auto; border:1px solid #000; }
    #nav  { display:none; }
    .double #nav { width:10%; float:right; display:block; }
    #content { margin-right:10%; border-right:1px solid #000; }
</style>

<div id="container" class="double">
    <div id="nav">nav content</div>
    <div id="content">page content</div>
</div>

现在,如果您从容器元素中删除了 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 and width 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:

<style type="text/css">
    #container { width:700px; margin:0 auto; border:1px solid #000; }
    #nav  { display:none; }
    .double #nav { width:10%; float:right; display:block; }
    #content { margin-right:10%; border-right:1px solid #000; }
</style>

<div id="container" class="double">
    <div id="nav">nav content</div>
    <div id="content">page content</div>
</div>

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.

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