CSS将元素浮动到居中元素旁边
我的页面中央有一张桌子 是否可以将示例中的按钮放在表格左侧? 这张技艺高超的图纸应该能让您更好地了解:CSS将元素浮动到居中元素旁边,css,css-float,center,Css,Css Float,Center,我的页面中央有一张桌子 是否可以将示例中的按钮放在表格左侧? 这张技艺高超的图纸应该能让您更好地了解: | | | $$center | | | 其中$$是我想放在中间的按钮。根据您的JSFIDLE,尝试这种方法: HTML 按钮绝对位于从右边缘到跨度元素100%宽度的位置。您可以使用jquery解决此问题 在页面加载中,您可以检查表的起始位置,然后将按钮添加到此表的左侧 比如说 $(function(
| |
| $$center |
| |
其中$$是我想放在中间的按钮。根据您的JSFIDLE,尝试这种方法: HTML
按钮绝对位于从右边缘到跨度元素100%宽度的位置。您可以使用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 });
});
瞧 .center
{
宽度:250px;
保证金:0px自动0px自动;
}
.center输入[type=“button”],div
{
浮动:左;
}
中心文本
+1表示“高度熟练”:P
。图纸不能具备技能,人可以。
span {
display: block;
width: 200px;
margin: 0 auto;
position: relative;
}
button {
position: absolute;
right: 100%;
}
$(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 });
});
.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>