CSS-小技巧-持续更新

本文介绍了CSS的一些实用技巧,包括禁止文字选中、使用背景和背景大小创建边框、背景图片设置、毛玻璃效果实现,以及利用伪元素绘制图形。同时,通过Less预处理器展示了如何提取公共样式,如画圆和三角形,以及实现文字两侧横线。这些技巧和方法有助于提升前端开发效率和页面样式美化。
摘要由CSDN通过智能技术生成

1、js css禁止多次点击选中文字
  • js方法
    <div onselectstart="return false;" >屏蔽双击选中文字的区域</div>
    
  • css方法
    <div style="-webkit-user-select:none;-moz-user-select:none;-o-user-select:none;user-select:none;" >
    屏蔽双击选中文字的区域
    </div>
    
2. 利用background 和 background-size 画边框
  background: linear-gradient(to left, #3686fe, #3686fe) left top no-repeat,
  linear-gradient(to bottom, #3686fe, #3686fe) left top no-repeat,
  linear-gradient(to left, #3686fe, #3686fe) right top no-repeat,
  linear-gradient(to bottom, #3686fe, #3686fe) right top no-repeat,
  linear-gradient(to left, #3686fe, #3686fe) left bottom no-repeat,
  linear-gradient(to bottom, #3686fe, #3686fe) left bottom no-repeat,
  linear-gradient(to left, #3686fe, #3686fe) right bottom no-repeat,
  linear-gradient(to left, #3686fe, #3686fe) right bottom no-repeat;
  background-size: 1px 10px, 10px 1px, 1px 10px, 10px 1px;
3. 设置背景
  background: url("../../../assets/images/resource-modal-border.png") no-repeat;
  background-size: 100% 100%;
4. 背景毛玻璃化
  backdrop-filter: blur(10px);
5. 利用伪元素
  • 利用伪元素画圆
      .stat-detail {
        &:before {
           content: "";
           display: block;
           width: 170px;
           height: 170px;
           background-color: transparent;
           position: absolute;
           left: 172px;
           border-radius: 100%;
           border: 6px solid #182640;
         }
      }
    
  • 利用伪元素画三角形 + 定位
      .item {
         position: relative;
         &:before {
          content: "";
          display: block;
          width: 0;
          height: 0;
          border-width: 3px 3px 0;
          border-style: solid;
          border-color: #6C8097 transparent transparent;
          transform: rotate(135deg);
          position: absolute;
          left: -1px;
          top: 0;
      }
    }
    
6. 公共样式提取
  • less 公共样式提取

      .square(@color) {
        content: "";
        display: block;
        width: 10px;
        height: 10px;
        position: absolute;
        left: -15px;
        top: 5px;
        background-color: @color;
      }
      .three:before {
        .square(#A7911D);
      }
    
  • sass 公共样式提取

      @mixin triangle($f){
        width: 0;
        height: 0;
        border-width: 10px 10px 0;
        border-style: solid;
        border-color: $f transparent transparent;
      }
      @include triangle(#F00)
    
7. 文字两边横线 less
    .welcome-word {
      position: relative;
      font-size: 20px;
      color: #7d7d7d;
      letter-spacing: 4px;
      margin-top: 30px;
      display: flex;
      flex-direction: row;
      justify-content: center;
      &:before {
        content: "";
        display: block;
        width: 40px;
        height: 0;
        border: 1px solid #ccc;
        position: absolute;
        left: 22%;
        top: 50%;
      }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值