元素在盒子内相对于自己本身的位置偏移.屡试不爽
<div>
<span class="error_msg">密码输入错误</span>
<input type="text" class="input">
</div>
div{
position: relative;
.error_msg{
top: -1.3rem;
position: absolute;
}
}
多行数据 默认只展示一行,有展开按钮,点击之后可以查看到多行
<div class="layui-card layui-card-one">
<p style='height:30px;font-size:16px;font-weight: bold;'>{$talentPool.name}</p>
<div style='display:flex;height:30px;'>
<p style='width:33%;'><span style='color:#AAAAAA;'>创建时间:</span>15日</p>
<p style='width:33%;'><span style='color:#AAAAAA;'>现有人数:</span>54人</p>
<p style='width:33%;'><span style='color:#AAAAAA;'>人才库类型:</span>A型</p>
</div>
<div class="text">
<span style='color:#AAAAAA;'>描述:</span>
<span>一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题一大段问题</span>
</div>
<span class="expand">展开</span>
</div>
$('.expand').click(function(){
let item = $('.text');
item.toggleClass('switching_height');
if(item.hasClass('switching_height')){
$(this).text('收起');
}else{
$(this).text('展开');
}
})
.layui-card-one{
padding:15px;
position: relative;
overflow: hidden;
}
.expand{
position: absolute;
right:40px;
bottom: 10px;
}
.text{
white-space: nowrap;
overflow: hidden;
height: 20px;
text-overflow: ellipsis;
width:calc(100% - 90px);
}
.switching_height{
white-space: unset;
overflow: unset;
height: unset;
}
.text::after {
content: "...";
position: absolute;
right: 0;
bottom: 0;
}
子元素在父元素内完全居中
.inner {
position: relative;
border: 1px dashed black !important;
box-sizing: border-box;
background-clip: content-box;
i {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}