只要不指定,所有标签均在标准流中定位。块级标签由于独占一行,所以从上到下排列,而行内和行内块级则水平排列。
一切标签皆是框
通过position属性,我们可以选择四种不同类型的定位
talk is less show code!
static就不写了relative
立即学习“前端免费学习笔记(深入)”;
<style> .left{ position: relative; left: -20px; } .right{ position: relative; left: 20px; background-color: blue; } .up{ position: relative; top: -20px; background-color: yellow; } .down{ position: relative; background-color: red; }</style><p>原始</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1712">
<img src="https://img.php.cn/upload/ai_manual/000/969/633/68b6d35694968678.png" alt="DeepBrain">
</a>
<div class="aritcle_card_info">
<a href="/ai/1712">DeepBrain</a>
<p>AI视频生成工具,ChatGPT +生成式视频AI =你可以制作伟大的视频!</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="DeepBrain">
<span>108</span>
</div>
</div>
<a href="/ai/1712" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="DeepBrain">
</a>
</div>
<p class="left">原始</p><p class="right">原始</p><p class="up">原始</p><p class="down">原始</p>
屏幕快照 2016-03-27 下午8.08.48.png
我们注意到,黄色的div由于设置了top: -20px,向上偏移了。但是关键的问题来了,接下的红色div仍是按照黄色div原先在文档流中的位置向下定位的,我们将top: -20px;的代码注释掉,结果如下
屏幕快照 2016-03-27 下午8.08.18.png
这就是relative中原本在正常文档流中所占空间仍保留的意思。
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号