使用css实现自适应标题浮动效果(代码实例)


当前第2页 返回上一页

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

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>纯css实现自适应标题浮动效果</title>

  

    <style>

        body {

            background-color:#FAFAFA;

        }

  

        input[type="text"] {

    -webkit-box-sizing:border-box;

    -moz-box-sizing:border-box;

    box-sizing:border-box;

    width:100%;

    height:-webkit-calc(3em + 2px);

    height:calc(3em + 2px);

    margin:0 0 1em;

    padding:1em;

    border:1px solid #cccccc;

    border-radius:1.5em;

    background:#fff;

    resize:none;

    outline:none;

}

input[type="text"][required]:focus {

    border-color:#00bafa;

}

input[type="text"][required]:focus + label[placeholder]:before {

    color:#00bafa;

}

input[type="text"][required]:focus + label[placeholder]:before,input[type="text"][required]:valid + label[placeholder]:before {

    -webkit-transition-duration:.2s;

    transition-duration:.2s;

    -webkit-transform:translate(0,-1.5em) scale(0.9,0.9);

    -ms-transform:translate(0,-1.5em) scale(0.9,0.9);

    transform:translate(0,-1.5em) scale(0.9,0.9);

}

input[type="text"][required]:invalid + label[placeholder][alt]:before {

    content:attr(alt);

}

input[type="text"][required] + label[placeholder] {

    display:block;

    pointer-events:none;

    line-height:2.3em;

    margin-top:-webkit-calc(-3em - 2px);

    margin-top:calc(-3em - 2px);

    margin-bottom:-webkit-calc((3em - 1em) + 2px);

    margin-bottom:calc((3em - 1em) + 2px);

}

input[type="text"][required] + label[placeholder]:before {

    content:attr(placeholder);

    display:inline-block;

    margin:0 -webkit-calc(1em + 2px);

    margin:0 calc(1em + 2px);

    padding:0 2px;

    color:#898989;

    white-space:nowrap;

    -webkit-transition:0.3s ease-in-out;

    transition:0.3s ease-in-out;

    background-image:-webkit-gradient(linear,left top,left bottom,from(#ffffff),to(#ffffff));

    background-image:-webkit-linear-gradient(top,#ffffff,#ffffff);

    background-image:linear-gradient(to bottom,#ffffff,#ffffff);

    -webkit-background-size:100% 5px;

    background-size:100% 5px;

    background-repeat:no-repeat;

    background-position:center;

}

</style>

</head>

<body>

<div style="width:400px;height:100px;margin:50px auto">

<form>

<input required="" type="text">

<label alt="请输入用户名" placeholder="名称"></label>

</form>

</div>

</body>

</html>

更多编程相关知识,请访问:编程视频!!

以上就是使用css实现自适应标题浮动效果(代码实例)的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

css怎么实现超出两行显示省略

css如何加空格

老司机来和你谈谈,为什么说css是最难的!!

浅谈css perspective属性和perspective()函数的异同点

css box-flex-group属性怎么用

2021年值得了解的10 个 css 功能(分享收藏)

css的语法结构是什么?

css字体保持在一行不换行的实现方法

css的color属性有继承性吗?

css text-indent属性怎么用

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




打赏

取消

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

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

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

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

评论

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