HTML_CSS学习:定位

一、相对定位

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>相对定位</title><style>.outer{width: 500px;background-color: #999ff0;border: 1px solid #000;padding: 20px;}.box{width: 200px;height: 200px;font-size: 20px;}.box1{background-color: #ff0000;}.box2{background-color: #00ff00;/*position: relative;*//*left: 100px;*/}.box3{background-color: #0000ff;}</style>
</head>
<body><div class="outer"><div class="box box1">1</div><div class="box box2">2</div><div class="box box3">3</div></div></body>
</html>

显示结果:

二、绝对定位

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>绝对定位</title><style>.outer{width: 500px;background-color: #999ff0;border: 1px solid #000;padding: 20px;position: relative;}.box{width: 200px;height: 200px;font-size: 20px;}.box1{background-color: #ff0000;}.box2{background-color: #00ff00;position: absolute;top: 220px;left: 20px;/*transition: 1s all linear;*//*float: right;*//*top: 50px;*//*right: 50px;*//*right: -100px;*//*bottom: -50px;*//*margin-left: 50px;*//*margin-top: 50px;*//*margin-right: 3000px;*/}.box3{background-color: #0000ff;}.outer:hover .box2{left:220px}</style>
</head>
<body><div class="outer"><div class="box box1">1</div>
<!--        定位元素也能设置宽高--><div class="box box2">2</div><div class="box box3">3</div></div></body>
</html>

显示结果:

三、固定定位

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>固定定位</title><style>.outer{width: 500px;background-color: #999ff0;border: 1px solid #000;padding: 20px;position: relative;}.box{width: 200px;height: 200px;font-size: 20px;}.box1{background-color: #ff0000;}.box2{background-color: #00ff00;position: fixed;bottom:0;right:0;float: left;}.box3{background-color: #0000ff;}.outer:hover .box2{left:220px}</style>
</head>
<body><div class="outer"><div class="box box1">1</div>
<!--        定位元素也能设置宽高--><span class="box box2">heiheiehiehiehiei</span><div class="box box3">3</div></div><div>lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt tempora tempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt tempora tempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt tempora tempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt temporatempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt tempora tempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt temporatempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt tempora tempore tenetlorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam atque autem beatae blanditiis consectetur consequuntur cumque delectus doloribus eaque eius eligendi enim eum,excepturi expedita fuga harum hic illum incidunt iure iusto laboriosam laudantium libero magnam maiores mol,l molestiae mollitia nam nesciunt nihil nobis nostrum numquam obcaecatiodio officia omnis optio pariatur perferendis placeat quae quam quibusdam quidem quisquam quo repellat repudiandae rerum saepe sapientesequi similique sit soluta sunt temporatempore tenet</div></body>
</html>

显示结果:

四、粘性定位

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>粘性定位</title><style>*{margin: 0;padding: 0;}body{height: 2000px;}.page-header{height: 100px;text-align: center;line-height: 100px;background-color: #bfad39;font-size: 20px;}.item{background-color: silver;}.first{background-color: #0dcaf0;font-size: 40px;position: sticky;top: 0px;}</style>
</head>
<body>
<!--    头部--><div class="page-header">头部</div>
<!--    内容区--><div class="content">
<!--        每一项--><div class="item"><div class="first">A</div><h2>A1</h2><h2>A2</h2><h2>A3</h2><h2>A4</h2><h2>A5</h2><h2>A6</h2><h2>A7</h2><h2>A8</h2></div><div class="item"><div class="first">B</div><h2>B1</h2><h2>B2</h2><h2>B3</h2><h2>B4</h2><h2>B5</h2><h2>B6</h2><h2>B7</h2><h2>B8</h2></div><div class="item"><div class="first">C</div><h2>C1</h2><h2>C2</h2><h2>C3</h2><h2>C4</h2><h2>C5</h2><h2>C6</h2><h2>C7</h2><h2>C8</h2></div></div></body>
</html>

显示结果:

五、定位的层级

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>定位的层级</title><style>.outer{width: 500px;background-color: #999ff0;border: 1px solid #000;padding: 20px;position: relative;z-index: 2;}.box{width: 200px;height: 200px;font-size: 20px;}.box1{background-color: #ff0000;}.box2{background-color: #00ff00;position: relative;top: -150px;left: 50px;/*z-index:auto;*/}.box3{background-color: #0000ff;position: absolute;top: 130px;left: 130px;}.box4{background-color: #00ffb7;position: fixed;top: 200px;left: 200px;z-index: 50;}.box5{background-color: #ff00ff;position: fixed;top: 300px;left: 300px;z-index: 10;}</style>
</head>
<body><div class="outer"><div class="box box1">1</div><div class="box box2">2</div><div class="box box3">3</div><div class="box box4">4</div><div class="box box5">5</div></div></body>
</html>

显示结果:

六、定位可以越过padding

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>定位可以越过padding</title><style>.outer{width: 800px;height: 600px;padding: 20px;background-color: #999ff0;position: relative;}.inner{width: 200px;height: 200px;background-color: #ff0000;position: absolute;top: 0;left: 0;}</style>
</head>
<body><div class="outer"><div class="inner"></div></div></body>
</html>

显示结果:

七、定位的特殊应用1

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>定位的特殊应用</title><style>.outer{height: 400px;background-color: silver;position: relative;}.inner{background-color: yellow;font-size: 20px;padding: 20px;border: 10px solid #000;position: absolute;/*top:0;*/left: 0px;right:0px;top:0px;bottom:0px;/*width: 100%;*/}</style>
</head>
<body><div class="outer"><div class="inner">你好啊</div></div>
</body>
</html>

显示结果:

八、定位的特殊应用2

相关代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>定位的特殊应用</title><style>.outer{height: 400px;width: 800px;background-color: silver;/*overflow: hidden;*/position: relative;}.inner{width: 400px;height: 100px;background-color: yellow;font-size: 20px;/*nargin:0 auto;*//*margin-top: 150px;*/position: absolute;/*top:0;*//*bottom: 0;*//*left: 50%;*//*right: 50%;*//*top:50%;*//*margin-left: -200px;*//*margin: auto;*/top:0;bottom:0;left:0;margin: auto;}</style>
</head>
<body><div class="outer"><div class="inner">你好啊</div></div></body>
</html>

显示结果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/671424.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

文心一言 VS 讯飞星火 VS chatgpt (253)-- 算法导论18.2 6题

六、假设 B-TREE-SEARCH 的实现是在每个结点内采用二分查找&#xff0c;而不是线性查找。证明&#xff1a;无论怎样选择 t ( t 为 n 的函数)&#xff0c;这种实现所需的 CPU 时间都为 O(lgn)。如果要写代码&#xff0c;请用go语言。 文心一言&#xff1a; 首先&#xff0c;我…

什么是抖音橱窗?它和抖音小店有什么区别?普通人更适合做哪个?

大家好&#xff0c;我是电商糖果 相信有很多想在抖音卖货的朋友&#xff0c;都会搞不清抖音橱窗是什么&#xff1f; 甚至会把它和抖音小店当成一个项目&#xff0c;也不知道哪个更适合自己。 自己越了解发现越迷糊&#xff0c;有的说不需要直播&#xff0c;粉丝&#xff0c;…

pyside6的调色板QPalette的简单应用

使用调色板需要先导入:from PySide6.QtGui import QPalette 调色板QPalette的源代码&#xff1a; class QPalette(Shiboken.Object):class ColorGroup(enum.Enum):Active : QPalette.ColorGroup ... # 0x0Normal : QPalette.ColorGrou…

02 JavaSE--方法、对象及其三大特征

1. 方法 1.1 方法执行时的内存变化&#xff1a; 方法只定义不调用是不会分配内存的。只是方法的字节码指令存储在元空间中。方法在调用的瞬间&#xff0c;会给该方法分配内存空间&#xff0c;会在栈中发生压栈动作。每个方法都会有自己的空间&#xff0c;这个空间称为栈帧栈帧…

leetCode78. 子集

leetCode78. 子集 思路一&#xff1a;迭代法 代码 class Solution { public:vector<vector<int>> subsets(vector<int>& nums) {vector<vector<int>> res;int n nums.size();for(int i 0; i < 1 << n; i) // 1 << n 2^n{…

云仓酒庄携手央视共筑品牌新高度,酒类行业广告战略迈向新征程

随着酒类市场的日益繁荣与竞争的加剧&#xff0c;品牌宣传与推广在酒类行业中的地位愈发凸显。近日&#xff0c;云仓酒庄宣布与中视中州&#xff08;央视代理机构&#xff09;达成2024-2025年度央视广告战略合作&#xff0c;云仓酒庄副总裁周玄代表云仓酒庄签约&#xff0c;这一…

Al加码,引爆“躺平式”旅游 | 最新快讯

旅游业正迎来新的技术浪潮。 文&#xff5c;锌刻度&#xff0c;作者&#xff5c;孟会缘&#xff0c;编辑&#xff5c;李季 今年的五一&#xff0c;“微度假”“微旅行”纷纷出圈。 相较于三亚、云南等老牌旅游大热门&#xff0c;人们开始寻找一些不用“人挤人”的小众旅行目的…

Case中default的综合结果

在使用case语句时&#xff0c;不完备的case语句会导致Vivado综合时推断出锁存器。下面通过实例来详细看看各种情况下的综合结果&#xff1a; 1.完备的case语句 下述的verilog对应的电路结构是一个8选一的多路复用器&#xff1a; module case_test(input [2:0]sel,input data…

U盘提示“被写保护”无法操作处理怎么办?

今天在使用U盘复制拷贝文件时&#xff0c;U盘出现“U盘被写保护”提示&#xff0c;导致U盘明明有空闲内存却无法复制的情况。这种情况很常见&#xff0c;很多人在插入U盘到电脑后&#xff0c;会出现"U盘被写保护"的提示&#xff0c;导致无法进行删除、保存、复制等操…

【大模型应用篇7】新一代程序员需要掌握的智能体脚手架是?

大模型让智能体成为更多可能性&#xff0c; 很多公司开始押注下一轮应用形式&#xff0c;其中包括OpenAI、字节、科大讯飞、百度等公司都押注了智能体这个方向。其实&#xff0c;学习大模型到现在&#xff0c;个人也在一直想&#xff0c;大模型未来应用场景方向有哪些&#xff…

2002-2021年各地区平均受教育年限数据(分性别)(含原始数据+计算过程+计算结果)

2002-2021年各地区平均受教育年限数据&#xff08;分性别&#xff09;&#xff08;含原始数据计算过程计算结果&#xff09; 1、时间&#xff1a;2002-2021年 2、来源&#xff1a;国家统计局、统计年鉴、各省年鉴 3、指标&#xff1a;行政区划代码、地区、年份、人均受教育年…

PyTorch深度学习框架:从入门到实战

前言 学习 PyTorch 深度学习框架之前先学会深度学习和卷积神经网络 CNN &#xff0c;这样学习起来会更香嗷。 Windows系统下PyTorch的环境配置 Anaconda是什么&#xff1a; Anaconda是一个开源的Python发行版本&#xff0c;专注于数据分析领域。它包含了conda、Python等190多…