css 元素相对定位,相对自己本身的位置定位

2 篇文章 0 订阅

元素在盒子内相对于自己本身的位置偏移.屡试不爽

<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%);
          }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值