【发布时间】:2018-02-12 00:03:49
【问题描述】:
在 600 像素时,我的 flexbox 变成了一列。第二个框中的列表在较小的屏幕尺寸上未正确居中。我尝试在媒体查询内外添加边距和填充。它坐得太靠右了。当我调整宽度时,它似乎卡在左侧。我该如何解决这个问题?
/* FLEXBOX */
.flexbox {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
.box {
padding: 5px;
}
/* Table and Cell for Vertical Alignment */
.table {
display: table;
}
.cell {
display: table-cell;
vertical-align: middle;
}
/* SHOWCASE */
#showcase {
background-color: #1d2120;
height: 100vh;
width: 100%;
display: table;
}
#showcase h1 {
padding-top: 0px;
font-family: Ubuntu;
font-size: 4em;
color: #da5d61;
}
#showcase h2 {
color: #bcd5d1;
font -family: Cairo;
font-size: 2em;
margin: 0 0 20px;
}
#showcase h3 {
color: #ba9077;
font-family: Cairo;
font-size: 1em;
}
#inline {
font-size: 3em;
}
#inline li {
font-size: 1.5em;
padding: 0 10px 0 10px;
}
@media screen and (max-width: 600px) {
.flexbox {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
text-align: center;
}
#contact .container {
width: 60%;
}
}
@media screen and (max-width: 610px) {
.flexbox {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
text-align: center;
}
#contact .container {
width: 60%;
}
}
<!-- SHOWCASE -->
<header id="showcase">
<div class="cell">
<div class="flexbox">
<div class="box text-center">
<h1 class="text animated pulse">Ellis Smith</h1>
<h2><i class="fa fa-pencil" aria-hidden="true"></i> Copywriter</h2>
<h3>Quality copy, never copied.</h3>
</div>
<!-- /box -->
<nav class="box">
<ul>
<li>
<a href="#services">Services</a></li>
<li>
<a href="#testimonials-placeholder">Testimonials</a>
<li>
<a href="#contact">Contact</a></li>
</ul>
</nav>
<!-- /box -->
</div>
<!-- /flexbox -->
</div>
<!-- /cell -->
</header>
<!-- /showcase -->
<!--/END SHOWCASE -->
【问题讨论】:
-
嗯...如果您已经在使用 Bootstrap,为什么不想为此使用 Bootstrap? Bootstrap 4 中的所有内容都是基于 flexbox 的,在使用 Bootstrap 时添加自定义 css hack 通常不是一个好主意,因为它往往需要更多 css hack 来解决由原始 css hack 引起的问题。
-
好点。所以我可以移除 flexbox 并在表格的单元格内放置一个引导网格?
-
是的,您完全可以单独使用 Bootstrap 完成所有操作,不,您不应该将其放入表格单元格中。表格单元格的应用案例非常少见。只是一个普通的行列对。我会在一分钟内发布一些东西。
标签: html css flexbox bootstrap-4 twitter-bootstrap-4