我目前正在尝试实现您在下面看到的设计:
除了输入字段和按钮的大小外,一切正常。我正在使用 Boostrap。
HTML:
<div className='jumbotron text-center'>
<div className='container'>
<h1 id='hero-questions-h1'>What’s your name?</h1>
</div>
<div className='container'>
<div class="col-sm-4 text-center">
<div className="form-group input-group-lg">
<input type="text" className="form-control"></input>
</div>
<button type="button" id="continue-btn" className="btn btn-success btn-block">Continue</button>
</div>
</div>
<div className='container'>
<h2 id='tip'>
Tip! You will get motivational playlists, stories, posters and much more
</h2>
</div>
<footer className="footer">
<div className="container">
<p id="social-proof" className="text-center">“Must have for every ambitious athlete!”</p>
<p id="social-proof-tagline" className="text-center">Anders Hasselstrøm, Deca Ironman (10x)</p>
</div>
</footer>
</div>
CSS:
.jumbotron {
height: 100vh;
margin-bottom: 0px !important;
background-image: url("bg-hero-v2.png");
background-size: cover;
}
#hero-h1 {
color: white;
font-family: 'Roboto', sans-serif;
font-weight: 700;
font-size: 60px;
padding-top: 10%;
}
#hero-h2 {
color: #ECECEC;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 20px;
margin-top: 30px;
line-height: 40px;
padding-bottom: 40px;
}
#hero-questions-h1 {
color: white;
font-family: 'Roboto', sans-serif;
font-weight: 700;
font-size: 60px;
padding-top: 10%;
padding-bottom: 30px;
}
.btn-success {
background-color: #66B878 !important;
}
.form-control {
background-color: transparent !important;
color: white !important;
}
#signup-btn {
padding-left: 40px;
padding-right: 40px;
padding-top: 15px;
padding-bottom: 15px;
}
#continue-btn {
height: 60px;
font-size: 18px;
}
#social-proof {
color: white;
font-family: 'Roboto', sans-serif;
font-weight: 500;
font-size: 18px;
font-style: italic;
}
#social-proof-tagline {
color: white;
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 16px;
}
#tip {
color: #ECECEC;
font-family: 'Roboto', sans-serif;
font-weight: 300;
font-size: 16px;
margin-top: 30px;
}
.footer {
padding-top: 20px;
padding-bottom: 20px;
position: fixed;
bottom: 0;
width: 100%;
background-color: black;
opacity: 0.6;
}
如您所见,我当前的实现如下所示:
最佳答案
DOM 元素使用 class
而不是 className
分配 CSS 类(您可能会将其与 JS .className
属性混淆)。要按照您的喜好放置字段,我建议您利用 Bootstrap 网格 col-x-offset-x
options将列从 .row
的左侧偏移定位
为了正确定位,记得放置一个.row
列周围的元素,以及 .container
之间的元素.另外,input
元素是自动关闭的(即你不需要尾随 </input>
)
HTML
<div class='jumbotron text-center'>
<div class='container'>
<h1 id='hero-questions-h1'>What’s your name?</h1>
</div>
<div class='container'>
<div class="row">
<div class="col-sm-offset-3 col-sm-6 text-center">
<div class="form-group input-group-lg">
<input type="text" class="form-control" />
</div>
<button type="button" id="continue-btn" class="btn btn-success btn-block">Continue</button>
</div>
</div>
</div>
<div class='container'>
<h2 id='tip'>
Tip! You will get motivational playlists, stories, posters and much more
</h2>
</div>
<footer class="footer">
<div class="container">
<p id="social-proof" class="text-center">“Must have for every ambitious athlete!”</p>
<p id="social-proof-tagline" class="text-center">Anders Hasselstrøm, Deca Ironman (10x)</p>
</div>
</footer>
</div>
关于html - 将 Bootstrap 表单组输入字段居中并使其变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606453/