使用jquery对齐按钮
Aligning button with jquery
我正在使用jquery来调整我的页面上的几个div的大小,使它们匹配。然后我想在使用float: bottom
的div底部对齐按钮。高度调整工作得很好,但我似乎无法弄清楚为什么.css()
功能不适合我。下面是一些示例代码,说明了这个问题:
<div class="box" style='border: solid'>
<p> there is text inside this box</p>
<button class="adjust">test Button</button>
</div>
<div class="box" style='border: solid'>
<p> there is text inside this box</p>
<p> there is text inside this box</p>
<p> there is text inside this box</p>
<button class="adjust">test Button</button>
</div>
JavaScript: $(document).ready(function() {
$maxh = 0;
$(".box").each(function(){
if($(this).height() > $maxh){
$maxh = $(this).height();
}
});
$(".box").each(function(){
$(this).height($maxh);
});
$(".adjust").each(function(){
$(this).css("float", "bottom");
});
});
JSFiddle演示
首先,CSS中没有float: bottom
属性。
在您的具体示例中,您应该这样做:
.box { position: relative; }
.box button {
position: absolute;
bottom: 0;
}
这将强制您的按钮与包含它们的div的底部对齐。
相关文章:
- jquery移动对齐按钮取决于内容大小
- css中的按钮对齐
- ExtJS--如何居中对齐两个工具栏按钮
- 为什么我需要垂直对齐画布来对齐按钮
- 将一组单选按钮垂直对齐,必要时将其分开
- 如何使用共享按钮将所有内容对齐到一行来解决问题
- 如何对齐画布旁边的文本和按钮(WebGL+JavaScript+CSS)
- 在质量中对齐按钮、文本和分段
- 将测试选项与相应的“单选”按钮对齐
- 扩展对齐按钮在容器中居中
- ext.js 消息框按钮对齐方式
- CSS:将三个按钮对齐成两行
- 离子后退按钮与标题右侧对齐
- JS,Rails,CSS - 将按钮与页面上其他内容的底部对齐
- 正确对齐Google Plus One和Facebook Like按钮
- CK编辑器文本对齐按钮
- 水平放置的提交按钮和错误消息的正确对齐
- Sencha Touch 2:带按钮的消息框:如何垂直对齐按钮
- 面板与单选按钮对齐
- 删除按钮对齐对齐CKeditor