为什么我能够在about-middle里用overflow清除浮动,但是在banner里不行?

来源:4-3 项目作业

Z_ZG

2020-05-15 06:29:29

*{
	padding: 0;
	margin:0;
	font-family: Microsoft YaHei UI;
}
.header{
	background-color: #07cbc9;
	width: 100%;
	overflow: hidden;
	height: 54px;
	position: fixed;
	top: 0px;
	z-index:500;
}
.header-menu{
	float: right;
	margin-right: 100px;
}
.header-menu ul li{
	float: left;
	list-style: none;
	padding:15px;
	text-align: center;
	/*background-color: black;*/
}
.header-menu ul li:hover{
	background-color: black;
}
.header-menu ul li a{
	text-decoration: none;
	color: white;
}
.header-logo{
	float: left;
	margin-left: 100px;
}
.banner{
	width:100%;
	margin-top: 54px;
	overflow: hidden;
}
.banner-mask{
	height: 800px;
	background-color: black;
	opacity: 0.4;
	z-index: 200;
	position: absolute;
	width: 100%;
	/*display: none;*/
}
.banner-img{
	z-index: 100;
	position: absolute;
	width:100%;
}
.banner-img img{
	width:100%;
	height: 800px;
	display: block;
}
.banner-form{
	position: absolute;
	z-index: 300;
	text-align: center;
	left: 50%;
	margin-left: -252px;
	top: 50%;
	margin-top: -142px;

}
.banner-form input{
	background-color: transparent;
	width: 500px;
	margin-bottom: 10px;
	padding: 5px;
}
.banner-form textarea{
	background-color:transparent;
	width: 500px;
	margin-bottom: 10px;
	padding:5px;
}
.banner-form button{
	background-color:transparent;
	color: white;
	padding:5px;
}
.banner-form input:hover{
	border-color: #07cbc9;
}
.banner-form textarea:hover{
	border-color: #07cbc9;
}
.banner-form button:hover{
	border-style: none;
	background-color: #07cbc9;
}
.about-top{
	text-align: center;
	width: 600px;
	margin: auto;
	font-size: 20px;
}
.about-top-line{
	background-color: #07cbc9;
	display: block;
	width: 40px;
	height: 2px;
	margin: 15px auto;
}
.about-middle{
	position: relative;
	overflow: hidden;
}
.about-middle-left{
	position: absolute;
	width: 400px;
}
.about-middle-right{
	position: absolute;
}
.about-middle-middle{
	float: left;
}
.clear{
	clear: both;
}
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" type="text/css" href="css/demo.css">
	<script type="text/javascript" src="js/demo.js"></script>
</head>
<body>
	<div class="header">
		<div class="header-logo">
			<a href="#"><img src="images/logo.png"></a>
		</div>
		<div class="header-menu">
			<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="banner">
		<div class="banner-mask">
		</div>
		<div class="banner-img">
			<img src="images/banner3.jpg">
		</div>
		<div class="banner-form">
			<form>
				<input type="text" name="" placeholder="your Name"><br>
				<input type="text" name="" placeholder="your Phone"><br>
				<input type="text" name="" placeholder="your Email"><br>
				<textarea placeholder="Write Your Comment Here" rows="5"></textarea><br>
				<button>SEND MESSAGE</button>
			</form>
		</div>
	</div>
	<div class="about">
		<div class="about-top">
			<h1>ABOUT</h1>
			<label class="about-top-line"></label>
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
		</div>
		<div class="about-middle">
			<div class="about-middle-left">
				<h4>A WORD ABOUT US</h4>
				<div class="about-middle-left-content">
					<p>Praesent dignissim viverra est,sed bibendum ligula congue non.Sed ac nislet felis gravida commodo?Suspendisse eget ullamcorpet ipsum.Suspendisse diam amet</p>
					<button>EXPLORE</button>
				</div>
			</div>
			<div class="about-middle-middle">
				<img src="images/bb3.jpg">
			</div>
			<div class="about-middle-right">
				<div class="about-middle-right-first">
					<p class="first">7000</p>
					<label class="about-middle-right-first-line"></label>
					<p class="second">Students</p>
				</div>
				<div class="about-middle-right-second">
					<p class="first">600</p>
					<label class="about-middle-right-second-line"></label>
					<p class="second">Faculty</p>
				</div>
			</div>
		</div>
		<div class="about-bottom"></div>
	</div>
	<div class="gallery">
		
	</div>
	<div class="footer">
		
	</div>
</body>
</html>


写回答

2回答

好帮手慕阿园

2020-05-15

同学你好,如果父标签中使用了overflow:hidden;时,子标签中元素的position设置成relative的时候,父元素的overflow对其是不起作用的,需要将父标签的position也设置成relative,所以同学在banner中加上:position: relative;就可以了

祝学习愉快

0

好帮手慕阿园

2020-05-15

同学你好,当父元素的高度是靠子元素撑开的时候,子元素浮动时,则在父元素使用overflow: hidden可以清除浮动,使得父元素的高度依旧是靠子元素撑开。而同学banner中的子元素中并没有浮动,所以就没有效果

祝学习愉快

0
h_ZG
h position:absolution应该也具有浮动效果,我对.banner-mask .banner-img .banner-form设置的都是absolution属性,这三个也是banner的子元素
h020-05-15
共1条回复

0 学习 · 9666 问题

查看课程