浅谈Bootstrap中的自适应屏幕


本文摘自PHP中文网,作者青灯夜游,侵删。

本篇文章带大家聊聊Bootstrap中的自适应屏幕。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

Bootstrap是基于HTML.css.javaScript开发的简洁,直观,强悍的前端开发框架,使web开发跟家快捷能制作响应式网页。【相关推荐:《bootstrap教程》】

bootstrap自适应:

Bootstrap根据屏幕大小吧设备分为超小屏幕,小屏幕,中等屏幕,大屏幕四种并把屏幕分为12列对应屏幕宽度为:

超小屏幕(手机):0-768px 对应设置 class=col-xs-number
小屏幕(平板):768-992px 对应设置class=col-sm-number
中等屏幕(电脑):992-1200px 对应设置 class=col-md-number
大屏幕(电脑):1200px-? 对应设置 class=col-lg-number

在chrome浏览器,elements窗口中会发现当屏幕宽度小于768时,只有com-xs-12生效。

自适应:网页适应不同设备 ,用bootstrap框架

原理:是媒体(设备/浏览器)查询 @media only screen 查询设备的宽度

底层是以@media only screen and (min-width:最小值) and (max-width:最大值)进行呈现:

例一对背景:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

@media only screen and (min-width:0px) and (max-width:480px){

body{

background-color:red;

}

}

@media only screen and (min-width:481px) and (max-width:720px){

body{

background-color:green;

}

}

@media only screen and (min-width:721px){

body{

background-color:blue;

}

}

例二对块级元素p

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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<style type="text/css">

div{

float:left;

}

/**小屏0px-768px*/

@media only screen and (min-width:0px) and (max-width:768px){

.sm-12{

width:100%;

    }

}

/**大屏768*/

@media only screen and (min-width:768px){

.lg-6{

width:50%;

    }

}

 

</style>

<!-- 两个样式不会同时生效 在小屏上sm-12生效, width是100%在大屏上lg-6生效,width50%

css中标签分块级标记和行级标记,div是块级元素 -->

<div class="sm-12 lg-6">div1</div>

<div class="sm-12 lg-6">div2</div>

</body>

</html>

bootstarp对其进行整合自适应
步骤

1.link标签引入bootstrap.css文件
2.在bootstrap中定义
1)根元素必须是p class值必须等于container
2)根元素必须包含行元素且行元素class值必须等于row
3)行中包含列class的值必须为col-*-number

例如:

阅读剩余部分

相关阅读 >>

bootstrap中的按钮样式,图片样式 介绍

带你快速打造属于自己的bootstrap站点

bootstrap如何使用路径分页标签

bootstrap基于什么开发

bootstrap字体图标怎么使用方法

bootstrap原理是什么

bootstrap如何设置div边框

bootstrap做什么用的?

jsp中怎么导入bootstrap样式

easyui和bootstrap区别

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




打赏

取消

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

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

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

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

评论

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