将 div 拉伸到全宽(如果有空间)

Jan*_*nik 3 html css width css-float

我目前正在研究 tumblr 主题,但卡在页面导航上。“上一个”和“下一个”按钮的 html 或仅呈现(如果可用)。所以第一页上没有下一个按钮,最后一页上没有上一个按钮。这就是我希望相应的单个按钮拉伸到 100% 宽度的地方。我可以在 javascript 中做到这一点,但它根本不是一个选项,因为模板也可以在没有 javascript 的情况下工作。

html 看起来像这样:

<div id="navigation">
<a href="#" id="prev" style="width:476px; float:left;" class="button_normal"><p>Prev</p></a>
<a href="#" id="next" style="width:476px; float:right;"class="button_normal"><p>Next</p></a>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.button_normal {
text-align: center;
opacity: 0.55;
height: 30px;
line-height: 30px;
background: white;
font-size: 13px;
font-weight: 100;
color: #646464;
border: 1px solid #646464;
text-decoration: none;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin-bottom: 10px;
}

#navigation{
clear: both;
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

父 div 的宽度是 960px,所以两个按钮之间应该有 8px 的边距。我尝试用 min-width 和 width: 100% auto 修复它;但无法真正弄清楚如何制作它。

提前致谢。

Joe*_*oel 5

您可以使用表格显示样式。

/* add these properties to your stylesheet */
#navigation { display:table; }
.button_normal { display:table-cell; }

// remove the inline styles from your anchors
<div id="navigation">
    <a href="#" id="prev" class="button_normal"><p>Prev</p></a>
    <a href="#" id="next" class="button_normal"><p>Next</p></a>
</div>
Run Code Online (Sandbox Code Playgroud)

示例: http: //jsbin.com/unuwuh/2


t0n*_*yh0 5

您可以执行以下操作:

  1. 将 a 添加position:relative到您的父容器
  2. 创建一个名为“全宽”的新类,并在其中包含

    position: absolute;
    left:0px;
    right:0px;
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将类添加full-width到相应的按钮