实用的 CSS 技巧

  1. 解决 img 5px 间距的问题
    方案1:设置父元素字体大小为 0
    方案2:将 img 元素设置为 display: block
    方案3:将 img 元素设置为 vertical-align: bottom
    解决方案4:给父元素设置 line-height: 5px
  2. 元素的高度与 window 的高度相同
  3. 修改 input placeholder 样式
.placehoder-custom::-webkit-input-placeholder {
  color: #babbc1;
  font-size: 12px;
}
  1. 使用 :not 选择器
li:not(:last-child) {
  border-bottom: 1px solid #ebedf0;
}
  1. 使用 flex 布局将一个元素智能地固定在底部
.container {
  height: 100vh;
  /* Key Style */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
  1. 使用 caret-color 来修改input光标的颜色
caret-color: #ffd476;
  1. 删除input type=“number” 末尾的箭头
.no-arrow::-webkit-outer-spin-button,
.no-arrow::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
  1. outline:none 删除input输入状态线
  2. 解决iOS滚动条被卡住的问题:在苹果手机上,经常发生元素在滚动时被卡住的情况
body,html{
  -webkit-overflow-scrolling: touch;
}
  1. 绘制三角形
.box {
  padding: 15px;
  background-color: #f5f6f9;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.triangle {
  display: inline-block;
  margin-right: 10px;
  /* Base Style */
  border: solid 10px transparent;
}
/*下*/
.triangle.bottom {
  border-top-color: #0097a7;
}
/*上*/
.triangle.top {
  border-bottom-color: #b2ebf2;
}
/*左*/
.triangle.left {
  border-right-color: #00bcd4;
}
/*右*/
.triangle.right {
  border-left-color: #009688;
}
  1. 绘制小箭头
.box {
  padding: 15px;
  background-color: #ffffff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow {
  display: inline-block;
  margin-right: 10px;
  width: 0;
  height: 0;
  /* Base Style */
  border: 16px solid;
  border-color: transparent #cddc39 transparent transparent;
  position: relative;
}

.arrow::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -16px;
  border: 16px solid;
  border-color: transparent #fff transparent transparent;
}
/*下*/
.arrow.bottom {
  transform: rotate(270deg);
}
/*上*/
.arrow.top {
  transform: rotate(90deg);
}
/*左*/
.arrow.left {
  transform: rotate(180deg);
}
/*右*/
.arrow.right {
  transform: rotate(0deg);
}
  1. 隐藏滚动条
.box-hide-scrollbar::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
  1. 自定义选定的文本样式
.box-custom::selection {
  color: #ffffff;
  background-color: #ff4c9f;
}
  1. 不允许选择文本
.box p:last-child {
  user-select: none;
}
  1. 将一个元素在水平和垂直方向上居中
display: flex;
align-items: center;
justify-content: center;
  1. 单行文本溢出时显示省略号
 overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 375px;
  1. 多行文本溢出时显示省略号
overflow: hidden;
  text-overflow: ellipsis;

  display: -webkit-box;
  /* set n lines, including 1 */
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  1. 使用 “filter:grayscale(1)”,使页面处于灰色模式
body{
  filter: grayscale(1);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值