CSS 在底部中心的面板内放置一个按钮(asp.net)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8140620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
position a button inside a panel in bottom center (asp.net)
提问by Rodniko
i read about centering (bottom-center) a button inside a div , which is like centering a button inside a panel. i succeeded in doing that by adding this to the CSS of the button:
我读过关于在 div 内居中(底部居中)一个按钮,这就像在面板内居中按钮一样。我通过将其添加到按钮的 CSS 中成功地做到了这一点:
position:absolute;
margin-left:50%;
margin-right:50%;
bottom: 5px;
and the panel css property is:
面板 css 属性是:
position:relative;
The problem is that it centers the left side of the button, so the button itself with his whole width is not centered.
问题是它在按钮的左侧居中,所以按钮本身及其整个宽度没有居中。
How do i center the center of the button, so it will look like the button is really centered?
我如何将按钮的中心居中,以便按钮看起来真的居中?
回答by sandeep
For example write like this if you have position absolute
:
例如,如果你有这样写position absolute
:
button{
position:absolute;
margin-left:-100px;
left:50%;
width:200px;
bottom:5px;
}
Note:give margin-left
half
of the width
of the button
注:给出margin-left
half
的width
的button
回答by Kevin Anthony Oppegaard Rose
Instead of:
代替:
margin-left:50%;
margin-right:50%;
try
尝试
margin-left:auto;
margin-right:auto;
回答by Eray
You should use
你应该使用
margin : 0 auto;
instead of margin-left
and margin-right
而不是margin-left
和margin-right
It's mean is 0 px margin for top and bottom (you can set it too!!) , and auto margin for left and right. It will center, object.
它的意思是顶部和底部的边距为 0 px(您也可以设置它!!),以及左右的自动边距。它将居中,反对。
And remove position : absulote;
并删除 position : absulote;