对响应式web设计的方法实现


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

这篇文章分享给大家的内容是关于响应式web设计的方法实现,内容很有参考价值,希望可以帮到有需要的小伙伴。

媒体查询的用法

media 媒体查询包含一个可选的媒体类型和,满足CSS3规范的条件下,包含零个或多个表达式,这些表达式描述了媒体特征,最终会被解析为true或false。如果媒体查询中指定的媒体类型匹配展示文档所使用的设备类型,并且所有的表达式的值都是true,那么该媒体查询的结果为true.

  • 500px-800px之间的设备 @media screen and (min-width: 500px) and (max-width: 800px) { ... }

  • 最小宽度500 @media screen and (min-width: 500px){... }

  • 在非打印设备下 @media not print and (max-width: 1200px)

使用方式:

3857564536-5b55722337161_articlex.png

实例

html:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<!doctype html>

<html>

<head>

    <meta charset="utf-8"/>

    <title>响应式设计</title>

 

    <link rel="stylesheet" type="text/css" href="day01.css" media="screen and (min-width:1024px)"/>

    <link rel="stylesheet" type="text/css" href="day02.css" media="screen and (max-width:1024px) and (min-width:600px)"/>

    <link rel="stylesheet" type="text/css" href="day03.css" media="screen and (max-width:600px)"/>

</head>

<body>

    <p class="top">头部</p>

    <p class="zhong">

        <p class="left">左边</p>

        <p class="zhon">中间</p>

        <p class="right">右边</p>

     </p>

    <p class="xia">底部</p>

</body>

</html>

css1:

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

.body{

    margin:0;

     

}

 

 

.top,.zhong,.xia{

    width:100%;

    margin:0 auto;

     

}

 

 

.top{

    height:100px;

    background:#00f;

     

}

 

 

.zhong{

overflow:hidden;

     

}

 

.xia{

    height:100px;

    background:#ff0;

     

}

 

.left,.zhon,.right{

    float:left;

     

}

 

.left{

    width:100%;

    height:200px;

    background:#0f0;

}

 

.zhon{

    width:100%;

    height:350px;

    background:#f00;

}

 

.right{

    width:100%;

    height:200px;

    background:#00f;

}

css2:

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

.body{

    margin:0;

     

}

 

 

.top,.zhong,.xia{

    width:100%;

    margin:0 auto;

     

}

 

 

.top{

    height:100px;

    background:#00f;

     

}

 

 

.zhong{

overflow:hidden;

     

}

 

.xia{

    height:100px;

    background:#ff0;

     

}

 

.left,.zhon,.right{

    float:left;

     

     

}

 

.left{

    width:30%;

    height:200px;

    background:#0f0;

}

 

.zhon{

    width:70%;

    height:350px;

    background:#f00;

}

 

.right{

    width:100%;

    height:200px;

    background:#00f;

}

css3:

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

.body{

    margin:0;

     

}

 

 

.top,.zhong,.xia{

    width:100%;

    margin:0 auto;

     

}

 

 

.top{

    height:100px;

    background:#00f;

     

}

 

 

.zhong{

overflow:hidden;

     

}

 

.xia{

    height:100px;

    background:#ff0;

     

}

 

.left,.zhon,.right{

    float:left;

    background:#0f0;

     

}

 

.left{

    width:20%;

    height:200px;

     

}

 

.zhon{

    width:45%;

    height:350px;

    margin:0 20px;

     

}

 

.right{

    width:25%;

    height:200px;

}

运行结果:

1、

4195440276-5b55754b86fa3_articlex.png

2、

3984556589-5b55755d48e35_articlex.gif

3、

262877225-5b5575dea96e2_articlex.gif

总结:.媒体查询Media Queries能在不同的条件下使用不同的样式,使页面在不同在终端设备下达到不同的渲染效果;到目前为止,CSS3 Media Queries得到了众多浏览器支持,除了IE6-8浏览器不支持之外,在所有现代浏览器中都可以完美支持。还有一个与众不同的是,Media Queries在其他浏览器中不要像其他CSS3属性一样在不同的浏览器中添加前缀。

相关推荐:

关于css响应式的实现代码及效果

CSS实现响应式布局的方法

以上就是对响应式web设计的方法实现的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css怎么设置边框阴影效果

Html form标签name属性怎么用?form标签的name属性详解

怎么设置Html的背景图片的位置

Html如何在图片上设置超链接

css中rem有什么特点

css怎么把文字居中

css background为什么不显示

如何在Html中显示json数据

css怎么设置tr间距

css设置表格的属性有哪些

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




打赏

取消

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

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

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

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

评论

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