LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

【HTML】解决痛点的那些CSS

admin
2024年4月28日 21:56 本文热度 68

在写一些页面时,有些东西老是感觉能解决但就是想不起来具体怎么写,本文记录一些容易忘但很实用的css属性。

正文

01- video隐藏控件

有时候页面上的video视频可能需要显示默认的进度条音量等控件

/* 隐藏video 进度条 */
  video::-webkit-media-controls-timeline {
    display: none;
  }

  /* 隐藏video 观看的当前时间 */
  video::-webkit-media-controls-current-time-display {
    display: none;
  }

  /* 隐藏video 剩余时间 */
  video::-webkit-media-controls-time-remaining-display {
    display: none;
  }

  /* 隐藏video 音量按钮 */
  video::-webkit-media-controls-mute-button {
    display: none;
  }

  video::-webkit-media-controls-toggle-closed-captions-button {
    display: none;
  }

  /* 隐藏video 音量的控制条 */
  video::-webkit-media-controls-volume-slider {
    display: none;
  }

  /* 隐藏video 所有控件 */
  video::-webkit-media-controls-enclosure {
    display: none;
  }

02- 自定义鼠标光标

把默认的箭头改成自己喜欢的图片

首先需要把图片转换为.ico格式,这里有一个在线转换的网址

https://convertio.co/zh/png-ico/

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      body {
        min-height100vh;
        cursorurl("./img/happy.ico"34 34, pointer;
      }
    </style>
  </head>
  <body>

  </body>
</html>

03- 横向滑动

页面中横向滑动实用的场景也不少

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .Box {
        backgroundrgb(220, 220, 220);
        width100%;
        overflow: hidden;
        overflow-x: auto;
        white-space: nowrap;
      }

      .item {
        display: inline-block;
        background#aaffff;
        margin10px;
        width120px;
        height100px;
      }
    </style>
  </head>
  <body>
    <div class="Box">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>

  </body>
</html>

04- border占位置

有时候使用border会出现挤压或挤出的情况,是因为border是占位置的,把它改成outline就行了。

outline1px solid #ccc;

05- 虚线效果

css默认的虚线边框太密集,可以使用以下方法解决

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .box {
        width500px;
        margin20% auto;
        padding5px;
        box-sizing: border-box;
        border1px dashed transparent;
        backgroundlinear-gradient(white, white) padding-box, repeating-linear-gradient(-45deg, #ccc 0, #ccc 5px, white 0, white 10px);
      }
    </style>
  </head>
  <body>

    <div class="box">
      解决虚线太密集解决虚线太密集
    </div>

  </body>
</html>

06- 自定义滚动条

css默认滚动条各个浏览器都不一样,而且不好看,以下方法可自定义滚动条

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      .box {
        width600px;
        height100px;
        outline1px solid;
        overflow-y: auto;
        padding5px;
        box-sizing: border-box;
      }
      
      .box::-webkit-scrollbar {
        /* 宽度 */
        width8px;
        background-color#ebedf0;
      }
      
      .box::-webkit-scrollbar-track{
        border-radius3px;
        background-color: transparent;
      }
      
      .box::-webkit-scrollbar-thumb{
        border-radius:5px;
        /* 滚动条的颜色 */
        background-color:#ff5500;
        border:2px solid #ebedf0;
      }
    </style>
  </head>
  <body>

    <div class="box">
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
      自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条自定义滚动条
    </div>

  </body>
</html>

07- 媒体元素显示不全

一个视频或者图片设置了宽高100%,但是还是显示不完整,就像这样,宽度并没有100%显示

给video元素添加一个属性就好了 object-fit: cover;

video{
  width100%;
  height100%;
  object-fit: cover;
}

08- 禁止文本选中

user-select: none; 这个属性就是禁止选中文本

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    p{
      user-select: none;
    }
  </style>
</head>
<body>
  <p>
    禁止文本的选中禁止文本的选中禁止文本的选中
  </p>
</body>
</html>

09- 另一种阴影drop-shadow

和box-shadow差别还是挺大的,可以试试

<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      .drop-shadow {
        filterdrop-shadow(2px 4px 8px #c7c7c7);
      }
    </style>
  </head>
  <body>
    <img class="drop-shadow" src="./img/p.png">
  </body>
</html>


该文章在 2024/4/28 21:56:15 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved