【发布时间】:2016-04-15 05:06:51
【问题描述】:
我想在页面左侧有一个容器(带有一些文本),可以根据可用空间自行调整,右侧有 2 个侧边栏(我使用的是 Wordpress )。
(这 2 个侧边栏可以与 float 一起正常工作。)所以我在容器上尝试了 width:auto。
但它不会适应剩余的可用空间(它会占用所有页面宽度)。如果我将宽度设置为 70%,它适合索引页面上的空间,但如果我点击一篇文章,我只剩下 1 个侧边栏,所以文本和文本之间有一个空格侧边栏。
你知道如何解决这个问题吗?
#container { /* the text */
overflow:auto;
width:auto;
position:relative;
float:left;
}
#primary { /* first sidebar */
position:relative;
border:1px solid red;
float:right;
width:250px;
}
#second { /* second sidebar */
border:1px solid red;
background:white;
width:250px;
height:auto;
float:right;
margin-left:15px;
}
谢谢
编辑:
假设我使用它而不是 wordpress 侧边栏:我仍然无法使其工作,有人可以看看这个简单的代码吗?有 2 个盒子:绿色的一个和红色的一个......
<!DOCTYPE>
<html>
<head>
<meta charset="UTF-8" />
</head>
<body>
<div style="position:relative; width:700px; margin:0 auto;">
<div style="width:auto; border:1px solid green;">i would like to have a container (with some text) on the left of the page, that adapts itself with the space available, and 2 sidebars following on the right (i'm using Wordpress). (The 2 sidebars work fine with float. ) So i tried width:auto on the container.
But it does not adapt itself with the rest of the space available (it takes all the page width). If i set the width to 70%, it fits the space on the index page, but if i click on an article, i only have 1 sidebar left, so there is a blank space between the text and the sidebar.</div>
<div style="width:20%; float:right; border:1px solid red;">blablabla</div>
</div>
</body>
</html>
【问题讨论】:
-
一个非常简单的方法是编辑文章的模板,这样当只有一个侧边栏时,你就有了一个特殊的容器CSS。
-
@OptimusCrime:谢谢,你能说得更具体点吗?我应该在 html 中使用“style=”属性吗?它会覆盖css文件吗?
-
你的容器里面有两个侧边栏吗?
-
@Paul :文章有一个特殊的模板。例如,如果您在正文中添加一个类,例如
<body class="onesidebar">,您可以在 CSS 中编写类似body.onesidebar #container的内容 -
@Jack:嗨,杰克,没有外面的,我在上面编辑了我的帖子,也许你可以看看?非常感谢