用font-size 为0 不能居中 最后一行

用font-size 为0 不能居中 最后一行

1
<br>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>BEM模式开发</title>

<link rel="stylesheet" type="text/css" href="css/index.css">

</head>

<body>

<header class="header">

<div class="logo"></div>

<nav class="nav">

<a href="" class="nav__item">课程</a>

<a href="" class="nav__item nav__item_icon_new">职业路径</a>

<a href="" class="nav__item">实战</a>

<a href="" class="nav__item">猿问</a>

<a href="" class="nav__item">手记</a>

</nav>

<div class="profile">

<a href="" class="profile__item profile__phone"></a>

<a href="" class="profile__item profile__message"></a>

<a href="" class="profile__item profile__mail"></a>

<a href="" class="profile__item profile__ava"></a>

</div>

<div class="search"><input type="text" class="search__input"><a href="" class="search__submit"></a></div>

</header>


<section class="web-main">

<div class="banner"></div>


<div class="wrap">

    <div class="inner_tr">

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course1.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">前端小白入门系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course2.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">HTML5与CSS3实现动态网页系列课程</div>

<div class="wrap-item__desc">24课 1031人在学</div>

<div class="wrap-item__price"><i>¥</i>498.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course3.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">ECShop3从基本使用到二次开发系列课程</div>

<div class="wrap-item__desc">11课 7人在学</div>

<div class="wrap-item__price"><i>¥</i>298.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course4.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">零基础入门Android语法与界面系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

           </div>

           <div class="inner_tr">

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course5.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">Android网络与数据存储系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course6.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">Android从界面到数据存储系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course7.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">Java基础语法与常用工具类系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course8.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">前端小白入门系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

</div>

            <div class="inner_tr">

<a href="javascript:void(0)" class="wrap-item">

<div class="wrap-item__cover"><img src="img/course9.jpg" alt=""></div>

<div class="wrap-item__text">

<div class="wrap-item__tit">iOS基础语法(OC&Swift)与常用控件系列课程</div>

<div class="wrap-item__desc">33课 366人在学</div>

<div class="wrap-item__price"><i>¥</i>699.00</div>

</div>

</a>

</div>

</div>


<!-- div.wrap>(a[href="javascript:void(0)"].wrap-item>div.-cover>img[src=img/course$.jpg]^div.-text>.tit{前端小白入门系列课程}+.desc{33课 366人在学}+div.-price{699.00})*9|bem -->

</section>



 


</body>

</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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
body {
  padding0;
  margin0;
}
a {
  text-decorationnone;
}
.header {
  width100%;
  height60px;
  line-height60px;
  background-color#000;
}
.header .logo {
  floatleft;
  height38px;
  width128px;
  backgroundurl("../img/logo.png"no-repeat top center;
  margin11px 25px;
}
.header .nav {
  floatleft;
}
.header .nav__item {
  displayblock;
  floatleft;
  height60px;
  line-height60px;
  padding0 25px;
  color#fbfbfb;
  font-size14px;
}
.header .nav__item:hover {
  background-color#363c41;
}
.header .nav__item_icon_new {
  background-color#363c41;
}
.header .nav__item_icon_new:after {
  positionabsolute;
  display: inline-block;
  content' ';
  top6px;
  width16px;
  height16px;
  backgroundurl("../img/icon-new.png"no-repeat top center;
}
.header .profile {
  floatright;
}
.header .profile__item {
  displayblock;
  positionrelative;
  floatleft;
  width60px;
  height60px;
}
.header .profile__item:hover {
  background-color#ccc;
}
.header .profile__phone:before {
  displayblock;
  content" ";
  width22px;
  height22px;
  backgroundurl("../img/icon-1-sprite_w22.png"no-repeat top center;
  positionabsolute;
  top19px;
  left19px;
  background-position0 -22px;
}
.header .profile__message:before {
  displayblock;
  content" ";
  width22px;
  height22px;
  backgroundurl("../img/icon-1-sprite_w22.png"no-repeat top center;
  positionabsolute;
  top19px;
  left19px;
  background-position0 -44px;
}
.header .profile__mail:before {
  displayblock;
  content" ";
  width22px;
  height22px;
  backgroundurl("../img/icon-1-sprite_w22.png"no-repeat top center;
  positionabsolute;
  top19px;
  left19px;
  background-position0 -66px;
}
.header .profile__ava:after {
  displayblock;
  content" ";
  height36px;
  width36px;
  backgroundurl("../img/ava.jpg"no-repeat top center;
  background-size: cover;
  margin12px;
  border-radius: 50%;
}
.header .search {
  floatright;
  padding-right50px;
  positionrelative;
  height60px;
}
.header .search__input {
  width242px;
  bordernone;
  background-color#000;
  height36px;
  line-height36px;
  outlinenone;
  color#fbfbfb;
  border-bottom#ccc solid 1px;
}
.header .search:before {
  content'前端入门';
  displayblock;
  positionabsolute;
  width72px;
  height30px;
  line-height30px;
  text-aligncenter;
  top15px;
  background-color#ccc;
  color#5c646b;
  font-size12px;
}
.header .search__submit {
  display: inline-block;
  positionabsolute;
  background-position0 0;
  width22px;
  height22px;
  top20px;
  right50px;
  backgroundurl("../img/icon-1-sprite_w22.png"no-repeat top center;
}
.web-main {
  height1610px;
  width100%;
}
.web-main .banner {
  height560px;
  backgroundurl("../img/bg.jpg"no-repeat top center;
}
.web-main .wrap {
  height1050px;
  width1207px;
  margin0 auto;
  overflowhidden;
  padding-left3px;
  positionrelative;
  top-150px;
}
.web-main .wrap .inner_tr:after {
  content" ";
  displayblock;
  clearboth;
  zoom: 1;
}
.web-main .wrap-item {
  positionrelative;
  display: inline-block;
  floatleft;
  height326px;
  width285px;
  margin-right20px;
  margin-bottom26px;
  background-color"#ccc";
  box-shadow: 3px 3px 8px rgba(717270.1), -3px 0px 8px rgba(717270.1);
  border-radius: 0 0 5px 5px;
}
.web-main .wrap-item:after {
  content' ';
  displayblock;
  width98%;
  left1%;
  bottom-4px;
  height3px;
  background-color#fff;
  positionabsolute;
  border-radius: 4px;
  box-shadow: 0 3px 12px rgba(717270.3);
}
.web-main .wrap-item__cover {
  height135px;
}
.web-main .wrap-item__cover img {
  displayblock;
  border-radius: 5px 5px 0 0;
  width100%;
}
.web-main .wrap-item__text {
  positionabsolute;
  top124px;
  width229px;
  height132px;
  background: rgba(2552552550.9);
  padding32px 28px;
}
.web-main .wrap-item__tit {
  font-size18px;
  font-weightbold;
  color#141914;
}
.web-main .wrap-item__desc {
  positionabsolute;
  top90px;
  font-size14px;
  color#5c646b;
}
.web-main .wrap-item__desc:after {
  content" ";
  displayblock;
  positionabsolute;
  top30px;
  height1px;
  width229px;
  background-color#ccc;
}
.web-main .wrap-item__price {
  positionabsolute;
  bottom20px;
  color#ff0000;
}
.web-main .wrap-item__price i {
  vertical-alignsuper;
  font-stylenormal;
}
.web-main .wrap-item:nth-child(4n) {
  margin-right0;
}


正在回答

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

1回答

同学你好,font-size属性是控制字体大小的,不能控制居中显示。

可以将最后一个设置为块元素,将浮动去掉,使用margin:0 auto;居中显示。参考:

http://img1.sycdn.imooc.com//climg/5c2dde6b0001d8d307460187.jpg

自己添加测试下,祝学习愉快!

  • 慕用9491247 提问者 #1
    好的 不过 有个同学答是 font-size 可以去掉 去除行内块的间距 没看到效果 这个可以 不过这样俩个的时候 不能自动居中 中间位置
    2019-01-03 18:46:20
  • 好帮手慕星星 回复 提问者 慕用9491247 #2
    font-size是去除掉display:inline-block;元素之间默认的间隙,但是每一个设置了浮动之后,就没有间隙了。上面两行使用浮动完成就可以,下面单独变成块居中显示。
    2019-01-03 19:02:58
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
HTML5&CSS3进阶与常用框架 2018
  • 参与学习       315    人
  • 提交作业       136    份
  • 解答问题       626    个

如果你有H5、CSS3、JS基础,热爱前端并希望在前端应用方面不断进步,那就来吧,本路径为你带来的课程有HTML5进阶、CSS3进阶、JS面向对象、jQ基础、Less等,助你进一步提升前端开发技能

了解课程
请稍等 ...
微信客服

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

帮助反馈 APP下载

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

公众号

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

在线咨询

领取优惠

免费试听

领取大纲

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