Css 按钮中心定位
我在表格中排成一行的按钮的中心位置有问题。我使用了宽度和边距,但不起作用。你能帮我吗?以下是该按钮的代码(css): 试试这个Css 按钮中心定位,css,Css,我在表格中排成一行的按钮的中心位置有问题。我使用了宽度和边距,但不起作用。你能帮我吗?以下是该按钮的代码(css): 试试这个 button{ height:20px; width:100px; position:relative; top:50%; left:50%; } 对于水平对齐,请使用 button{ margin: 0 auto; } 为了实现这一点,我将使用以下代码: .subm { position:absolute;
button{
height:20px;
width:100px;
position:relative;
top:50%;
left:50%;
}
对于水平对齐,请使用
button{
margin: 0 auto;
}
为了实现这一点,我将使用以下代码:
.subm {
position:absolute;
width:130px;
height:25px;
top: calc(50% - 13px); // 50% - 0.5 * height.
left: calc(50% - 65px); // 50% - 0.5 * width.
}
对于家长:
position: relative;
如果您使用了宽度和边距:auto,并且它仍然没有居中,您可以看到,您可能只需要将
显示:块
添加到.sumb
类中,如下所示:
.subm {
display:block;
position:relative;
width:130px;
margin-left:auto;
margin-right:auto;
background-image:url('background.bmp');
border:none;
color:white;
opacity:1;
height:25px;
outline:0 none;
box-shadow:1px 1px 2px black
}
演示:添加提琴你的按钮类别见:提琴:,有趣的一个:可能重复的
margin:-10px-50px代码>?为了反映元素的一半高度?是的,我在问自己为什么tooIMHO-20px
应该是-10px
我会使用转换:翻译(-50%,-50%)代码>以避免修改两倍的值^^
.subm {
display:block;
position:relative;
width:130px;
margin-left:auto;
margin-right:auto;
background-image:url('background.bmp');
border:none;
color:white;
opacity:1;
height:25px;
outline:0 none;
box-shadow:1px 1px 2px black
}