本帖最后由 不二如是 于 2018-8-8 10:45 编辑
1、font元素,在H5中已经不推荐使用,如果需要设置字体大小样式,建议:
- font-weight: 400;
- font-size: 16px;
- font-family:"微软雅黑";
复制代码
并且h3元素已有默认大小,不建议当文本用,所以请用p元素。
2、关于垂直居中,请参看:
私家藏货之@垂直居中。
line-height方法适用于和父元素一样高(336px,而不是40px),例如:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- <style>
- #fishc{
- width: 500px;
- height: 500px;
- background: gray;
- }
- #fishc p{
- line-height: 500px;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <div id="fishc">
- <p>搜索趣图</p>
- </div>
- </body>
- </html>
复制代码
这才是line-height和盒子高度相同。
3、所以需要在添加一层div,用来放需要的40px:
- <div class="content">
- <div id="fishc">
- <p>搜索趣图</p>
- </div>
- </div>
复制代码
设置行高后,还需要margin需要反向移动
负的一半行高:
- .content{
- margin: 15px auto;
- height: 336px;
- width: 268px;
- border: 1px solid #D9E0EE;
- border-top: 3px solid #FF8400;
- }
- #fishc{
- margin: -20px 0;
- width: 100%;
- height: 40px;
- border-bottom: 1px solid #D9E0EE;
- }
- #fishc p{
- line-height: 40px;
- text-align: center;
- }
复制代码
源码(VIP免费):
index.zip
(452 Bytes, 下载次数: 1, 售价: 3 鱼币)