【发布时间】:2018-05-13 23:29:56
【问题描述】:
我正在练习 flexbox,但被困在了一个特定的练习上。首先,我有一个来自引导程序的导航栏和一个来自引导程序的 CDN。在导航栏下是完全空的,它是我试图将 4 个不同的列均匀分布在窗口和导航栏下的地方。那是由于某种原因不能做的事情。我尝试了所有的 flexbox 命令,但没有。谁能解释我的css无法工作的原因? https://jsfiddle.net/3k2xvt1k/#&togetherjs=FARNdVGlUO
HTML 代码
<!DOCTYPE html>
<html>
<head>
<title>Hover</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="hover.css">
</head>
<body>
<nav class="navbar navbar-light bg-light">
<span class="brand">YORGOS LAFAZANIDIS</span>
<ul class="nav justify-content-end">
<li class="nav-item">
<a href="#">Home</a>
</li>
<li class="nav-item">
<a href="#">Culture</a>
</li>
<li class="nav-item">
<a href="#">Bundles</a>
</li>
<li class="nav-item">
<a href="#">Contact</a>
</li>
</ul>
</nav>
<section class="b">
<h1>Hero text</h1>
<p><h5>Text text text</h5></p>
</section>
<section class="b2">
<h1>Hero text</h1>
<p><h5>Text text text</h5></p>
</section>
<!-- <section class="b3">
<h1>Hero text</h1>
<p><h5>Text text text</h5></p>
</section>
<section class="b4">
<h1>Hero text</h1>
<p><h5>Text text text</h5></p>
</section>
-->
</body>
</html>
CSS 代码
.brand {
color: #706965;
font-weight: bold;
font-size: 21px;
letter-spacing: 1px;
}
.nav-item {
margin: 15px;
letter-spacing: 1px;
text-decoration: none;
}
a {
color: #706965;
}
a:hover {
text-decoration: none;
}
.b {
display: flex;
flex-direction: column;
background-color: #ccc1c1;
max-width: 25%;
min-height: 100vh;
align-items: center;
}
.b2 {
display: flex;
flex-direction: column;
background-color: #ccc1c1;
max-width: 25%;
min-height: 100vh;
}
.b3 {
display: flex;
flex-wrap: wrap;
flex-direction: column;
background-color: #ccc1c1;
max-width: 25%;
min-height: 100vh;
align-items: center;
justify-content: space-around;
}
.b4 {
display: flex;
flex-wrap: wrap;
flex-direction: column;
background-color: #ccc1c1;
max-width: 25%;
min-height: 100vh;
align-items: center;
justify-content: space-around;
}
【问题讨论】:
-
问题不在于 CSS 不起作用。就是它不像你期望的那样工作。我们无法从上面的代码中知道您的期望是什么,除非您明确指定它们:“我希望
a按照链接的官方文档执行 b c”。请指定您对什么属性的值的期望,我们可以将您指向说明为什么它不会发生的文档,并且最有可能的是,我们可能会为您提供获得所需行为的替代方法。