我正在尝试在div的所有4个面上添加元素。我不想使用box-sizing,因为我必须将事件侦听器应用于要放在所有4个面上的元素上。
我可以将其添加到左侧和右侧,但是如何在所有4个侧面添加它呢?而且这也不是一种优雅的方式。
.box {
width: 100px;
height: 100px;
background: yellow;
text-align: center;
font-size: 0.8rem;
position: relative;
}
#sideEl {
background-color: red;
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
height: 100%;
cursor: w-resize;
}
#sideEl2 {
background-color: red;
position: absolute;
right: 0;
bottom: 0;
width: 4px;
height: 100%;
cursor: w-resize;
}
<div class="box">
<div id="sideEl">
<div id="sideEl2">
</div>
我曾提到在div的每个角落放置4个html元素。但是不知道如何将它们沿着侧面边框放置
将另外两个添加div
并使用:
side
,将由div
充当边的s使用。此类包含如双方相互的风格background-color
和position
。另外两个类:
side-h
由水平的边(顶边和底边)使用。对于这些特定方面,它们具有width
和height
,因为它们确实具有相同的值。同样,这些边都有cursor: n-resize
垂直光标的规则。
side-v
由垂直的边(右侧和左侧)使用。对于这些特定方面,它们具有width
和height
,因为它们确实具有相同的值。而且,这些边都有cursor: w-resize
水平光标的规则。
在#side-top
与#side-left
持有相同的值top
和left
规则。
在#side-bottom
与#side-right
持有相同的值bottom
和left
规则。
.box {
width: 100px;
height: 100px;
background: yellow;
text-align: center;
font-size: 0.8rem;
position: relative;
}
.box .side {
position: absolute;
background-color: red;
}
.box .side.side-h {
width: 100%;
height: 4px;
cursor: n-resize;
}
.box .side.side-v {
width: 4px;
height: 100%;
cursor: w-resize;
}
#side-top, #side-left {
top: 0;
left: 0;
}
#side-right, #side-bottom {
bottom: 0;
right: 0;
}
<div class="box">
<div class="side side-h" id="side-top"></div>
<div class="side side-v" id="side-right"></div>
<div class="side side-h" id="side-bottom"></div>
<div class="side side-v" id="side-left"></div>
</div>
内部元素的顺序
.box
可以更改而不会影响最终结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句