Css 固定页面中间按钮的固定位置
我的页面有一个固定宽度的大div,如下所示:Css 固定页面中间按钮的固定位置,css,position,margin,fixed,Css,Position,Margin,Fixed,我的页面有一个固定宽度的大div,如下所示: #index_body{ width: 1010px; background-image: url('images/main_bg_dark.png'); margin: auto; overflow: hidden; min-height: 50px; padding-bottom: 10px; border-radius: 7px; -moz-box-shadow: 0 5px 15px #000000; -
#index_body{
width: 1010px;
background-image: url('images/main_bg_dark.png');
margin: auto;
overflow: hidden;
min-height: 50px;
padding-bottom: 10px;
border-radius: 7px;
-moz-box-shadow: 0 5px 15px #000000;
-webkit-box-shadow: 0 5px 15px #000000;
box-shadow: 0 5px 15px #000000;
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
left:WHAT SHOULD BE HERE??
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
margin-left: 1010px;
}
我想在页面右侧(垂直于中间)添加按钮(20x20px)——仍然在索引体旁边
所以按钮有如下代码:
#index_body{
width: 1010px;
background-image: url('images/main_bg_dark.png');
margin: auto;
overflow: hidden;
min-height: 50px;
padding-bottom: 10px;
border-radius: 7px;
-moz-box-shadow: 0 5px 15px #000000;
-webkit-box-shadow: 0 5px 15px #000000;
box-shadow: 0 5px 15px #000000;
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
left:WHAT SHOULD BE HERE??
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
margin-left: 1010px;
}
因为这取决于实际的分辨率。我的索引体始终居中。如果我更改分辨率,我的按钮将移到左右
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
right: 10%;
}
10%就是一个例子,更改为一个看起来不错的百分比,它应该对屏幕分辨率做出响应
另一方面,为什么要在固定的容器中使用固定的元素?只需将其设置为绝对值,并将其向右浮动一个边距。好的,它应该是这样的:
#index_body{
width: 1010px;
background-image: url('images/main_bg_dark.png');
margin: auto;
overflow: hidden;
min-height: 50px;
padding-bottom: 10px;
border-radius: 7px;
-moz-box-shadow: 0 5px 15px #000000;
-webkit-box-shadow: 0 5px 15px #000000;
box-shadow: 0 5px 15px #000000;
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
left:WHAT SHOULD BE HERE??
}
#butt {
width:20px;
height:20px;
background: url('images/scrollUp.png');
position:fixed;
top:50%;
margin-left: 1010px;
}
不要设置
左
或右
位置,而是确保按钮元素位于索引元素内,然后使用边距
margin:0px 0px 0px 1010px代码>
这是一个经过测试并能正常工作的代码版本-这10%是免费的。因为随着分辨率的改变,它会移动。。。