吐槽话语:
最近小编被折磨够了,因为小编在制作一个生活资源网的学习项目!小编我只能说太折磨人了。在编写过程中遇到过许多的bug,虽然小编现在是做完了,但是我还是忍不住要吐槽一下,这个网站真的好麻烦,好几次改效果都快让我写不下去了,因为实在是太繁琐,经历了几天的战斗,最让我痛苦的莫过于导航栏的这一块的效果,气得我抓狂!虽然最后还是解决了,但是我也已经精疲力竭了。
其实问题的本身在于是否细心,很多样式都是小编我不细心导致!最后做完了我真的激动了!
心里狂喊:欧耶! 欧耶! 欧耶!
下面还是来说说我遇到的学习问题好了!再多吐槽的话也不能忘了正事!
问题内容:
第一个问题: 就是导航栏的问题,由于是响应式的页面,所以需要在不同的大小的窗口下显示不同的头部导航。
第二个问题: 在超小屏下鼠标放在a标签上时,从左侧滑出一个导航栏,同时滑出的导航栏是可以选中的。
就是这两个问题困扰我良久,今天给大家分享一下!
问题展示:
第一个问题:
响应式网站我们都知道有四个屏,超小屏,小屏,中屏,大屏,中屏和大屏的导航栏样式因为是一样的,所以小编写了三种屏幕下的导航栏。
- 超小屏:
- 小屏:
在这里小编解释一下哈!大家是不是觉得这个小屏下的导航栏有点丑,虽然我也这么觉得,但是他就是这样的,这个导航栏的字体样色设置的是白色,背景颜色也是白色,虽然我也不知道为什么要这么设置,但是他的要求就是这样的,当鼠标放上去字体样色就是黑色了。 - 中屏和大屏:
第二个问题:
- 别人的效果是这样子的:
别人的效果
- 我的却是这个样子的:
我的效果
解决方法:
第一个问题:
小编我比较笨,所以选择了比较麻烦的方法,直接制作了三个导航栏,给他们设置不同屏幕下的显示与隐藏。这个问题就完美的解决了。
代码展示:
<div class="header hidden-sm hidden-xs">
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-3 logo">
<img src="picture/logo.png" alt="">
</div>
<ul class="col-md-8 col-sm-8 col-xs-8 nav-one">
<li><a href="index.html">首页</a></li>
<li><a href="news.html">新闻</a></li>
<li><a href="tuijian.html">推荐</a></li>
<li><a href="#">热榜</a></li>
<li><a href="yuer.html">育儿</a></li>
<li><a href="美容.html">美容</a></li>
<li><a href="整形.html">整形</a></li>
<li><a href="养生.html">养生</a></li>
</ul>
<div class="col-md-1 col-sm-1 col-xs-1 search">
<a href="" class="glyphicon glyphicon-search"></a>
</div>
</div>
</div>
</div>
<div class="header-two visible-sm hidden-md">
<div class="container">
<div class="row">
<ul class="header1-nav">
<li><a href="index.html">首页</a></li>
<li><a href="news.html">新闻</a></li>
<li><a href="tuijian.html">推荐</a></li>
<li><a href="#">热榜</a></li>
<li><a href="yuer.html">育儿</a></li>
<li><a href="美容.html">美容</a></li>
<li><a href="整形.html">整形</a></li>
<li><a href="养生.html">养生</a></li>
</ul>
</div>
</div>
</div>
<div class="header-three visible-xs hidden-sm hidden-md">
<div class="container">
<div class="row">
<a href="#" class="col-xs-2 first">
<span class="btn">
</span>
</a>
<div class="wai-nav">
<a href="#" class="glyphicon glyphicon-remove wai-a"></a>
<a href="#" class="wai-a">首页</a>
<a href="#" class="wai-a">新闻</a>
<a href="#" class="wai-a">推荐</a>
<a href="#" class="wai-a">热榜</a>
<a href="#" class="wai-a">育儿</a>
<a href="#" class="wai-a">美容</a>
<a href="#" class="wai-a">整形</a>
<a href="#" class="wai-a">养生</a>
</div>
<div class="col-xs-8 three-banner">
<img src="picture/logo.png" alt="">
</div>
<a href="#" class="col-xs-2 last"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
css代码:
// 超小屏
@media screen and (max-width:768px) {
html{
font-size:12px!important ;
// font-size: (768px / 12);
}
.main{
padding-top: 0 !important;
}
footer{
text-align: center;
}
}
// 小屏
@media screen and (min-width:768px) {
html{
font-size:14px!important ;
// font-size: (750px / 12);
}
.main{
padding-top: 0 !important;
}
footer{
text-align: center;
}
}
// 中屏
@media screen and (min-width:992px) {
html{
font-size:16px!important ;
// font-size: (970px / 12);
}
.main{
padding-top: 0 !important;
}
footer{
text-align: center;
}
}
// 大屏
@media screen and (min-width:1170px) {
html{
font-size:20px!important ;
// font-size: (1170px / 12);
}
footer{
text-align:left;
}
}
body{
background-color: #f6f6f6 !important;
}
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
}
a{
text-decoration: none;
}
a:hover{
text-decoration: none;
}
// 头部导航栏
.header{
width: 100%;
height: 4.5rem;
line-height: 4.5rem;
background-color: green;
z-index: 999;
.logo{
img{
width: 100%;
}
}
.nav-one{
li{
float: left;
&:nth-child(8) a{
color: black;
border-left: 0;
}
a{
font-size: 1rem;
padding: 0 1rem;
color: #fff;
border-left: .05rem solid rgba(255, 255, 255, 0.1);
&:hover{
color: black;
text-decoration: none;
}
}
}
}
.search{
height: 4.5rem;
position: relative;
a{
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
display: block;
color: #fff;
font-size: 1rem;
}
}
}
.header-two{
padding-top: 4.5rem;
background-color: #fff;
width: 100%;
border-bottom: 1px solid #ccc;
height: 7rem;
ul{
li{
// width: (100% / 8);
float: left;
&:nth-child(8) a{
color: black;
border-left: 0;
}
a{
padding: 0.5rem 2rem;
font-size: 1.3rem;
border-left: 1px solid green;
color: #fff;
&:hover{
color: black;
text-decoration: none;
}
}
}
}
}
.header-three{
background-color: green;
width: 100%;
border-bottom: 1px solid green;
height: 4.5rem;
line-height: 4.5rem;
position: relative;
text-align: center;
.first{
color: #fff;
font-size: 1.5rem;
text-decoration: none;
// background-color: tomato;
height: 4.5rem;
display: block;
span{
display: block;
margin-top: 1rem;
width: 2rem;
height: 2rem;
border-top: 2px solid #fff;
border-bottom: 2px solid #fff;
}
&:hover +.wai-nav{
transform: translateX(0);
}
}
.last{
color: #fff;
font-size: 1.5rem;
text-decoration: none;
display: block;
&:hover{
color: #fff;
}
}
// 外部导航栏
.wai-nav{
position: absolute;
top: 4.5rem;
left: 0;
transform: translateX(-100%);
width: 50%;
height: 100rem;
text-align: left !important;
line-height: normal;
// animation: move 3s forwards;
transition: all 0.3s linear;
background-color: #fff;
z-index: 99;
.wai-a{
display: block;
width: 100%;
padding: 1rem 0 1rem 2rem;
font-size: 1.5rem;
color: black;
&:nth-child(1){
&:hover{
color: black;
}
}
&:nth-child(2){
color: green;
}
&:hover{
color: green;
text-decoration: none;
}
}
&:hover{
transform: translateX(0);
}
}
.three-banner{
img{
width: 16rem;
height: 4rem;
}
}
}
第二个问题:
这个问题困扰了我一天的时间,我好多次都想改的放弃了,最后的做法却让我吐血三升。其实只需要给滑出的导航添加一个:hover就可以了,让他滑出来的时候鼠标可以放上去。最后我改出来之后真的让我吐血三升!
代码展示:
<div class="header-three visible-xs hidden-sm hidden-md">
<div class="container">
<div class="row">
<a href="#" class="col-xs-2 first">
<span class="btn">
</span>
</a>
<div class="wai-nav">
<a href="#" class="glyphicon glyphicon-remove wai-a"></a>
<a href="#" class="wai-a">首页</a>
<a href="#" class="wai-a">新闻</a>
<a href="#" class="wai-a">推荐</a>
<a href="#" class="wai-a">热榜</a>
<a href="#" class="wai-a">育儿</a>
<a href="#" class="wai-a">美容</a>
<a href="#" class="wai-a">整形</a>
<a href="#" class="wai-a">养生</a>
</div>
<div class="col-xs-8 three-banner">
<img src="picture/logo.png" alt="">
</div>
<a href="#" class="col-xs-2 last"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
css代码:
.header-three{
background-color: green;
width: 100%;
border-bottom: 1px solid green;
height: 4.5rem;
line-height: 4.5rem;
position: relative;
text-align: center;
.first{
color: #fff;
font-size: 1.5rem;
text-decoration: none;
// background-color: tomato;
height: 4.5rem;
display: block;
span{
display: block;
margin-top: 1rem;
width: 2rem;
height: 2rem;
border-top: 2px solid #fff;
border-bottom: 2px solid #fff;
}
&:hover +.wai-nav{
transform: translateX(0);
}
}
.last{
color: #fff;
font-size: 1.5rem;
text-decoration: none;
display: block;
&:hover{
color: #fff;
}
}
// 外部导航栏
.wai-nav{
position: absolute;
top: 4.5rem;
left: 0;
transform: translateX(-100%);
width: 50%;
height: 100rem;
text-align: left !important;
line-height: normal;
// animation: move 3s forwards;
transition: all 0.3s linear;
background-color: #fff;
z-index: 99;
.wai-a{
display: block;
width: 100%;
padding: 1rem 0 1rem 2rem;
font-size: 1.5rem;
color: black;
&:nth-child(1){
&:hover{
color: black;
}
}
&:nth-child(2){
color: green;
}
&:hover{
color: green;
text-decoration: none;
}
}
&:hover{
transform: translateX(0);
}
}
.three-banner{
img{
width: 16rem;
height: 4rem;
}
}
}
可恶啊! 啊!啊!啊!啊!啊!