老师我给a1绝对定位一个菜单栏,为什么我的橙色盒子没能显示出来呢。
来源:2-7 使用CSS制作菜单
Vigorous阿炎
2020-10-23 16:32:36
.header-top{
height: 150px;
background-color: rgb(228, 187, 187);
}
.A{
height: 32px;
background-color: #2A2A2A ;
line-height: 32px;
}
.header-top .A .center-wrap{
}
.header-top .A .center-wrap .right .iconfont{
float: right;
margin-right: 16px;
line-height: 32px;
}
.header-top .A .center-wrap .right .iconfont:first-child{
margin-right: 0;
}
.header-top .A .center-wrap .right .dr,.zc{
font-size: 12px;
color: #FFFFFF;
text-align: justify;
line-height: 32px;
}
.header-top .A .center-wrap .A1{
float: left;
}
.header-top .A .center-wrap .A1> ul> li{
/* 大于号表示父亲的第一任儿子 */
font-size: 14px;
float: left;
margin-right: 18px;
}
.header-top a{
font-family: PingFangSC-Regular;
color: #FFFFFF;
text-align: justify;
line-height: 18px;
}
.header-top .A .center-wrap .A1> ul> li.a1{
/* li里面本身的一个a1元素用交集 */
padding-right:12px;
position: relative;
}
header-top .A .center-wrap .A1>ul>li.a1 .menu{
/* 为什么我的盒子没显示出来,难道是溢出隐藏掉了 */
position: absolute;
top: 30px;
left: 0;
width: 300px;
height: 400px;
background-color: rgb(138, 230, 102);
z-index: 9999;
}
.header-top .A .center-wrap .A1> ul> li.a1 .B{
position: absolute;
right: 0;
top: 50%;
margin-top: -6px;
width: 12px;
height: 12px;
transition: transform 0.2s linear 0s;
}
.header-top .A .center-wrap .A1> ul> li.a1:hover .B{
transform:rotate(180deg)
}
/* 先两个盒子使用绝对定位然后微调,然后大盒子hover,
之后控制大盒子transition旋转速度 */
.header-top .A .center-wrap .A1> ul> li.a1 .B .aa1{
position: absolute;
left: 2px;
top: 4px;
width: 6px;
height: 6px;
background-color: rgb(248, 248, 246);
transform: rotate(45deg);
}
.header-top .A .center-wrap .A1> ul> li.a1 .B .aa2{
position: absolute;
top: 2px;
left: 2px;
width: 6px;
height: 6px;
background-color: #2A2A2A;
transform: rotate(45deg);
}
.main-nav{
background-color: #20BD9A;
height: 40px;
}
.main-nav .center-wrap ul li{
float: left;
margin-right: 18px;
line-height: 40px;
font-size: 16px;
position: relative;
}
.main-nav .center-wrap ul li{
padding-right: 16px;
}
.main-nav .center-wrap ul li .b1{
position: absolute;
right: 0;
top: 50%;
margin-top: 0px;
/* transparent透明色 */
border: 8px solid transparent;
border-top-color:white;
border-bottom: none;
transition: transform 0.2s linear 0s;
}
.main-nav .center-wrap ul li:hover .b1{
transform: rotate(180deg);
}
.log-area{
height: 78px;
background-color: #fff;
}
.log-area h1{
float: left;
font-size: 24px;
color: #20BD9A;
text-align: justify;
line-height: 78px;
margin-right: 20px;
}
.log-area input{
float: left;
width: 373px;
height: 30px;
opacity: 0.3;
border: 1px solid #20BD9A;
border-radius: 8px 0 0 8px;
margin-top: 24px;
/* 取消默认的外线(外线是文本框特有的东西) */
outline: none;
}
.log-area .iconfont{
float: left;
margin-top: 24px;
width: 32px;
height: 30px;
background-color: #20BD9A;
border-radius: 0 4px 4px 0;
font-size: 20px;
text-align: center;
line-height: 30px;
}
HTML部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>慕云游</title>
<meta name="keywords" content="旅游,机票,观光,休闲">
<meta name="Description" content="旅游好地方,给你身心放个假,
机票,度假,观光,休闲旅游必去的地方">
<link rel="stylesheet" href="CSS/reset.css">
<link rel="stylesheet" href="CSS/base.css">
<link rel="stylesheet" href="CSS/css.css">
</head>
<body>
<head>
<header class="header-top site-head">
<!-- 整个页面区域 -->
<div class="A topbar">
<!-- 中间上半部分区域,还有下半部分所以需要分区 -->
<div class="center-wrap">
<!-- 正式编辑区 -->
<div class="A1">
<ul>
<li>
<a href="">目的地</a>
</li>
<li>
<a href="">锦囊</a>
</li>
<li class="a1">
<a href="">社区</a>
<div class="B">
<em class="aa1"></em>
<em class="aa2"></em>
</div>
</li>
<li>
<a href="">行程助手</a>
</li>
<li class="a1">
<a href="">商城</a>
<div class="B">
<em class="aa1"></em>
<em class="aa2"></em>
</div>
</li>
<li class="a1">
<a href="">酒店民宿</a>
<div class="B">
<em class="aa1"></em>
<em class="aa2"></em>
</div>
<div class="menu"></div>
</li>
<li>
<a href="">特价酒店</a>
</li>
</ul>
</div>
<div class="right">
<a class="iconfont dr" href="">登入</a>
<a class="iconfont zc" href="">注册</a>
<a class="iconfont" href=""></a>
<a class="iconfont" href=""></a>
<a class="iconfont" href=""></a>
<span class="iconfont">|</span>
<a class="iconfont" href=""></a>
</div>
</div>
</div>
<div class="main-nav">
<div class="center-wrap">
<div>
<ul>
<li class="b">
<a href="">机酒自由行</a>
<p class="b1"></p>
</li>
<li>
<a href="">优惠机票</a>
</li>
<li class="b">
<a href="">跟团游</a>
<p class="b1"></p>
</li>
<li>
<a href="">酒店</a>
</li>
<li class="b">
<a href="">当地玩乐</a>
<p class="b1"></p>
</li>
<li>
<a href="">签证</a>
</li>
<li>
<a href="">游轮</a>
</li>
<li>
<a href="">河轮</a>
</li>
<li>
<a href="">保险</a>
</li>
<li>
<a href="">租车自驾</a>
</li>
<li class="b">
<a href="">深度旅游</a>
<p class="b1"></p>
</li>
<li>
<a href="">私人订制</a>
</li>
</ul>
</div>
</div>
</div>
<div class="log-area">
<div class="center-wrap">
<h1>暮云商城</h1>
<input type="text" placeholder="慕云游、酒店、机票、民宿">
<a class="iconfont" href=""></a>
</div>
</div>
</header>
</head>
</body>
</html>
在这里输入代码,可通过选择【代码语言】突出显示
3回答
同学你好,是指把下方代码修改为bottom和right吗?
如果是的话,那么此问题是和同学的另一个提问相同,已经做出解答了,链接:http://class.imooc.com/course/qadetail/261247,祝学习愉快~
好帮手慕言
2020-10-23
同学你好,可以在浏览器中按F12,鼠标选中类名为menu的元素,在右侧发现设置的样式没有生效,如下:
遇到这种情况,猜测是选择器写错了,可以打开css文件,发现少了一个点,添加上之后,再次查看就添加上了
遇到问题解决之后,同学可以把问题及解决方法整理一下,下次再遇到类似的问题,就知道如何排查了。祝学习愉快~
好帮手慕言
2020-10-23
同学你好,是少了一个点,添加上即可,代码参考:
相似问题