在成都做网站、成都建网站,成都网站建设及网页制作,首选领城互动
  • 首页
  • 关于我们
  • 服务范围
  • 经典案例
  • 联系我们
当前位置:首页 > 服务项目 > 品牌形象设计 > 设计提升用户体验之:宽度自适应效果的实现!

设计提升用户体验之:宽度自适应效果的实现!

 随着3G甚至于4G手机的普及,移动终端开始成为网民中的生力军,越来越多的人使用手机上网。

  移动设备正在以惊人的速度增长,大有超过桌面设备,占据网络主力的趋势。或许在不久的将来成为访问互联网的最常见的终端。于是,在这种状况下网站的网页设计师不得不面对一个难题:同样的网页,如何让不同屏幕大小的浏览者都能很好的观看?

  跟pc的屏幕相比,手机的屏幕一般都比较小,如今屏幕最大的手机也不过4-5英寸。而且手机的宽度通常在600像素以下;PC的屏幕宽度,一般都在1000像素以上(目前主流宽度是1366×768),有的还达到了2000像素。于是乎,我们遇到了一个最直接的难题。同样的内容,要在大小迥异的屏幕上,都呈现出满意的效果,似乎并不是一件容易的事。

  这个问题很早就开始被人们重视,之前很多网站的解决方法是:为不同的设备提供不同的网页,没有直面问题的根本,从另一个思路去化解了它。比如专门提供一个mobile版本,或者iPhone / iPad版本。这样做固然保证了浏览效果,但是却增加了网站运营和维护的成本。因为,不同的版本对应了不同的程序、服务器。这些都是需要人力物力去维系的!

  为继续尝试从根源上化解这个难题,很早之前就开始有人设想,能不能让我们的网页做到”一次设计,普遍适用”,让同一张网页自动适应不同大小的屏幕,根据屏幕宽度,自动调整布局(layout)? 最早进行这种构想的是我们伟大的国外设计师。

以下为引用内容:

 一、”自适应网页设计”的由来  2010年,Ethan Marcotte提出了“自适应网页设计”(Responsive Web Design)这个名词,指可以自动识别屏幕宽度、并做出相应调整的网页设计。

  他制作了一个范例,里面是《福尔摩斯历险记》六个主人公的头像。如果屏幕宽度大于1300像素,则6张图片并排在一行。

  如果屏幕宽度在600像素到1300像素之间,则6张图片分成两行

  如果屏幕宽度在400像素到600像素之间,则导航栏移到网页头部。

  如果屏幕宽度在400像素以下,则6张图片分成三行。

 

  二、允许网页宽度自动调整

  “自适应网页设计”到底是怎么做到的?其实并不难。

 

  首先,在网页代码的头部,加入一行viewport元标签。

 

<meta name=”viewport” content=”width=device-width, initial-scale=1″ />

 

  viewport是网页默认的宽度和高度,上面这行代码的意思是,网页宽度默认等于屏幕宽度(width=device-width),原始缩放比例(initial-scale=1)为1.0,即网页初始大小占屏幕面积的100%。

 

  所有主流浏览器都支持这个设置,包括IE9。对于那些老式浏览器(主要是IE6、7、8),需要使用css3-mediaqueries.js。

 

<!–[if lt IE 9]>

<script src=”http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js”></script>

<![endif]–>

 

  三、不使用绝对宽度

 

  由于网页会根据屏幕宽度调整布局,所以不能使用绝对宽度的布局,也不能使用具有绝对宽度的元素。这一条非常重要。

 

  具体说,CSS代码不能指定像素宽度:

 

  width:xxx px;

 

  只能指定百分比宽度:

 

  width: xx%;

 

  或者

 

  width:auto;

 

  四、相对大小的字体

 

  字体也不能使用绝对大小(px),而只能使用相对大小(em)。

 

body {

font: normal 100% Helvetica, Arial, sans-serif;

}

 

  上面的代码指定,字体大小是页面默认大小的100%,即16像素。

 

  然后,h1的大小是默认大小的1.5倍,即24像素(24/16=1.5)。

 

h1 {

font-size: 1.5em;

}

 

  small元素的大小是默认大小的0.875倍,即14像素(14/16=0.875)。

 

small {

font-size: 0.875em;

}

 

  五、流动布局(fluid grid)

 

  “流动布局”的含义是,各个区块的位置都是浮动的,不是固定不变的。

 

.main {

float: right;

width: 70%;

}

 

.leftBar {

float: left;

width: 25%;

}

 

  float的好处是,如果宽度太小,放不下两个元素,后面的元素会自动滚动到前面元素的下方,不会在水平方向overflow(溢出),避免了水平滚动条的出现。

 

  另外,绝对定位(position: absolute)的使用,也要非常小心。

 

  六、选择加载CSS

 

  “自适应网页设计”的核心,就是CSS3引入的Media Query模块。

 

  它的意思就是,自动探测屏幕宽度,然后加载相应的CSS文件。

 

<link rel=”stylesheet” type=”text/css”

media=”screen and (max-device-width: 400px)”

href=”tinyScreen.css” />

 

  上面的代码意思是,如果屏幕宽度小于400像素(max-device-width: 400px),就加载tinyScreen.css文件。

 

  如果屏幕宽度在400像素到600像素之间,则加载smallScreen.css文件。

 

<link rel=”stylesheet” type=”text/css”

media=”screen and (min-width: 400px) and (max-device-width: 600px)”

href=”smallScreen.css” />

 

  除了用html标签加载CSS文件,还可以在现有CSS文件中加载。

 

@import url(“tinyScreen.css”) screen and (max-device-width: 400px);

 

  七、CSS的@media规则

 

  同一个CSS文件中,也可以根据不同的屏幕分辨率,选择应用不同的CSS规则。

 

  上面的代码意思是,如果屏幕宽度小于400像素,则column块取消浮动(float:none)、宽度自动调节(width:auto),sidebar块不显示(display:none)。

 

  八、图片的自适应(fluid image)

  除了布局和文本,”自适应网页设计”还必须实现图片的自动缩放。

  这只要一行CSS代码:

 

img { max-width: 100%;}

 

  这行代码对于大多数嵌入网页的视频也有效,所以可以写成:

 

img, object { max-width: 100%;}

 

  老版本的IE不支持max-width,所以只好写成:

 

img { width: 100%; }

 

  此外,windows平台缩放图片时,可能出现图像失真现象。这时,可以尝试使用IE的专有命令:

 

img { -ms-interpolation-mode: bicubic; }

 

  或者,Ethan Marcotte的imgSizer.js。

 

addLoadEvent(function() {

 

var imgs = document.getElementById(“content”).getElementsByTagName(“img”);

 

imgSizer.collate(imgs);

 

});

 

  不过,有条件的话,最好还是根据不同大小的屏幕,加载不同分辨率的图片。有很多方法可以做到这一条,服务器端和客户端都可以实现。



    电话:028-85030041
    地址:中国成都新希望国际A座
    ©Linking 2006-2021 Inc.
    蜀ICP备12000250号-1
Process: 0.039s ( Load:0.005s Init:0.012s Exec:0.017s Template:0.005s ) | DB :13 queries 0 writes | UseMem:2,097 kb
页面Trace信息
当前页面 : /vi/201205/154.html
模板缓存 : C:\wwwroot\www.citycy.com/data/front/runtime/cache/351ab735e880a1dd5f3567d38b061acb.php
请求方法 : GET
通信协议 : HTTP/1.1
请求时间 : 2023-09-24 15:04:05
用户代理 : CCBot/2.0 (https://commoncrawl.org/faq/)
会话ID : mqgmea3nc5npa2jao2ikakcoi4
日志记录 : 62条日志
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead DbMysql.class.php 第 62 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000558s SQL = SHOW COLUMNS FROM citycy_category
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000105s SQL = SELECT `catid` FROM `citycy_category` WHERE `catdir`='vi' LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead functions.php 第 118 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2048] Only variables should be assigned by reference FbaseAction.class.php 第 68 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: forward FbaseAction.class.php 第 69 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead common.php 第 79 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: userdata FbaseAction.class.php 第 105 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: userdata FbaseAction.class.php 第 105 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2048] Declaration of ContentModel::add() should be compatible with Model::add($data = '', $options = Array) ContentModel.class.php 第 507 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2048] Declaration of ContentModel::delete() should be compatible with Model::delete($options = Array) ContentModel.class.php 第 507 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000585s SQL = SHOW COLUMNS FROM citycy_content
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. DbMysql.class.php 第 400 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. DbMysql.class.php 第 400 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000103s SQL = SELECT `cid` FROM `citycy_content` WHERE ( `url` = '201205/154.html' ) AND ( `status` = '9' ) LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. DbMysql.class.php 第 400 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000142s SQL = SELECT * FROM `citycy_content` WHERE ( `url` = '201205/154.html' ) LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000394s SQL = SHOW COLUMNS FROM citycy_content_article
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. DbMysql.class.php 第 400 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000103s SQL = SELECT * FROM `citycy_content_article` WHERE ( `cid` = '154' ) LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000417s SQL = SHOW COLUMNS FROM citycy_model_field
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000083s SQL = SELECT `fieldid` FROM `citycy_model_field` WHERE `status`='1' AND `modelid`='1'
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000337s SQL = SHOW COLUMNS FROM citycy_content_tag
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8192] mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. DbMysql.class.php 第 400 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000097s SQL = SELECT citycy_tag.name FROM `citycy_content_tag` LEFT JOIN citycy_tag ON (citycy_tag.tagid=citycy_content_tag.tagid) WHERE ( citycy_content_tag.keyid = 'c-154' ) ORDER BY citycy_tag.tagid DESC
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2] Invalid argument supplied for foreach() ContentModel.class.php 第 416 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 199 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2] strpos(): Empty needle ThumbField.class.php 第 21 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: value Field.class.php 第 197 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined index: p FbaseAction.class.php 第 262 行.
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000102s SQL = SELECT * FROM `citycy_content` WHERE sort<1 AND catid=11 ORDER BY sort DESC LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] SQL: RunTime:0.000064s SQL = SELECT * FROM `citycy_content` WHERE sort>1 AND catid=11 ORDER BY sort ASC LIMIT 1
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2] Missing argument 1 for Ad::__construct(), called in C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\functions.php on line 259 and defined Ad.class.php 第 40 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [2] Missing argument 2 for Ad::__construct(), called in C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\functions.php on line 259 and defined Ad.class.php 第 40 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: type Ad.class.php 第 41 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: setting Ad.class.php 第 42 行.
[ 2023-09-24T15:04:05+08:00 ] NOTIC: [8] Undefined variable: html Ad.class.php 第 136 行.
加载文件 : 76
[0] => C:\wwwroot\www.citycy.com\index.php
[1] => C:\wwwroot\www.citycy.com\define.php
[2] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\ThinkPHP.php
[3] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\runtime.php
[4] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\defines.php
[5] => C:\wwwroot\www.citycy.com\front\Conf\paths.php
[6] => C:\wwwroot\www.citycy.com\front\Conf\core.php
[7] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\functions.php
[8] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\Think.class.php
[9] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Exception\ThinkException.class.php
[10] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\Log.class.php
[11] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\App.class.php
[12] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\Action.class.php
[13] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\View.class.php
[14] => C:\wwwroot\www.citycy.com\front\Common\alias.php
[15] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\convention.php
[16] => C:\wwwroot\www.citycy.com\front\Conf\config.php
[17] => C:\wwwroot\www.citycy.com\data\config.inc.php
[18] => C:\wwwroot\www.citycy.com\data\config.cache.php
[19] => C:\wwwroot\www.citycy.com\front\Common\common.php
[20] => C:\wwwroot\www.citycy.com\front\Conf\routes.php
[21] => C:\wwwroot\www.citycy.com\front\Conf\tags.php
[22] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Common\debug.php
[23] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Core\Model.class.php
[24] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Db\Db.class.php
[25] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Db\Driver\DbMysql.class.php
[26] => C:\wwwroot\www.citycy.com\data\cache\category_11.php
[27] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lang\zh-cn.php
[28] => C:\wwwroot\www.citycy.com\front\Lib\Action\FcontentAction.class.php
[29] => C:\wwwroot\www.citycy.com\front\Lib\Action\FbaseAction.class.php
[30] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\ORG\Util\Input.class.php
[31] => C:\wwwroot\www.citycy.com\include\Auth.class.php
[32] => C:\wwwroot\www.citycy.com\include\Act.class.php
[33] => C:\wwwroot\www.citycy.com\data\cache\front_act_cache.php
[34] => C:\wwwroot\www.citycy.com\front\Lib\Model\ContentextModel.class.php
[35] => C:\wwwroot\www.citycy.com\admin\Lib\Model\ContentModel.class.php
[36] => C:\wwwroot\www.citycy.com\include\Pager.class.php
[37] => C:\wwwroot\www.citycy.com\data\cache\model_1.php
[38] => C:\wwwroot\www.citycy.com\data\cache\modelField_1.php
[39] => C:\wwwroot\www.citycy.com\data\cache\modelField_2.php
[40] => C:\wwwroot\www.citycy.com\data\cache\modelField_4.php
[41] => C:\wwwroot\www.citycy.com\data\cache\modelField_6.php
[42] => C:\wwwroot\www.citycy.com\data\cache\modelField_7.php
[43] => C:\wwwroot\www.citycy.com\data\cache\modelField_8.php
[44] => C:\wwwroot\www.citycy.com\data\cache\modelField_9.php
[45] => C:\wwwroot\www.citycy.com\data\cache\modelField_10.php
[46] => C:\wwwroot\www.citycy.com\data\cache\modelField_11.php
[47] => C:\wwwroot\www.citycy.com\data\cache\modelField_12.php
[48] => C:\wwwroot\www.citycy.com\data\cache\modelField_13.php
[49] => C:\wwwroot\www.citycy.com\data\cache\modelField_14.php
[50] => C:\wwwroot\www.citycy.com\data\cache\modelField_15.php
[51] => C:\wwwroot\www.citycy.com\data\cache\modelField_16.php
[52] => C:\wwwroot\www.citycy.com\data\cache\modelField_20.php
[53] => C:\wwwroot\www.citycy.com\data\cache\modelField_21.php
[54] => C:\wwwroot\www.citycy.com\include\Field.class.php
[55] => C:\wwwroot\www.citycy.com\include\field\CatidField.class.php
[56] => C:\wwwroot\www.citycy.com\include\field\TitleField.class.php
[57] => C:\wwwroot\www.citycy.com\include\field\InputField.class.php
[58] => C:\wwwroot\www.citycy.com\include\field\ThumbField.class.php
[59] => C:\wwwroot\www.citycy.com\include\field\AttrField.class.php
[60] => C:\wwwroot\www.citycy.com\include\field\TextareaField.class.php
[61] => C:\wwwroot\www.citycy.com\include\field\EditorField.class.php
[62] => C:\wwwroot\www.citycy.com\include\Keylink.function.php
[63] => C:\wwwroot\www.citycy.com\include\field\BoxField.class.php
[64] => C:\wwwroot\www.citycy.com\include\field\TagField.class.php
[65] => C:\wwwroot\www.citycy.com\include\field\DatetimeField.class.php
[66] => C:\wwwroot\www.citycy.com\include\library\ThinkPHP\Lib\Think\Util\Template\TemplateSmarty.class.php
[67] => C:\wwwroot\www.citycy.com\include\Smarty\Smarty.class.php
[68] => C:\wwwroot\www.citycy.com\data\front\runtime\templates_c\%%F8^F84^F844ADE2%%article_view.html.php
[69] => C:\wwwroot\www.citycy.com\data\front\runtime\templates_c\%%71^714^714F4B17%%header.html.php
[70] => C:\wwwroot\www.citycy.com\include\Smarty\internals\core.load_plugins.php
[71] => C:\wwwroot\www.citycy.com\include\Smarty\internals\core.assemble_plugin_filepath.php
[72] => C:\wwwroot\www.citycy.com\include\tag\function.ffad.php
[73] => C:\wwwroot\www.citycy.com\data\ads\ad_1.php
[74] => C:\wwwroot\www.citycy.com\include\Ad.class.php
[75] => C:\wwwroot\www.citycy.com\data\front\runtime\templates_c\%%80^806^80621A61%%footer.html.php