with 和 height 与绝对定位的关系?

落落叶叶无声 2021-02-04 12:24:09
为什么我设置了item2 的 right 和 bottom,以及 item2 的宽高,它就可以向上伸展,而不是基于right 和 bottom向下伸展?


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.box {
position: relative;
width: 300px;
height: 100px;
border: 10px solid red;
box-sizing: border-box;
}

.item2 {
position: absolute;
right: -10px;
bottom: -10px;
width: 0px;
height: 0px;
box-sizing: border-box;
border: 10px solid transparent;
}

.box:hover .item2 {

box-sizing: border-box;
width: 300px;
height: 100px;
border-color: black;
transition: all 1s;

}
</style>
</head>
<body>
<div class="box">
<div class="item2"></div>
</div>
</body>
</html>
...全文
414 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
item2 标签那里设置了绝对定位,此时标签是相对父标签进行定位,楼主设置了这个right和bottom值 此时位置正好在父标签的最右下端外侧 如果要实现向下伸展,只需设置这两个值即可 运行结果:
yhanw 2021-02-19
  • 打赏
  • 举报
回复
设置.item2的定位时,会使.item2具备一个宽高,这个宽高的优先级比width和height低
yhanw 2021-02-19
  • 打赏
  • 举报
回复
top:.item2的上边与.box上边的距离,从上往下为正;
right:.item2的右边与.box右边的距离,从右往左为正;
bottom:.item2的下边与.box下边的距离,从下往上为正;
left:.item2的左边与.box左边的距离,从左往右为正;
ZionHH 2021-02-05
  • 打赏
  • 举报
回复
字面意思,盒子定位(上右下左),top起点基于盒子上,right基于右,bottom基于下,left基于左
汇品铺子 2021-02-04
  • 打赏
  • 举报
回复
你可以理解为 你把item2定位在了右下角。 如果你希望他往下和往右延展,那么你就把它定位在左上角。

61,129

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧