我有一个工作正常的导航栏但我希望导航栏品牌具有不同的字体和大小的样式并且垂直居中但是当我在不同的浏览器和媒体类型上查看它时它似乎改变了它的位置而且从不在中间,即在iPhone和平板电脑上。
css代码是:
a[href^=tel] { color: inherit; text-decoration: none; }
.navbar-default {
padding-left:0px;
padding-right:0px;
border: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
background-color: #00a3fe;
font-size: 14pt;font-weight: 400;}
a:hover {
text-decoration:none;
}
.nav.navbar-nav.navbar-right li a {
color: #ffffff;
}
.nav.navbar-nav.navbar-nav li a {
color: #ffffff;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
background-color: #49bdfe;
color: #FFFFFF;
}
.navbar-toggle, .icon-bar {
border:1px solid white;
background-color:white;
}
.navbar-toggle {
color: : white;
border: none;
background: transparent !important;
}
.navbar-toggle:hover {
background: transparent !important;
}
.navbar-toggle {
border: none;
background: transparent !important;
}
.navbar-toggle:hover {
background: transparent !important;
}
.navbar-toggle .icon-bar {
width: 22px;
transition: all 0.2s;
}
.navbar-toggle .top-bar {
transform: rotate(45deg);
transform-origin: 10% 10%;
}
.navbar-toggle .middle-bar {
opacity: 0;
}
.navbar-toggle .bottom-bar {
transform: rotate(-45deg);
transform-origin: 10% 90%;
}
.navbar-toggle.collapsed .top-bar {
transform: rotate(0);
}
.navbar-toggle.collapsed .middle-bar {
opacity: 1;
}
.navbar-toggle.collapsed .bottom-bar {
transform: rotate(0);
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
padding: 10px 16px;
transition: all 0.4s ease 0s;
}
.btn-lg {
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}
.btn-primary {
color: #fff;
background-color: #49bdfe;
border-color: #357ebd;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-primary.active,
.open .dropdown-toggle.btn-primary {
color: #fff;
background-color: #3276b1;
border-color: #285e8e;
}
和html是:
<nav class='navbar navbar-default'>
<div class='container'>
<div class='navbar-header'>
<button type='button' class = 'navbar-toggle collapsed' data-toggle = 'collapse' data-target = '#example-navbar-collapse'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar top-bar'></span>
<span class='icon-bar middle-bar'></span>
<span class='icon-bar bottom-bar'></span></button>
<span class='navbar-brand'>My Site</span>
</div>
<div class='collapse navbar-collapse' id = 'example-navbar-collapse'>
<ul class='nav navbar-nav'>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>About</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Get bids</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Register company</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Contact</a></li>
</ul>
<ul class='nav navbar-nav navbar-right'>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'><span class='glyphicon glyphicon-user'></span> Login</a></li>
</ul>
</div>
</div>
</nav>
答案 0 :(得分:1)
您可以使用display: flex; align-items: center
使其垂直对齐。
a[href^=tel] { color: inherit; text-decoration: none; }
.navbar-default {
padding-left:0px;
padding-right:0px;
border: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
background-color: #00a3fe;
font-size: 14pt;font-weight: 400;}
a:hover {
text-decoration:none;
}
.nav.navbar-nav.navbar-right li a {
color: #ffffff;
}
.nav.navbar-nav.navbar-nav li a {
color: #ffffff;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
background-color: #49bdfe;
color: #FFFFFF;
}
.navbar-toggle, .icon-bar {
border:1px solid white;
background-color:white;
}
.navbar-toggle {
color: : white;
border: none;
background: transparent !important;
}
.navbar-toggle:hover {
background: transparent !important;
}
.navbar-toggle {
border: none;
background: transparent !important;
}
.navbar-toggle:hover {
background: transparent !important;
}
.navbar-toggle .icon-bar {
width: 22px;
transition: all 0.2s;
}
.navbar-toggle .top-bar {
transform: rotate(45deg);
transform-origin: 10% 10%;
}
.navbar-toggle .middle-bar {
opacity: 0;
}
.navbar-toggle .bottom-bar {
transform: rotate(-45deg);
transform-origin: 10% 90%;
}
.navbar-toggle.collapsed .top-bar {
transform: rotate(0);
}
.navbar-toggle.collapsed .middle-bar {
opacity: 1;
}
.navbar-toggle.collapsed .bottom-bar {
transform: rotate(0);
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
padding: 10px 16px;
transition: all 0.4s ease 0s;
}
.btn-lg {
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}
.btn-primary {
color: #fff;
background-color: #49bdfe;
border-color: #357ebd;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-primary.active,
.open .dropdown-toggle.btn-primary {
color: #fff;
background-color: #3276b1;
border-color: #285e8e;
}
.navbar-brand {
font: 24px cursive!important;
display: flex;
align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class='navbar navbar-default'>
<div class='container'>
<div class='navbar-header'>
<button type='button' class = 'navbar-toggle collapsed' data-toggle = 'collapse' data-target = '#example-navbar-collapse'>
<span class='sr-only'>Toggle navigation</span>
<span class='icon-bar top-bar'></span>
<span class='icon-bar middle-bar'></span>
<span class='icon-bar bottom-bar'></span></button>
<span class='navbar-brand'>My Site</span>
</div>
<div class='collapse navbar-collapse' id = 'example-navbar-collapse'>
<ul class='nav navbar-nav'>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>About</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Get bids</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Register company</a></li>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'>Contact</a></li>
</ul>
<ul class='nav navbar-nav navbar-right'>
<li><a href='about.php' class='btn btn-primary btn-lg sharp' role='button'><span class='glyphicon glyphicon-user'></span> Login</a></li>
</ul>
</div>
</div>
</nav>