我对flexbox很新。我似乎无法弄清楚如何将div定位到flex容器的底部。我搜索堆栈溢出的解决方案,但没有任何作用。显然,我做错了什么。
因此div 标题底部应位于标题容器的底部。任何帮助都感激不尽。提前谢谢。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="author" content="">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Website</title>
<!-- STYLESHEETS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- FONTS -->
<link href="https://fonts.googleapis.com/css?family=Playball|Raleway: 300,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header class="header">
<div class="header-logo">
<a href="/">
<img class="header-logo-img" src="http://placehold.it/100x100" alt="">
</a>
</div>
<nav class="header-nav-primary" role="navigation">
<ul class="nav-primary-items">
<li class="nav-primary-item">
<a class="nav-primary-link" href="#home">Home</a>
</li>
<li class="nav-primary-item">
<a class="nav-primary-link" href="#menu">Menu</a>
</li>
<li class="nav-primary-item">
<a class="nav-primary-link" href="#over">Over</a>
</li>
<li class="nav-primary-item">
<a class="nav-primary-link" href="#contact">Contact</a>
</li>
</ul>
</nav>
<div class="header-bottom">
<div class="social-media">
<a href="http://www.facebook.be" target="_blank">
<i class="fa fa-facebook fa-lg" aria-hidden="true"></i>
</a>
<a href="http://www.instagram.be" target="_blank">
<i class="fa fa-instagram fa-lg" aria-hidden="true"></i>
</a>
</div>
<div class="address">
<p>Diestsesteenweg ###<br>3010 Kessel-Lo<br>###/## ## ##</p>
</div>
</div>
</header>
<main class="main">
<section id="home"></section>
<section id="menu"></section>
<section id="over"></section>
<section id="contact"></section>
</main>
</div>
</body>
</html>
CSS
body {
min-width: 320px;
background-color: #fff;
font-family: 'Montserrat', sans-serif;
color: #f1ebda;
font-size: 1.5rem;
font-weight: 300;
line-height: 1.8;
}
.wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
min-width: 100vw;
min-height: 100vh;
}
.header {
padding: 2.75rem;
background-color: #303030;
}
.header-logo {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 5.625rem;
}
.nav-primary-items {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: row wrap;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
list-style: none;
margin: 0 0 1.250rem 0;
padding: 0;
}
.nav-primary-item {
margin: 0 .4rem;
}
.nav-primary-link {
display: inline-block;
padding: 0 .4rem;
text-transform: uppercase;
letter-spacing: 0.188rem;
font-size: 1.1rem;
}
.header-bottom {
text-align: center;
}
.social-media i {
margin-right: 1.250rem;
}
.address p {
margin: 1.250rem 0 0 0;
}
.main {
overflow: auto;
padding: 4.45rem 2.75rem;
}
h1, h2, h3, h4, h5, h6 {
margin: 0 0 1.05rem;
padding: 0;
color: #111;
font-weight: 700;
line-height: 1.2;
font-family: 'Playball', sans-serif;
}
a {
text-decoration: none;
color: #f1ebda;
}
a:active,
a:hover,
a:focus {
color: #f1ebda;
text-decoration: none;
}
@media (min-width: 840px) {
.wrapper {
-webkit-box-orient: horizontal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
overflow: hidden;
height: 100vh;
}
.header {
-webkit-box-flex: 0;
-webkit-flex: 0 0 32rem;
-ms-flex: 0 0 32rem;
flex: 0 0 32rem;
padding: 4.45rem 2.75rem;
max-width: 32rem;
}
.header-nav-primary {
margin-bottom: 2.75rem;
}
.nav-primary-items {
-webkit-flex-flow: column nowrap;
-ms-flex-flow: column nowrap;
flex-flow: column;
text-align: center;
}
.nav-primary-item {
margin-bottom: 3.125em;
}
.nav-primary-link {
display: block;
padding: .4rem;
}
.main {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
padding: 4.45rem;
}
}
答案 0 :(得分:-1)
只需添加:
align-self: flex-end;
到你想要放在底部的元素。
如果您想学习其他一些很酷的技巧,这些是Flexbox的精彩指南:
答案 1 :(得分:-1)
使用以下代码:
.header-bottom{
align-self: flex-end;
text-align: center;
}
请参阅本教程:https://css-tricks.com/snippets/css/a-guide-to-flexbox/