css如何实现边框长度控制功能


本文摘自PHP中文网,作者V,侵删。

以前需要边框长度比容器小一些时,我用div嵌套。后来发现伪类在实现这个效果时很方便,只需要一个div就够了,另外调整padding和margin都不会很麻烦。

(推荐教程:CSS入门教程)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<div class="content-block">

<div class="box-container">

<div class="border-top">border top</div>

</div>

<div class="box-container">

<div class="border-left">border left</div>

</div>

<div class="box-container">

<div class="border-right">border right</div>

</div>

<div class="box-container">

<div class="border-bottom">border bottom</div>

</div>

</div>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

.box-container {

    position: relative;

    width: 90%;

    color: #777;

}

.border-top {

    background: #b4bcbf;

    padding: 15px;

}

    .border-top:before {

        content: '';

        position: absolute;

        left: 42%;

        top: 0;

        bottom: auto;

        right: auto;

        height: 7px;

        width: 50%;

        background-color: #8796a9;

    }

.border-left {

    background: #dfdad6;

    padding: 15px;

}

    .border-left:before {

        content: '';

        position: absolute;

        left: 0;

        top: 6%;

        bottom: auto;

        right: auto;

        height: 52%;

        width: 5px;

        background-color: #a89d9e;

    }

.border-right {

    background: #eee9c4;

    padding: 15px;

}

    .border-right:after {

        content: '';

        position: absolute;

        left: auto;

        top: auto;

        bottom: 5px;

        right: 0;

        height: 52%;

        width: 5px;

        background-color: #f39c81;

    }

.border-bottom {

    background: #bcdc9d;

    padding: 15px;

}

    .border-bottom:after {

        content: '';

        position: absolute;

        left: 18px;

        top: auto;

        bottom: 0;

        right: auto;

        height: 6px;

        width: 105px;

        background-color: #32b66b;

    }

效果如下图:

5f6a1f9ca376281f35a5e9eb16ab129.png

相关视频教程推荐:css视频教程

以上就是css如何实现边框长度控制功能的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css %单位的特点

css如何实现下拉菜单

style标签怎么用?

css align-self属性怎么用

css中伪类和伪对象(伪元素)区别是什么

sass系统是什么

js框架与css框架的区别是什么

css怎么去除图片边框

css实现动态条形加载条效果(附源码)

如何利用纯css实现图片轮播

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...