使用 css 将按钮放置在 div 内
我有一些 html 代码,所以:
<div class="ui-tabs-panel">
<div class="dataTables_wrapper">
<div>
<button>Add Whatever</button>
</div>
</div>
</div>
与定位有关的应用样式是:
ui-tabs-panel {
display: block;
}
dataTables_wrapper: {
clear: both,
position: relative;
}
my_button div: ?
my_button: ?
外部 div 是 jQuery 选项卡面板;中间的 div 是一个精简的 jQuery 数据表。我希望我的按钮右对齐,位于选项卡边框内。我尝试过一些事情。将这些样式应用到按钮本身:
1. float:right
右对齐,但位于选项卡边框之外。
2. position:absolute
也超出了选项卡边框。
3. right: -91%
当屏幕最大化时看起来很棒,但当我调整大小时开始切断按钮的右边缘。 (按钮具有恒定的宽度。)
4. margin-left: 91%
做同样的事情。
我尝试将 float: right
应用于容器 div,但仍然将其粘在选项卡面板之外。
我可以处理调整大小事件,并重新计算其中正确属性的百分比值,但这让我觉得绕着街区去隔壁。在 css 中执行此操作的正确方法是什么?
I have some html code, so:
<div class="ui-tabs-panel">
<div class="dataTables_wrapper">
<div>
<button>Add Whatever</button>
</div>
</div>
</div>
The applied styles that have to do with positioning are:
ui-tabs-panel {
display: block;
}
dataTables_wrapper: {
clear: both,
position: relative;
}
my_button div: ?
my_button: ?
The outside div is a jQuery tabs panel; the middle div is a stripped-down jQuery datatables table. I want my button to be right-aligned, and inside the tab border. I've tried a few things. Applying these styles to the button itself:
1. float:right
right-aligns, but outside the tab border.
2. position: absolute
goes outside the tab border as well.
3. right: -91%
looks great when the screen is maxed, but starts cutting off the right edge of the button as I resize smaller. (The button has a constant width.)
4. margin-left: 91%
does the same thing.
I tried applying a float: right
to the container div, and that still sticks it outside the tab panel.
I could handle the resize event, and recalculate the percentage value of the right attribute in it, but that strikes me as going around the block to get next door. What's the right way to do this in css?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要使用浮动,则对容器应用overflow:hidden:
如果要使用定位,则对容器应用position:relative:
If you want to use float, then apply overflow:hidden to container:
If you want to use positioning, then apply position:relative to container: