为什么.line变得那么大!!

为什么.line变得那么大!!

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Career buildert</title>
<style>
*{margin: 0;padding: 0;font-family: "微软雅黑";}
a{text-decoration: none;}

.nav{width: 100%;height: 80px;background-color: rgb(7,203,201);position: relative;}
.nav img{position: absolute;top:0;bottom: 0;left:20px;margin: auto 0;}
.navv{float: right;position: absolute;top: 0;bottom: 0;margin: auto 0;right: 0px;height:50px;width:50%;}
.navv ul{float: right;height: 50px;}
.navv ul li{list-style-type: none;float:left;font-weight: bold;line-height: 50px;margin: 0 9px;}
.navv ul li a:link{color: #fff;}
.navv ul li a:visited{color: #fff;}

.mess{width: 100%;height: 800px;position: relative;margin-bottom: 40px;}
.mess img{width: 100%;height: 800px;z-index: -1;}
.mess .black{width: 100%;height: 800px;background-color: #000;opacity: 0.5;position: absolute;top: 0;z-index: 1;}
/*chrome的opacity不识别百分比只识别小数点是什么鬼*/
.form{width: 33%;height: 500px;position: absolute;top: 0;bottom: 0;left:0;right:0;margin: auto auto;z-index: 999;}
.input{width: 623.984px;height: 40px;background-color: transparent;border: 2px solid rgb(128,128,128);margin: 20px auto;color:#fff;}
.bigInput{width: 623.984px;height: 170px;background-color: transparent;border: 2px solid rgb(128,128,128);color:#fff;line-height: 40px;margin-bottom: 20px; }
.button{width: 120px;height: 40px;background-color: transparent;border: 2px solid rgb(128,128,128); font-weight: bold;color:#fff;display: block;margin: 0 auto;}

.md{width:100%;height:1500px;position: relative;}
.about{width: 100%;height:500px;position:relative;}
.bo{width:100%;height: 30px;margin: 20px auto;text-align: center;font-size: 1.3em;font-weight: bold;}
.line{width: 30px;height: 2px;background-color: rgb(7,203,201);margin: 0 auto;}
.about div{width: 500px;height: 40px;margin: 0 auto;}
</style>
</head>
<body>
<div class="head">
<div class="nav">
<img src="logo.png">
<div class="navv">
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT</a></li>
<li><a href="#">GALLERY</a></li>
<li><a href="#">FACULTY</a></li>
<li><a href="#">EVENTS</a></li>
<li><a href="#">CONTACT</a></li>
</ul>
</div>
</div>
<div class="mess">
<img src="banner3.jpg">
<div class="black"></div>
<div class="form">
<input type="text" name="yourName" id="yourName" value="&nbsp;&nbsp;your Name" class="input">
<input type="text" name="yourPhone" id="yourPhone" value="&nbsp;&nbsp;your Phone" class="input">
<input type="text" name="yourEmail" id="yourEmail" value="&nbsp;&nbsp;your Email" class="input">
<!--  <input type="text" name="comment" id="comment" value="&nbsp;&nbsp;Write Your Comment Here" class="bigInput"> -->
<textarea name="comment" id="comment" cols="30" rows="10" class="bigInput">&nbsp;&nbsp;Write Your Comment Here</textarea>
<input type="submit" value="SEND MESSAGE" class="button">
</div>
</div>
</div>
<div class="md">
<div class="about">
<div class="bo">ABOUT</div>
<div class="line"></div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </div>
</div>
<div class="squa"></div>
<div class="gall"></div>
</div>
<div class="foot"></div>

</body>
</html>

麻烦老师看一下,我明明设置了.line的宽和高,结果在浏览器里一打开变得特别大,这是什么情况啊

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

因为优先级的问题:

  1.   .about div{}优先级高于.line {}优先级,所以 div 使用的是width: 500px;  height: 40px;

  2.  将.line 的优先级提升,如下:

  .about div.line {
        width: 30px;
        height: 2px;
        background-color: rgb(7, 203, 201);
        margin: 0 auto;       
    }

希望对你有帮助,动手实践,加油。

  • 秦鲸卿 提问者 #1
    感谢!问题解决了
    2018-01-16 17:33:46
  • 秦鲸卿 提问者 #2
    hello,还有一个问题,按老师的说法修改之后, .bo{width:100%;height: 30px;margin: 20px auto;text-align: center;font-size: 1.3em;font-weight: bold;} .about div.line{width: 30px;height: 2px;background-color: rgb(7,203,201);margin: 0 auto;} .about div{width: 500px;height: 40px;margin: 10px auto;} 这里面我把第三项的上下margin设为零的时候,.bo(第一项)的上下margin也变成0了,这是为什么呢?把.about div上下margin设为10px的时候,.bo的上下mergin又出现了
    2018-01-16 17:57:32
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师