前台CSS样式使用小结

这篇博客记录了在Vue前端项目中使用CSS的一些关键知识点,包括定位、颜色、伪元素、优先级、CSS事件、选择器、li元素模仿表格、表格固定表头以及input样式等。还提及了在实现特定滚动效果时遇到的问题,并分享了vue相关的在线资源。
摘要由CSDN通过智能技术生成

最近做Vue前台相关的项目, 使用了一些前台CSS的知识, 作为笔记mark一下吧

1. 关于定位

**水平居中:** 
    文字(text-align: center;); 
    元素: (margin: 0px; auto)
**垂直居中:** 
    文字(line-height: 20px; height:20px;), 
    元素: (vertical-align: middle/sub;)
    于父元素定位: 父元素 (position: relative;) 
    子元素(position: absolute; left/top..)
    img居中显示: (height/width: 1px;position: relative;top: 50%;left: 50%;margin-top: -25px; /* 高度的一半 */margin-left: -25px; /* 宽度的一半 */)

2. 颜色

png/元素透明: (background-color: transparent;)
visibility:hidden; 则相当于完全从文档流中删除了该元素,但尺寸仍然保留。vue(v-show)/angularjs(n-show)
opacity:0; 则仅仅不可见,但仍可被浏览器发现,也就能触发各种事件
display: none; 元素被移除, 不被渲染; //在vue(v-if)/angularjs(n-if)

3. 伪元素:

背景
:before{
    content: "";
    position: absolute;
    top: 0px;right: 0px;
    width: 20px;height: 20px;
    background: url(/img/pic.png) no-repeat;
}

3. 优先级

强制优先: left: auto !important; /*!important*/

4. CSS 事件

屏蔽鼠标事件: pointer-events: none;
拖拽事件: draggable:false;
hover事件: li:hover{cursor: pointer;}

5. 选择器

li:last-child; &:first-child; /*less 写法: &: 当前的元素*/
li:nth-child(n+6) {display: none;} /*隐藏第5以后的元素*/
li:nth-child(3n) {display: none;} /*隐藏3的倍数的元素*/

6. 其他

鼠标样式: cursor: pointer/default;

scroll样式:

/*scroll body*/
scrollBody{
    overflow-y: scroll;
    overflow-x: visible;
}   
/*定义滚动条轨道 轨道背景*/
#class::-webkit-scrollbar-track
{
    width: 10px;
    background-color: #CCC;
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.22);
}
/*定义滚动条高宽及背景 滚动条整体部分*/
#class::-webkit-scrollbar
{
    width: 10px;
    background-color: rgba(0, 0, 0, 0.34);
}
/*定义滚动条 下移动的滑块*/
#class::-webkit-scrollbar-thumb
{
    background-color: #DBDBDB;
    border-radius: 10px;
}

列出来整体例子
Html

<div id="wrapper">
  <div class="scrollbar" id="style-default">
  <div class="force-overflow"></div>
   </div>

<div class="scrollbar" id="style-1">
  <div class="force-overflow"></div>
</div>

    <div class="scrollbar" id="style-2">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-3">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-4">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-5">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-6">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-7">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-8">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-9">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-10">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-11">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-13">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-14">
      <div class="force-overflow"></div>
    </div>

    <div class="scrollbar" id="style-15">
      <div class="force-overflow"></div>
    </div>
</div>

CSS


header
{
    font-family: 'Lobster', cursive;
    text-align: center;
    font-size: 25px;    
}

#info
{
    font-size: 18px;
    color: #555;
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值