Html 使按钮位于页面的绝对中心和中间
我试图制作一个带有一个大按钮的页面,该按钮始终位于页面的绝对中间/中间。我希望按钮文本是大的,但当我把它大,它抵消按钮,它不再在中间。我做错了什么 (我还安装了引导程序,并且很高兴使用行/列/偏移) CSSHtml 使按钮位于页面的绝对中心和中间,html,css,twitter-bootstrap-3,Html,Css,Twitter Bootstrap 3,我试图制作一个带有一个大按钮的页面,该按钮始终位于页面的绝对中间/中间。我希望按钮文本是大的,但当我把它大,它抵消按钮,它不再在中间。我做错了什么 (我还安装了引导程序,并且很高兴使用行/列/偏移) CSS .btn-text { vertical-align: middle; font-family: 'Corben'; font-size: 580%; } .wrapper { text-align: center; } .btn { positi
.btn-text {
vertical-align: middle;
font-family: 'Corben';
font-size: 580%;
}
.wrapper {
text-align: center;
}
.btn {
position: absolute;
top: 50%;
padding: 20%;
}
.btn-text {
font-family: 'Corben';
font-size: 280%;
}
.wrapper {
position: fixed;
width: 100%;
height: 100%;
display: flex;
align-items: center;
}
HTML
...
<body>
<div class="wrapper">
<div class="btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
</body>
...
<div class="wrapper">
<div class="center-block btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
。。。
按钮
...
jsIDLE:如果使用CSS3转换可以(如果您不需要支持IE如果使用CSS3转换可以(如果您不需要支持IE另一种解决方案是使用引导
中心块
类将按钮水平居中,使用flexbox将按钮垂直居中)
HTML
...
<body>
<div class="wrapper">
<div class="btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
</body>
...
<div class="wrapper">
<div class="center-block btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
另一种解决方案是使用Bootstrap
center block
类水平居中按钮,使用flexbox垂直居中按钮
HTML
...
<body>
<div class="wrapper">
<div class="btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
</body>
...
<div class="wrapper">
<div class="center-block btn btn-large btn-primary" id="oujh-button">
<div class="btn-text">BUTTON</div>
</div>
</div>
Rad,这完全有效。我绝对不支持IEI我很高兴!这是一个非常实用的方法,用于将任何东西集中在它的(相对)容器中。很高兴能提供帮助!Rad,这完全有效。我绝对不支持IEI我很高兴!这是一个非常实用的方法,用于将任何东西集中在它的(相对)容器中集装箱。很乐意帮忙!