css揭秘读书笔记(一)

css揭秘读书笔记(一)

  • 带箭头的提示框
  • 透明边框
  • 多重边框
  • 背景图片灵活定位
  • 缝边效果
  • 边框内圆角
带箭头的提示框
tips: 利用伪元素和继承

这里写图片描述
html

<div class="box">你好,css</div>

css

.box {
    width: 200px;
    padding: 20px;
    margin-top: 20px;
    position: relative;
    border: 1px solid #e4e4e4;
    background: #f5f5f5;
}
.box:after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: -7px;
    left: 20px;
    border: inherit;
    background: inherit;
    border-right: 0;
    border-bottom: 0;
    transform: rotate(45deg);
}
透明边框
tips: 如果不用background-clip则边框会被覆盖,因为background-clip默认值为border-box,即将背景裁剪到边框,将值设为padding-box即可将背景裁剪到内边距框

这里写图片描述
html

<div class="box">你好,css</div>

css

body {
    background: #F5E434;
}
.box {
    width: 200px;
    padding: 20px;
    margin-top: 20px;
    background: #fff;
    border: 10px solid hsla(0, 0%, 100%, .5);/*透明边框*/
    background-clip: padding-box;
}
多重边框
tips: 利用box-shadow,将偏移值和模糊距离都设为0,阴影的尺寸即为边框的宽度,因为box-shadow可以添加多个阴影,因此可以实现多重边框

这里写图片描述
html

<div class="box">你好,css</div>

css

.box {
    width: 200px;
    padding: 20px;
    margin: 40px;
    background: yellowgreen;
    box-shadow: 0 0 0 10px #655,
    0 0 0 20px deeppink;
}
背景图片灵活定位
tips: 利用background-origin改变背景图片的定位位置,默认根据内边框定位

这里写图片描述
html

<div class="box">你好,css你好,css你好,css你好,css你好,css</div>

css

.box {
    width: 200px;
    padding: 20px;
    background: url(images/square.png) no-repeat;
    border: 1px solid #e4e4e4;
    background-origin: content-box;
    /*还可以改成background-position: left 20px top 20px;*/
}
缝边效果
tips: 利用outline-offset将描边移至元素内,但是outline不能实现圆角

这里写图片描述
html

<div class="box">你好,css</div>

css

.box {
    width: 200px;
    padding: 20px;
    background: yellowgreen;
    border-radius: 5px;
    outline: 1px dashed #fff;
    outline-offset: -10px;
}
边框内圆角
tips: 利用box-shadow和outline,box-shadow可以实现圆角,outline在box-shadow的上层

这里写图片描述

html

<div class="box">你好,css</div>

css

.box {
    width: 200px;
    padding: 20px;
    margin: 40px;
    background: tan;
    border-radius: 10px;
    box-shadow: 0 0 0 4px deeppink;
    outline: 10px solid #655;
}

将box-shadow的颜色值设为#655并设置阴影尺寸合理值即可以“填满空隙”,关于阴影尺寸的设置:必须大于 (21)r ,其中 r <script type="math/tex" id="MathJax-Element-2">r</script> 为圆角半径。
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值