跨度标签red arrow
具有position: absolute
在右下角的预期。当我开始在content
容器中输入文本时,箭头开始飘走。
将content
高度设置为auto
或100%
没有解决问题。
red arrow
无论content
元素的高度如何,我们如何保持 span 标签固定在右下角?
https://codesandbox.io/s/gracious-shockley-dcp59?file=/src/App.js
HTML
<div className="App">
<div className="container">
<div className="content">
<div suppressContentEditableWarning={true} contentEditable="true">
Test
</div>
</div>
<span className="helper"></span>
</div>
<div className="container">
<div className="content">
<div suppressContentEditableWarning={true} contentEditable="true">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was
popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of
Lorem Ipsum.
</p>
</div>
</div>
<span className="helper"></span>
</div>
</div>
样式文件
.container {
overflow: auto;
border: 1px solid #000;
width: 150px;
height: 100px;
float: left;
transform: translate(0px, 10px);
margin-right: 20px;
}
.content {
padding: 15px;
background-color: #ddd;
}
.helper::before {
content: "";
position: absolute;
right: 3px;
bottom: 3px;
width: 5px;
height: 5px;
border-right: 4px solid red;
border-bottom: 4px solid red;
}
为了解决这个问题,我将滚动行为定义移动到.content
并分配position: relative;
给.container
.
.container {
position: relative; /* new */
overflow: hidden; /* changed */
border: 1px solid #000;
width: 150px;
height: 100px;
float: left;
transform: translate(0px, 10px);
margin-right: 20px;
}
.content {
padding: 15px;
background-color: #ddd;
width: inherit; /* new */
height: inherit; /* new */
box-sizing: border-box; /* new */
overflow-y: scroll; /* new */
}
.helper {
position: absolute;
right: 3px;
bottom: 3px;
width: 5px;
height: 5px;
border-right: 4px solid red;
border-bottom: 4px solid red;
}
<div class="App">
<div class="container">
<div class="content">
<div suppressContentEditableWarning={true} contentEditable="true">
Test
</div>
</div>
<span class="helper"></span>
</div>
<div class="container">
<div class="content">
<div suppressContentEditableWarning={true} contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<span class="helper"></span>
</div>
</div>
注意:我已更改className
为class
使代码片段起作用。我没有对 HTML 结构进行任何更改。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句