麻烦老师帮忙看下代码有无问题,有没有更简洁的写法建议
来源:2-17 自由编程
qq_慕工程8315848
2020-10-22 12:32:29
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
css/style.css
*{
margin: 0;
padding: 0;
}
ul,ol{
list-style: none;
}
a{
text-decoration: none;
}
/* header */
header{
width: 100%;
height: 80px;
background: #07cbc9;
}
header .header-top{
width: 1200px;
height: 80px;
margin: 0 auto;
position: relative;
}
header .header-top .logo{
float: left;
position: absolute;
top: 16px;
}
header .header-top nav{
float: right;
}
header .header-top nav ul li{
float: left;
font-size: 16px;
height: 80px;
line-height: 80px;
color: white;
margin-left: 20px;
}
.banner{
width: 100%;
height: 600px;
position: relative;
}
.banner img{
width: 100%;
height: 600px;
position: absolute;
}
.banner .content{
width: 100%;
height: 600px;
background: rgba(0, 0, 0, .5);
position: absolute;
}
.banner .content form{
width: 520px;
height: 400px;
position: absolute;
top: 100px;
left: 50%;
margin-left: -200px;
background: none;
}
.banner .content form p{
margin-bottom: 20px;
text-align: center;
}
.banner .content form input{
width: 504px;
height: 40px;
background: none;
border: 1px solid #888;
}
.banner .content form input.submit{
width: 200px;
}
.banner .content form textarea{
width: 504px;
height: 110px;
background: none;
border: 1px solid #888;
}
/* main */
main{
width: 1200px;
margin: 0 auto;
position: relative;
}
main .main-top{
margin-top: 30px;
}
main h3{
font-size: 32px;
text-align: center;
}
main .main-top .line{
width: 60px;
height: 3px;
background: #07cbc9;
margin: 10px auto;
}
main .main-top p{
text-align: center;
color: gray;
font-style: 14px;
}
main .about{
width: 1201px;
height: 464px;
}
main .about .left-concent{
float: left;
}
main .about .left-concent h3{
text-align: left;
margin: 30px 0;
}
main .about .left-concent .box{
width: 300px;
padding: 20px;
font-size: 18px;
border: 1px solid gray;
background: rgba(255, 255, 255, .5);
position: absolute;
z-index: 9;
}
main .about .left-concent .box p{
margin-bottom: 30px;
}
main .about .left-concent .box .btn{
width: 140px;
height: 40px;
background: #000;
color: white;
text-align: center;
line-height: 40px;
}
main .about img{
float: left;
width: 650px;
height: 435px;
position: absolute;
left: 50%;
margin-left: -325px;
bottom: 0;
}
main .about .right-content{
float: right;
}
main .about .right-content ul li{
width: 260px;
padding: 40px 0;
text-align: center;
margin: 30px 0 0 20px;
border: 1px solid #07cbc9;
}
main .about .right-content ul li h4{
font-size: 28px;
}
main .about .right-content ul li .line{
width: 60px;
height: 3px;
background: #07cbc9;
margin: 10px auto;
}
.content {
width:100%;
margin: 0 auto;
}
.content ul{
overflow: hidden;
}
.content ul li{
width: 25%;
height: 380px;
float: left;
position: relative;
}
.content ul li .pic{
width: 636px;
height: 380px;
}
.content ul li.pic:nth-of-type(1) .triangle,.content ul li.pic:nth-of-type(3) .triangle{
width: 0px;
height: 0px;
border: 40px solid transparent;
border-right-color:#07cbc9 ;
position: absolute;
right:0;
top: 50%;
margin-top: -25px;
}
.content ul li.pic:nth-of-type(6) .triangle,.content ul li.pic:nth-of-type(8) .triangle{
width: 0px;
height: 0px;
border: 40px solid transparent;
border-left-color:#07cbc9 ;
position: absolute;
left:0;
top: 50%;
margin-top: -25px;
}
.content ul li.pic img{
width: 636px;
height: 380px;
}
.content ul li.text{
background: #07cbc9;
padding: 20px;
box-sizing: border-box;
}
.content ul li.text h3{
color: #fff;
font-size: 24px;
margin-bottom: 30px;
}
.content ul li.text .p1{
font-size: 16px;
margin-bottom: 20px;
}
.content ul li.text .p2{
font-size: 14px;
color: gray;
}
.content ul li.text button{
display: block;
width: 138px;
height: 40px;
background: #000;
margin: 30px auto;
color: white;
border: none;
}
.gallery .center{
width: 1200px;
margin: 30px auto;
overflow: hidden;
}
.gallery .center .center-top h3{
font-size: 32px;
text-align: center;
}
.gallery .center .center-top .line{
width: 60px;
height: 3px;
background: #07cbc9;
margin: 10px auto;
}
.gallery .center .center-top p{
text-align: center;
color: gray;
font-style: 14px;
}
.gallery .center .center-pic {
width: 1200px;
height: 533px;
}
.gallery .center .center-pic ul li{
float: left;
margin: 15px 20px;
}
.gallery .center .center-pic ul li img{
width: 360px;
height: 240px;
display: block;
}
.gallery .center .center-pic ul li .text{
width: 340px;
height: 50px;
background: #000;
color: white;
padding-left: 20px;
line-height: 50px;
}
footer .foot{
width: 100%;
height: 80px;
background: #07cbc9;
text-align: center;
line-height: 80px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="header-top">
<div class="logo"><img src="images/logo.png" alt=""></div>
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>GALLERY</li>
<li>FACULTY</li>
<li>EVENTS</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
</header>
<div class="banner">
<img src="images/banner3.jpg" alt="">
<!-- banner遮罩层 -->
<div class="content">
<!-- banner表单 -->
<form action="">
<p><input type="text" placeholder="YourName"></p>
<p><input type="password" placeholder="YourPhone"></p>
<p><input type="email" placeholder="YourEmial"></p>
<p><textarea name="" id="" cols="40" rows="6" placeholder="YourComment"></textarea></p>
<p> <input class="submit" type="submit" value="SEND MESSAGE"></p>
</form>
</div>
</div>
<main>
<div class="main-top">
<h3>ABOUT</h3>
<div class="line"></div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting
<br>industry. Lorem Ipsum has been the industry's standard dummy
<br>text ever since the 1500s.</p>
</div>
<div class="about">
<div class="left-concent">
<h3>A WORD
<br>ABOUT US</h3>
<div class="box">
<p>
Praesent dignissim viverra est, sed bibendum ligula congue non. Sed ac nisl et felis gravida commodo? Suspendisse eget ullamcorper ipsum. Suspendisse diam amet.
</p>
<div class="btn">EXPLORE</div>
</div>
</div>
<img src="images/bb3.jpg" alt="">
<div class="right-content">
<ul>
<li class="right-content-top">
<h4>70000</h3>
<div class="line"></div>
<p>Student</p>
</li>
<li class="right-content-bottom">
<h4>600</h3>
<div class="line"></div>
<p>Facyltyu</p>
</li>
</ul>
</div>
</div>
</main>
<div class="content">
<ul>
<li class="pic">
<img src="images/b1.jpg" alt="">
<div class="triangle"></div>
</li>
<li class="text">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
<p class="p2">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
<button>EXPLORE</button>
</li>
<li class="pic">
<img src="images/b2.jpg" alt="">
<div class="triangle"></div>
</li>
<li class="text">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
<p class="p2">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
<button>EXPLORE</button>
</li>
<li class="text">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
<p class="p2">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
<button>EXPLORE</button>
</li>
<li class="pic">
<img src="images/b3.jpg" alt="">
<div class="triangle"></div>
</li>
<li class="text">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
<p class="p2">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>
<button>EXPLORE</button>
</li>
<li class="pic">
<img src="images/b4.jpg" alt="">
<div class="triangle"></div>
</li>
</ul>
</div>
<div class="gallery">
<div class="center">
<div class="center-top">
<h3>GALLERY</h3>
<div class="line"></div>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting
<br>industry. Lorem Ipsum has been the industry's standard dummy
<br>text ever since the 1500s.
</p>
</div>
<div class="center-pic">
<ul>
<li>
<img src="images/03-01.jpg" alt="">
<div class="text">
Science Lab
</div>
</li>
<li>
<img src="images/03-02.jpg" alt="">
<div class="text">
Indoor Stadium
</div>
</li>
<li>
<img src="images/03-03.jpg" alt="">
<div class="text">
Transportation
</div>
</li>
<li>
<img src="images/03-04.jpg" alt="">
<div class="text">
Kids Room
</div>
</li>
<li>
<img src="images/03-05.jpg" alt="">
<div class="text">
Meditation Classes
</div>
</li>
<li>
<img src="images/03-06.jpg" alt="">
<div class="text">
Kids Play Ground
</div>
</li>
</ul>
</div>
</div>
</div>
<footer>
<div class="foot">
©2016 imooc.com 京ICP备13046642号
</div>
</footer>
</body>
</html>
1回答
同学你好,代码整体效果实现的很好,思路也很棒,有如下细节可以优化下:
logo已经设置定位了,就不需要再设置左浮动了,可以去掉浮动代码,简化代码书写。
可以使用background:transparent;设置背景颜色为透明,另外,样式相同的代码可以书写在一起,简化代码书写。
main设置了固定宽度后,可以.about盒子去掉宽度。由于.about盒子是块元素,默认会铺满父盒子
可以去掉about区域图片的绝对定位,使用margin属性调整间距,简化代码书写。
样式相同的代码书写在一起,简化代码书写。
祝学习愉快~
相似问题