老师好,麻烦帮忙检查下代码,谢谢~

老师好,麻烦帮忙检查下代码,谢谢~

老师好,以下是这道题的代码。我自己测试了一下效果还OK,麻烦老师帮忙看看还有哪些可以优化的地方好吗?谢谢!


相关代码:

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML页面练习</title>
    <link rel="stylesheet" href="css/css.css">
</head>
<body>
    <!-- 页面头部 -->
    <header>
        <div class="logo_nav">
            <!-- logo -->
            <div class="logo">
                <img src="images/logo.png" alt="">
            </div>
            <!-- 导航区域 -->
            <div class="nav">
                <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>
    </header>
    <!-- Banner -->
    <section class="banner">
        <!-- banner图片 -->
        <div class="banner_images">
            <img src="images/banner3.jpg" alt="">
        </div>
        <!-- banner遮罩层 -->
        <div class="banner_cover"></div>
        <!-- banner表单 -->
        <div class="banner_form">
            <form action="">
                <div class="enter_content">
                    <input type="text"  placeholder="your Name">
                    <input type="text"   placeholder="your Phone">
                    <input type="email"  placeholder="your Email">
                    <textarea cols="60" rows="5" placeholder="Write Your Comment Here"></textarea>
                </div>
                <div class="send_message">
                    <input type="submit" value="SEND MESSAGE">
                </div>
            </form>
        </div>
    </section>
    <!-- about区域 -->
    <section class="about_section">
        <!-- about上半部分 -->
        <div class="about_upper_section">
            <h2>ABOUT</h2>
            <p class="line"></p>
            <p class="para">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>
        <!-- about下半部分 -->
        <div class="about_lower_section">
            <!-- about下半部分左 -->
            <div class="about_lower_section_left">
                <h3>A WORD<br>
                ABOUT US</h3>
                <div class="para_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>
                    <button>EXPLORE</button>
                </div>
            </div>
            <!-- about下半部分中 -->
            <div class="about_lower_section_middle">
                <img src="images/bb3.jpg" alt="">
            </div>
            <!-- about下半部分右 -->
            <div class="about_lower_section_right">
                <div class="box1">
                    <p class="r1">70000</p>
                    <p class="line"></p>
                    <p class="r3">Students</p>
                </div>
                <div class="box2">
                    <p class="r1">600</p>
                    <p class="line"></p>
                    <p class="r3">Faculty</p>
                </div>
            </div>
        </div>
    </section>
    <!-- 图文混排区域 -->
    <section class="images&texts">
        <!-- 图片1 -->
        <div class="img_1">
            <img src="images/b1.jpg" alt="">
        </div>
        <!-- 文字2 -->
        <div class="tx_2">
            <h3>Library</h3>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
            <p>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>
            <p>EXPLORE</p>
        </div>
        <!-- 图片3 -->
        <div class="img_3">
            <img src="images/b2.jpg" alt="">
        </div>
        <!-- 文字4 -->
        <div class="tx_4">
            <h3>Library</h3>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
            <p>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>
            <p>EXPLORE</p>
        </div>
        <!-- 文字5 -->
        <div class="tx_5">
            <h3>Library</h3>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
            <p>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>
            <p>EXPLORE</p>
        </div>
        <!-- 图片6 -->
        <div class="img_6">
            <img src="images/b3.jpg" alt="">
        </div>
        <!-- 文字7 -->
        <div class="tx_7">
            <h3>Library</h3>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
            <p>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>
            <p>EXPLORE</p>
        </div>
        <!-- 图片8 -->
        <div class="img_8">
            <img src="images/b4.jpg" alt="">
        </div>
    </section>
    <!-- gallery区域 -->
    <section class="gallery_section">
        <!-- gallery上半部分 -->
        <div class="gallery_upper_section">
            <h2>Gallery</h2>
            <p>分割线</p>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting</p>
            <p>industry. Lorem Ipsum has been the industry's standard dummy</p>
            <p>text ever since the 1500s.</p>
        </div>
        <!-- gallery下半部分 -->
        <div class="gallery_lower_section">
            <dl>
                <dt>
                    <img src="images/03-01.jpg" alt="">
                </dt>
                <dd>Science Lab</dd>
                <dt>
                    <img src="images/03-02.jpg" alt="">
                </dt>
                <dd>Indoor Stadium</dd>
                <dt>
                    <img src="images/03-03.jpg" alt="">
                </dt>
                <dd>Transportation</dd>
                <dt>
                    <img src="images/03-04.jpg" alt="">
                </dt>
                <dd>Kids Room</dd>
                <dt>
                    <img src="images/03-05.jpg" alt="">
                </dt>
                <dd>Meditation Classes</dd>
                <dt>
                    <img src="images/03-06.jpg" alt="">
                </dt>
                <dd>Kids Play Ground</dd>
            </dl>
        </div>
    </section>
    <!-- 页脚 -->
    <footer>
        <p>&copy;&nbsp;2016&nbsp;imooc.com&nbsp;京ICP备13046642号</p>
    </footer>
</body>
</html>



CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* 以这个css为准 */
*{
    padding0;
    margin0;
}
ul,ol{
    list-stylenone;
}
a{
    text-decorationnone;
}
header{
    width100%;
    height80px;
    background-color#07cbc9;
}
header .logo_nav{
    width1200px;
    margin0 auto;
}
header .logo_nav .logo{
    floatleft;
    width260px;
    height48px;
    padding16px 0;
}
header .logo_nav .nav{
    floatright;
    width720px;
    height80px;
    margin-left160px;
    margin-right40px;
}
header .logo_nav .nav ul{
 
}
header .logo_nav .nav ul li{
    floatleft;
    width100px;
    height80px;
    margin-right20px;
}
header .logo_nav .nav ul li a{
    displayblock;
    width100px;
    height80px;
    colorwhite;
    font-size16px;
    text-aligncenter;
    line-height80px;
}
header .logo_nav .nav ul li a:hover{
    background-color: gold;
}
.banner{
    width100%;
    height600px;
    positionrelative;
}
.banner .banner_images img{
    width100%;
    height600px;
}
.banner .banner_cover{
    positionabsolute;
    left0;
    top0;
    width100%;
    height600px;
    background-color: rgba(0000.5);
}
.banner .banner_form form{
    positionabsolute;
    width506px;
    left50%;
    margin-left-252px;
    top100px;
}
.banner .banner_form form .enter_content input,textarea{
    displayblock;
    width504px;
    border1px solid #808080;
    backgroundnone;
    color#808080;
}
.banner .banner_form form .enter_content input{
    height40px;
    margin-bottom20px;
}
.banner .banner_form form .enter_content textarea{
    height110px;
}
.banner .banner_form form .send_message input{
    displayblock;
    width200px;
    height40px;
    border1px solid #808080;
    backgroundnone;
    margin20px auto;
    color#808080;
}
.about_section{
    width100%;
    margin-top30px;
}
.about_section .about_upper_section{
    margin-bottom30px;
}
.about_section .about_upper_section h2{
    font-size32px;
    text-aligncenter;
}
.about_section .about_upper_section .line{
    width60px;
    height3px;
    background-color#07cbc9;
    margin10px auto;
}
.about_section .about_upper_section .para{
    text-aligncenter;
    color: grey;
    font-size14px;
}
.about_section .about_lower_section{
    positionrelative;
    width1201px;
    height464px;
    margin0 auto;
}
.about_section .about_lower_section .about_lower_section_left{
    floatleft;
    background-color: azure;
}
.about_section .about_lower_section .about_lower_section_middle{
    width650px;
    height435px;
    margin0 auto;
    padding-top30px;
}
.about_section .about_lower_section .about_lower_section_right{
    positionabsolute;
    top30px;
    right0;
    floatright;
    width262px;
}
.about_section .about_lower_section .about_lower_section_left h3{
    positionabsolute;
    top40px;
    font-size25px;
}
.about_section .about_lower_section .about_lower_section_left .para_box{
    positionabsolute;
    left0;
    top50%;
    margin-top-93px;
    width300px;
    height186px;
    padding20px;
    font-size18px;
    border1px solid grey;
    background-color: rgba(2552552550.5);
}
.about_section .about_lower_section .about_lower_section_left .para_box button{
    width140px;
    height40px;
    background-color: rgba(0000.8);
    colorwhite;
    font-size20px;
    margin-top20px;
}
.about_section .about_lower_section .about_lower_section_right .box1,.box2{
    width260px;
    text-aligncenter;
    border1px solid #07cbc9;
    margin-bottom30px;
    padding40px 0;
    background-color#fff;
}
.about_section .about_lower_section .about_lower_section_right .r1{
    font-size28px;
    font-weightbold;
}
.about_section .about_lower_section .about_lower_section_right .line{
    width60px;
    height3px;
    background-color#07cbc9;
    margin10px auto;
}


测试效果截图:

https://img1.sycdn.imooc.com//climg/637f901d09d03bc019170788.jpg


about区域中间的图片部分我没有使用浮动,只是给左右两个部分分别使用了左浮和右浮,请问这样OK吗?


我记得课上老师说过使用浮动的话,盒子里面的所有元素都要浮动,所以一开始我是给中间图片部分设置了左浮动的。


但是设置浮动之后发现很难调整位置(调整至水平居中),不管用margin: 0 auto,还是绝对定位都不管用,所以试着去掉了浮动,去掉之后发现使用margin: 0 auto就可以水平居中了,所以就使用了这样的样式设置。


麻烦老师帮忙看一下代码和我的问题,非常感谢!

正在回答

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

1回答

同学你好,代码可做如下优化:

1、如下按钮有多余的边框(放大页面看的清楚):

https://img1.sycdn.imooc.com//climg/63801fc1090a658d07600235.jpg

另外,按钮的背景色应该是纯黑色。

综上调整一下:

https://img1.sycdn.imooc.com//climg/6380203f09df6c7b10440318.jpg

2、右侧文字区,使用定位就可以调整位置了,此时不需要设置浮动(浮动多余了):

https://img1.sycdn.imooc.com//climg/6380208a09e1ae1109480221.jpg

问题解答如下:

1、中间区域的样式是可以的。

2、浮动时,最常规的做法是“盒子元素最好全部浮动”。但是如果自己没法用这种写法实现效果,那么可以更换其他写法,毕竟代码的实现方式并不唯一。

3、让中间内容浮动后,就没法使用margin:0 auto;实现水平居中了,这是正常的。此时可以用margin-left属性移动中间区域的位置,只要视觉上觉得图片居中了就可以了,不用100%居中,灵活处理一下。

祝学习愉快!

  • 桐子酱Virginia 提问者 #1

    好的,谢谢老师的耐心检查和回答!已修改代码~

    2022-11-25 11:22:52
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

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

帮助反馈 APP下载

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

公众号

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

在线咨询

领取优惠

免费试听

领取大纲

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