为什么我设置了line_height却不能垂直居中?

来源:3-10 企业网站制作之新闻中心制作(一)

qq_一支泊_0

2016-03-26 18:15

 <div class="news">

                <div class="title"><h2 class="title_left">新闻中心</h2><a href="news.html"><span classs="title_right">More&gt;&gt;</span></a></div><!--title结束-->                 

               <div class="pic_news">

                   <img src="images/news.jpg"/>

                   <h2>520慕女神喊你来表白!</h2>

                   <p>活动时间5月20日-5月25日<br/>获奖公布时间:5月26日<br/>Learn More>></p>

                </div><!--pic_news结束-->

.news

{

width:340px;

border:1px solid #e8e8e8;

}


.course

{

width:410px;

border:1px solid #e8e8e8;

margin:0 7px;

background-color:#393CCD;

}


.sidebar

{

width:230px;

background-color:#42B57E;

}


.news,.course,.sidebar

{

height:250px;

float:left;

}


.title

{

height:35px;

border-bottom:2px solid #e8e8e8;

}


.title_left

{

width:70%;

font-family:"微软雅黑";

font-size:14px;

font-weight:bold;

color:#786f66;

float:left;

line-height:35px;

padding-left:20px;

}


.title_right

{

width:20%;

float:left;

line-height:35px;

}


写回答 关注

3回答

  • berserk5683
    2016-03-27 10:19:50
    已采纳
    *{margin:0;padding: 0;}
    		
    	.news
    	{
    	width:340px;
    	border:1px solid #e8e8e8;
    	}
    
    	.course
    	{
    	width:410px;
    	border:1px solid #e8e8e8;
    	margin:0 7px;
    	background-color:#393CCD;
    	}
    
    	.sidebar
    	{
    	width:230px;
    	background-color:#42B57E;
    	}
    
    	.news,.course,.sidebar
    	{
    	height:250px;
    	float:left;
    	}
    
    	.title
    	{
    	height:35px;
    	border-bottom:2px solid #e8e8e8;
    	}
    
    	.title a{line-height: 37px;}
    
    	.title_left
    	{
    	width:70%;
    	font-family:"微软雅黑";
    	font-size:14px;
    	font-weight:bold;
    	color:#786f66;
    	float:left;
    	line-height:35px;
    	padding-left:20px;
    	}
    
    	.title_right
    	{
    	width:20%;
    	float:left;
    	}
    	
    	一开始把浏览器的margin和padding清除一下,然后你的title>a 标签是内联元素,给它设置ling-height
    	就行了。


    qq_一支泊...

    非常感谢!

    2016-03-28 15:18:32

    共 1 条回复 >

  • 慕瓜9991283
    2016-10-13 11:36:29

    太好了  谢谢回答 很给力

  • amily52000
    2016-06-04 08:10:52

    非常感谢!!我也是同样的问题,做在浏览器的第一个DIV总是对不齐,现在解决了

    qq_悠悠我...

    你好 你是怎么解决的呢 我一开始也*{margin:0 padding:0}了 但是还是那样

    2016-06-25 00:08:29

    共 1 条回复 >

企业网站综合布局实战

本课程重点介绍HTML/CSS实现常见企业网站布局的方法

157038 学习 · 2134 问题

查看课程

相似问题