麻烦老师帮忙看下代码有无问题,有没有更简洁的写法建议

来源:2-17 自由编程

qq_慕工程8315848

2020-10-22 12:32:29

# 具体遇到的问题

# 报错信息的截图

# 相关课程内容截图

# 尝试过的解决思路和结果

# 粘贴全部相关代码,切记添加代码注释(请勿截图)

css/style.css

*{

    margin0;

    padding0;

}

ul,ol{

    list-stylenone;

}

a{

    text-decorationnone;

}

/* header */

header{

    width100%;

    height80px;

    background#07cbc9;

}

header .header-top{

    width1200px;

    height80px;

    margin0 auto;

    positionrelative;

}

header .header-top .logo{

    floatleft;

    positionabsolute;

    top16px;

}

header .header-top nav{

    floatright;

}

header .header-top nav ul li{

    floatleft;

    font-size16px;

    height80px;

    line-height80px;

    colorwhite;

    margin-left20px;

}

.banner{

    width100%;

    height600px;

    positionrelative;

}

.banner img{

    width100%;

    height600px;

    positionabsolute;

}

.banner .content{

    width100%;

    height600px;

    backgroundrgba(000.5);

    positionabsolute;

}

.banner .content form{

    width520px;

    height400px;

    positionabsolute;

    top100px;

    left50%;

    margin-left-200px;

    backgroundnone;

}

.banner .content form p{

    margin-bottom20px;

    text-aligncenter;

}

.banner .content form input{

    width504px;

    height40px;

    backgroundnone;

    border1px solid #888;

}

.banner .content form input.submit{

    width200px;


}

.banner .content form textarea{

    width504px;

    height110px;

    backgroundnone;

    border1px solid #888;

}


/* main */

main{

    width1200px;

    margin0 auto;

    positionrelative;

}

main .main-top{

    margin-top30px;

}

main  h3{

    font-size32px;

    text-aligncenter;

}

main .main-top .line{

    width60px;

    height3px;

    background#07cbc9;

    margin10px auto;


}

main .main-top p{

    text-aligncenter;

    colorgray;

    font-style14px;

}

main .about{

    width1201px;

    height464px;

}

main .about .left-concent{

    floatleft;


}

main .about .left-concent h3{

    text-alignleft;

    margin30px 0;

}

main .about .left-concent .box{

    width300px;

    padding20px;

    font-size18px;

    border1px solid gray;

    backgroundrgba(255255255.5);

    positionabsolute;

    z-index9;

}

main .about .left-concent .box p{

    margin-bottom30px;

}

main .about .left-concent .box .btn{

    width140px;

    height40px;

    background#000;

    colorwhite;

    text-aligncenter;

    line-height40px;

}

main .about img{

    floatleft;

    width650px;

    height435px;

    positionabsolute;

    left50%;

    margin-left-325px;

    bottom0;


}

main .about .right-content{

    floatright;


}

main .about .right-content ul li{

    width260px;

    padding40px 0;

    text-aligncenter;

    margin30px 0 0 20px;

    border1px solid #07cbc9;

}

main .about .right-content ul li h4{

    font-size28px;

}

main .about .right-content ul li .line{

    width60px;

    height3px;

    background#07cbc9;

    margin10px auto;

}

.content {

    width:100%;

    margin0 auto;

    

}

.content ul{

    overflowhidden;

}

.content ul li{

    width25%;

    height380px;

    floatleft;

    positionrelative;

}

.content ul li .pic{

    width636px;

    height380px;

    

}

.content ul li.pic:nth-of-type(1.triangle,.content ul li.pic:nth-of-type(3.triangle{

    width0px;

    height0px;

    border40px solid transparent;

    border-right-color:#07cbc9 ;

    positionabsolute;

    right:0;

    top50%;

    margin-top-25px;

}

.content ul li.pic:nth-of-type(6.triangle,.content ul li.pic:nth-of-type(8.triangle{

    width0px;

    height0px;

    border40px solid transparent;

    border-left-color:#07cbc9 ;

    positionabsolute;

    left:0;

    top50%;

    margin-top-25px;

}

.content ul li.pic img{

    width636px;

    height380px;

}

.content ul li.text{

    background#07cbc9;

    padding20px;

    box-sizingborder-box;

}

.content ul li.text h3{

    color#fff;

    font-size24px;

    margin-bottom30px;

}

.content ul li.text .p1{

    font-size16px;

    margin-bottom20px;

}

.content ul li.text .p2{

    font-size14px;

    colorgray;

}

.content ul li.text button{

    displayblock;

    width138px;

    height40px;

    background#000;

    margin30px auto;

    colorwhite;

    bordernone;

}

.gallery .center{

    width1200px;

    margin30px auto;

    overflowhidden;

}

.gallery .center .center-top h3{

    font-size32px;

    text-aligncenter;

}

.gallery .center .center-top .line{

    width60px;

    height3px;

    background#07cbc9;

    margin10px auto;

}

.gallery .center .center-top p{

    text-aligncenter;

    colorgray;

    font-style14px;

}

.gallery .center .center-pic {

    width1200px;

    height533px;

}

.gallery .center .center-pic ul li{

    floatleft;

    margin15px 20px;

}

.gallery .center .center-pic ul li img{

    width360px;

    height240px;

    displayblock;

}

.gallery .center .center-pic ul li .text{

    width340px;

    height50px;

    background#000;

    colorwhite;

    padding-left20px;

    line-height50px;

}

footer .foot{

    width100%;

    height80px;

    background#07cbc9;

    text-aligncenter;

    line-height80px;

}




<!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">

            &copy;2016 imooc.com 京ICP备13046642号

        </div>

    </footer>

</body>

</html>


写回答

1回答

好帮手慕慕子

2020-10-22

同学你好,代码整体效果实现的很好,思路也很棒,有如下细节可以优化下:

  1. logo已经设置定位了,就不需要再设置左浮动了,可以去掉浮动代码,简化代码书写。

    http://img.mukewang.com/climg/5f9122f50955279605680187.jpg

  2. 可以使用background:transparent;设置背景颜色为透明,另外,样式相同的代码可以书写在一起,简化代码书写。

    http://img.mukewang.com/climg/5f9123ab0910add006990808.jpg

  3. main设置了固定宽度后,可以.about盒子去掉宽度。由于.about盒子是块元素,默认会铺满父盒子

    http://img.mukewang.com/climg/5f91256709b8071005400181.jpg

  4. 可以去掉about区域图片的绝对定位,使用margin属性调整间距,简化代码书写。

    http://img.mukewang.com/climg/5f9125e409dc5d1805010375.jpg

  5. 样式相同的代码书写在一起,简化代码书写。

    http://img.mukewang.com/climg/5f912654091ea79f06240712.jpg

祝学习愉快~

0

0 学习 · 15276 问题

查看课程