我的页面中心有一张桌子
是否可以将示例中的按钮放置在表格的左侧?
这张技术精湛的绘图应该可以为您提供更好的图片:
| |
| $$center |
| |
$$ 是我想要放置在中心之外的按钮。
我的页面中心有一张桌子
是否可以将示例中的按钮放置在表格的左侧?
这张技术精湛的绘图应该可以为您提供更好的图片:
| |
| $$center |
| |
$$ 是我想要放置在中心之外的按钮。
根据您的 jsfiddle 尝试这种方法:
HTML
<span>Center body text<button>Click</button></span>
CSS
span {
display: block;
width: 200px;
margin: 0 auto;
position: relative;
}
button {
position: absolute;
right: 100%;
}
按钮是绝对放置的,从右边缘到 span 元素宽度的 100%。
.center
{
width:250px;
margin:0px auto 0px auto;
}
.center input[type="button"], div
{
float:left;
}
<div class="center">
<input type="button" name="submit" value="$$" />
<div> center text </div>
</div>
你可以用jquery解决这个问题。
在页面加载时,您可以检查表格的开始位置,然后将按钮添加到该表格的左侧
例如
$(function(){
//Get the left position of the table
var leftPosition = $("table").offset().left;
//Get the top position of the table
var topPosition= $("table").offset().top;
//Now add the left position of the table minus the button width and a spacing of 5
var leftButtonPosition = leftPosition - $("myButton).width() + 5;
$("myButton).offset({ top: topPosition + 5 , left: leftButtonPosition });
});
等等瞧;)