为什么会自动的有个空白

图片描述

第一个p标签前边老是会有一块空白,而不是靠左的。

部分代码:<div class="heilan"> <div class="pic">PIC</div> <div class="blogname"> <p>Blogger Name</p> <h2>Blog Site Name</h2> </div> </div> <div class="blog"> <p><a href="">This will be The Blog Entry Title</a></p> <p>A short summary of the blog entry above.</p> </div>

                部分CSS:`#top-l .heilan{
margin-top:10px;
height:80px;
width:420px;
background: url(../images/pic-tit.png) no-repeat;

}

.pic,.blogname{
float: left;
color: #fff;
height:70px;
line-height: 0;
font-size: 20px;
}

.pic{
line-height: 24px;
margin:22px;
}

.blogname{
margin-left: 20px;
}

.blog{
width:420px;
}`

阅读 3.2k
5 个回答

没有清除浮动;
需要clear:both;

p标签有默认缩进的

内边距问题吗→_→

在Chrome调试中,蓝色部分是content大小,红色部分是margin大小。

可以看到<p>标签的内容确实是占领了整行的。所以设置<p>的行内对齐就好了:

cssp{
  text-align: left;
}

更多元素对齐的讨论可以参考:CSS Alignment:元素对齐问题

新手上路,请多包涵

.heilan {overflow:hidden;}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题