常用的css代码

清除浮动

  • 单位元素清除浮动
    .clearfix:after{
      content:"";//设置内容为空
      height:0;//高度为0
      line-height:0;//行高为0
      display:block;//将文本转为块级元素
      visibility:hidden;//将元素隐藏
      clear:both//清除浮动
   }

   .clearfix{
      zoom:1;为了兼容IE
   }
  • 双伪元素清除浮动
    .clearfix:before,.clearfix:after {
              content: "";
              display: block;
              clear: both;
        }
        .clearfix {
              zoom: 1;
        }

文字两端对齐

text-align:justify;

设定文字在某行末尾以省略号代替超出文字

<div class="box">
  文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述
</div>

<style>
/* 目前没有浏览器支持 box-orient 属性。
    Firefox 支持替代的 -moz-box-orient 属性。
    Safari、Opera 以及 Chrome 支持替代的 -webkit-box-orient 属性。 */
    .box {
      width: 200px;
      height: 80px;
      border: 1px solid blue;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2;  /*限制在一个块元素显示的文本的行数*/
      -webkit-box-orient: vertical;  /*规定框的子元素应该被水平或垂直排列*/
      white-space: normal;   /*超出文字会自动换行, 不能是no-warp*/
      word-wrap:break-word;  /*强制换行, 因为如果全是字母或数组会认为是一个单词而不换行*/
    }
</style>

文字超出以省略号代替

自适应多列

<div class="box">
  <div class="one"></div>
  <div class="two">
    <div class="two1"></div>
    <div class="two1"></div>
    <div class="two1"></div>
    <div class="two1"></div>
    <div class="two1"></div>
    <div class="two1"></div>
  </div>
</div>

<style>
  .box {
    height: 200px;
    border:1px solid blue;
    display: flex;
  }
  .box .one {
    width: 100px;
    height: 100%;
    background-color: red;
  }
  .box .two {
    height: 100%;
    flex: 1;
    background-color: rgb(228, 148, 148);
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    align-content: space-around;
  }
  .two1 {
    width: 60px;
    height: 60px;
    flex: 0 0 26%;
    background-color: gray;
  }

</style>

这里写图片描述

这里写图片描述

横向滑动

<view class="swip">
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
  <view class="sp"></view>
</view>
.swip {
  width: 750rpx;
  height: 110rpx;
  border:1px solid gray;
  overflow-x: scroll;
  overflow-y: hidden;
  white-space: nowrap;
  .sp {
    width: 200rpx;
    height: 100rpx;
    background-color: red;
    margin-right:20rpx;
    display: inline-block;

  }
}

这里写图片描述

动画

.carAnimate {
  animation: carSize 0.3s 1;
}
@keyframes carSize {
  0% {
    transform: scale(1);
    font-size: 26rpx;
  }
  40% {
    transform: scale(1.2);
  }
  60% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    font-size: 26rpx;
  }
}

vh和vw和vm

  • vh 可视窗口的高度 100vh
  • vw 可视窗口的宽度 100vw
  • vm 可视窗口的宽或者高(谁小就是谁) 100vm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值