我最近开始玩Bootstrap并且我创建了我的徽标以便在页面的左上方,然后nav
栏在同一行但是在右侧,然后我想在屏幕中间说:“欢迎blablah”
然而,欢迎位出现在屏幕的顶部,而不是中间,因此出于某种原因它与徽标重叠。
不确定为什么这样做,猜测一些不好的编码等。
body {
font-family: 'Open Sans', sans-serif, Arial;
font-size: 16px;
color: #6D6D6D;
background-color: #F5F5F5;
font-weight: 300;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: 'Montserrat', sans-serif, Arial;
padding-bottom: 5px;
color: #373432;
line-height: 1em;
font-weight: normal;
}
a {
text-decoration: none;
outline: none;
}
.parallax {
background-image: url("../Images/back1.jpg");
min-height: 1000px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
}
.logo {
float: left;
padding-top: 50px;
padding-left: 40px;
}
.logo h1 {
text-transform: uppercase;
font-weight: 900;
font-size: 60px;
letter-spacing: -5px;
line-height: 50px;
color: white;
}
.navbar-nav>li>a {
line-height: 6px;
}
.navbar {
float: right;
padding-top: 53px;
padding-right: 60px;
font-size: 13px;
text-transform: uppercase;
}
.navbar-default {
background-color: transparent;
border-top: 0px solid rgba(0, 0, 0, 0.5);
border-bottom: 0px solid rgba(0, 0, 0, 0.5);
border-left: 0px solid rgba(0, 0, 0, 0.5);
border-right: 0px solid rgba(0, 0, 0, 0.5);
}
.navbar-default .navbar-nav>li>a {
color: #ffffff;
}
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav>li>a:focus {
background-color: #F8BD23;
text-decoration: none;
color: #ffffff;
-webkit-transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
}
.navbar-nav>li {
padding-left: 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="parallax">
<div class="logo"><img src="http://placehold.it/50x50"></div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" class="navbar-toggle collapsed" data-target="#navbar" data-toggle="collapse" type="button"><span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">a</a>
</li>
<li>
<a href="#">b</a>
</li>
<li>
<a href="#">c Us</a>
</li>
<li>
<a href="#">d</a>
</li>
<li>
<a href="#">e</a>
</li>
<li>
<a href="#">f</a>
</li>
<li class="dropdown">
<a aria-expanded="false" aria-haspopup="true" class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">Classes</a>
<ul class="dropdown-menu">
<li>
<a href="#">a</a>
</li>
<li>
<a href="#">b</a>
</li>
<li>
<a href="#">c</a>
</li>
<li>
<a href="#">d</a>
</li>
<li>
<a href="#">We</a>
</li>
<li>
<a href="#">r</a>
</li>
<li>
<a href="#">a</a>
</li>
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
<div class="container">
<div class="HomeMes">
<h1>WELCOME</h1>
</div>
</div>
</div>
我可以“修复”它的方式是在margin-top: 200px;
类上进行HomeMes
,但我知道这是错误的编码,因此我正在尝试找到正确的方法。如果有人能让我知道我做错了什么就会很好。感谢。
所以看起来应该是这样的:
Logo Navbar
Welcome message
答案 0 :(得分:1)
先生,请先将容器类更改为:
.container {
width:100%;
height:100%;
display:flex;
justify-content:center;
flex-direction: column;
align-items: center;
}
在Chrome中测试它并且它可以工作,但由于某种原因它在代码片段预览中不起作用。希望这对你有所帮助。显示:当尝试水平+垂直对齐元素时,flex有很多帮助!