我在尝试将按钮放置在 div 的底部和中心时遇到了一个真正的问题。我最终让它在全屏模式下看起来正确,但我知道这种方法是完全错误的。
我能够按照我想要的方式对齐文本,但按钮的位置和翻译功能不一样。我尝试使用 bootstraps 列,但没有用。我不确定我是否完全理解相对于它们的父元素或位置定位事物。另外,我试过了
vertical-align:bottom
vertical-align:baseline
这些都不起作用。
在 div 的底部和中心放置按钮或任何元素的最佳做法是什么
.navbar-brand {
font-family: 'Great Vibes', cursive;
font-size: 30px;
margin: 5px 0px 5px 1px;
}
.navbar-brand {
color: #F05F40 !important;
}
.jumbotron {
background: url('http://i65.tinypic.com/1213l9y.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100vh;
width: 100vw;
margin-left: -15px;
}
.jumbotron h1 {
font-family: 'Great Vibes', cursive;
font-size: 75px;
color: white;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.jumbotron h4 {
font-family: 'Great Vibes', sans-serif;
font-size: 25px;
color: white;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.btn-primary {
color: white;
background-color: #F05F40;
border-color: #F05F40;
-webkit-transition: all 0.35s;
-moz-transition: all 0.35s;
transition: all 0.35s;
margin-top: 25%;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary.focus,
.btn-primary:active,
.btn-primary.active,
.open>.dropdown-toggle.btn-primary {
color: white;
background-color: #ee4b28;
border-color: #ed431f;
}
.btn-primary:active,
.btn-primary.active,
.open>.dropdown-toggle.btn-primary {
background-image: none;
}
.btn-primary.disabled,
.btn-primary[disabled],
fieldset[disabled] .btn-primary,
.btn-primary.disabled:hover,
.btn-primary[disabled]:hover,
fieldset[disabled] .btn-primary:hover,
.btn-primary.disabled:focus,
.btn-primary[disabled]:focus,
fieldset[disabled] .btn-primary:focus,
.btn-primary.disabled.focus,
.btn-primary[disabled].focus,
fieldset[disabled] .btn-primary.focus,
.btn-primary.disabled:active,
.btn-primary[disabled]:active,
fieldset[disabled] .btn-primary:active,
.btn-primary.disabled.active,
.btn-primary[disabled].active,
fieldset[disabled] .btn-primary.active {
background-color: #F05F40;
border-color: #F05F40;
}
.btn-primary .badge {
color: #F05F40;
background-color: white;
}
.btn {
font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
border: none;
border-radius: 300px;
font-weight: 700;
text-transform: uppercase;
}
.btn-xl {
padding: 15px 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">The Authentic Gentleman</a>
</div>
<nav class="pull-right collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">Blog</a>
</li>
<li>
<a href="#">Advice</a>
</li>
<li class="#">
<a href="#">About</a>
</li>
</ul>
</nav>
</div>
</header>
<div class="container-fluid">
<div class="jumbotron">
<h1 class="text-center">The Authetnic Gentelman</h1>
<h4 class="text-center">Refine your life</h4>
<div class="text-center">
<a href="#about" class="btn btn-primary btn-xl">Find Out More</a>
</div>
</div>
</div>
最佳答案
您可以使用 position: absolute;
设置它。 updated codepen
<div class="text-center btnDiv">
<a href="#about" class="btn btn-primary btn-xl">Find Out More</a>
</div>
.jumbotron {
position: relative;
}
.btnDiv {
width: 100%;
left: 0;
bottom: 10px;
position: absolute;
}
关于html - 如何在div的底部和中心放置一个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45181899/