html - css绝对定位问题
本文介绍了html - css绝对定位问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<style type="text/css">
header {
position: relative;
border: 1px solid #e3e3e3;
width: 300px;
}
header .time {
position: absolute;
bottom: 0;
left: 0;
background-color: #f6f6f6;
width: 100%;
padding: 5px;
}
</style>
</head>
<body>
<header>
<div class="title">
<h1>哒哒哒</h1>
</div>
<div class="time">
<time>2016/02/05</time>
</div>
<div class="content">
<p>哈哈哈哈</p>
</div>
</hedaer>
</body>
</html>
以上图片是代码在浏览器浏览的结果。
图片中有两个问题:
一、在.time中加入padding后,宽度会大于100%,背景颜色超出。
二、.time使用绝对定位到header的底部,但是会遮住.content的内容。
以上代码参考:Theme Preview
参考红框圈起来那。
请问这两个问题该如何解决?谢谢!
解决方案
第一个问题,可以设box-size:border-box;第二个问题,position脱离文档流当然会遮住。这个地方给父容器设padding-bottom
这篇关于html - css绝对定位问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文