老师,请帮忙看下,还有要优化的吗?

老师,请帮忙看下,还有要优化的吗?

http://img1.sycdn.imooc.com//climg/601e448a093eda1d13670933.jpg

相关代码:


<!DOCTYPE html>

<html lang="en">


<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        * {

            margin0;

            padding0;

        }


        .content .title {

            padding-top30px;

        }


        .content .title h1 {

            text-aligncenter;

        }


        .content .hg {

            width70px;

            height5px;

            background-color#07cbc9;

            margin0 auto;

            margin-top10px;

        }


        .content .wenzi {

            margin-top10px;

        }


        .content .wenzi p {

            text-aligncenter;

            colorgray;

            width510px;

            margin0 auto;

        }


        .content .main-content {

            width1160px;

            height613px;

            /* background-color: thistle; */

            margin0 auto;

            padding20px;

        }


        .content .main-content .top {

            width1160px;

            height290px;

            /* background-color: green; */


            margin-bottom30px;

        }


        .content .main-content .bottom {

            width1160px;

            height290px;

            /* background-color: greenyellow; */

        }



        .sam {

            floatleft;

            margin-right40px;

        }


        .block {

            displayblock;

        }


        .content .main-content .top .img-3,

        .content .main-content .bottom .img-6 {

            margin-right-40px;

        }


        .yangshi {

            height30px;

            background-colorblack;

            colorwhitesmoke;

            padding10px;

        }

    </style>

</head>


<body>

    <div class="content">

        <!-- 标题 -->

        <div class="title">

            <h1>GALLERY</h1>

        </div>


        <!-- 横杠 -->

        <div class="hg"></div>


        <!-- 文字 -->

        <div class="wenzi">

            <p>Lorem ipsum is simply dummy text of the printing and typesetting industry.Lorem ipsum has been the

                industry standard dummy text ever since the 1500s</p>

        </div>


        <!-- 主体内容 -->

        <div class="main-content">

            <!-- 上面的图文 -->

            <div class="top">

                <div class="img-1 sam">

                    <img class="block" src="/images_stars/03-01.jpg" alt="">

                    <p class="yangshi">Science Lab</p>

                </div>

                <div class="img-2 sam">

                    <img class="block" src="/images_stars/03-02.jpg" alt="">

                    <p class="yangshi">Indoor Stadium</p>

                </div>

                <div class="img-3 sam">

                    <img class="block" src="/images_stars/03-03.jpg" alt="">

                    <p class="yangshi">Transportation</p>

                </div>

            </div>

            <!-- 下面的图文 -->

            <div class="bottom">

                <div class="img-4 sam">

                    <img class="block" src="/images_stars/03-04.jpg" alt="">

                    <p class="yangshi">Science Lab</p>

                </div>

                <div class="img-5 sam">

                    <img class="block" src="/images_stars/03-05.jpg" alt="">

                    <p class="yangshi">Indoor Stadium</p>

                </div>

                <div class="img-6 sam">

                    <img class="block" src="/images_stars/03-06.jpg" alt="">

                    <p class="yangshi">Transportation</p>

                </div>


            </div>

        </div>

    </div>

</body>


</html>


正在回答

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

1回答

同学你好,代码中有如下问题可优化:

1、每排最后一个元素,只需要将右侧的边距设置为0即可,没必要设置负值,如下:

http://img1.sycdn.imooc.com//climg/601e4a5a09f7950006570208.jpg

2、整体布局可做如下优化:

6组图文的结构是一样的,实际开发中,会将6组内容放在一个父元素中,不用分成上下两部分,如下:

http://img1.sycdn.imooc.com//climg/601e4b1d09f33a3107090666.jpg

然后统一设置6组图文的样式即可:

http://img1.sycdn.imooc.com//climg/601e4bf5090b2b4406490455.jpg

http://img1.sycdn.imooc.com//climg/601e4c0909cf67f607280422.jpg

http://img1.sycdn.imooc.com//climg/601e4c5b095207af08440228.jpg

http://img1.sycdn.imooc.com//climg/601e4c7d09137b4406610245.jpg

结构上,多余的类名也可以删除:

http://img1.sycdn.imooc.com//climg/601e4ccc098e747405570271.jpg

3、路径建议不要写成“/”开头:

http://img1.sycdn.imooc.com//climg/601e4cf509e2fb0205880122.jpg

原因是“/”是相对于根路径来寻找图片的,“/images_stars/03-06.jpg”这个地址实际对应的路径是“http://127.0.0.1:5500/images_stars/03-06.jpg”(根路径是http://127.0.0.1:5500),如果老师的目录结构与同学的不一样,会造成找不到图片而报错,例如:

http://img1.sycdn.imooc.com//climg/601e4e7b0948018309840579.jpg

http://img1.sycdn.imooc.com//climg/601e4ecc0947c18019070648.jpg

所以建议改成相对路径,如下:

http://img1.sycdn.imooc.com//climg/601e4f2d0972756208240197.jpg

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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