从现在开始,像HTML5一样使用

从现在开始,像HTML5一样使用

 相信从事网站建设的人都知道,HTML5必定是个趋势,大家现在应该做的就是在国内IE6猖獗的情况下像HTML5一样使用老的CSS以及代码。

这方面做的很好的一个典范就是淘宝网,淘宝UED团队在不久前对淘宝网首页进行了一次大改版,使用了最新的HTML5技术构建的淘宝首页,但是据淘宝网官方的统计说明淘宝网的使用群体中使用IE9及以下版本不支持HTML5浏览器的人数占到了一大半,那这么做是不是会冒很大的风险。其实淘宝UED团队的做法非常明智,他们使用JS构建最新的HTML5标签,然后对其进行定义,并在头部判断当浏览器不支持JS时给出提示(不开启js上网的用户恐怕少的可怜吧),然后使用最新的标签,完美的兼容了极大多数的浏览器。

最新的HTML5标签的浏览器有以下几种

article, aside, canvas, details, embed, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {

    display: block;

}

command, datalist, keygen, mark, meter, progress, rp, rt, ruby, time, wbr {

    display: inline;、

}

 

其实,我们也没有必要非得像淘宝 一样做的那么到位,我们完全可以“像HTML5那样使用” 原来的样式。来看下面的例子

HTML5 example:

figure {

    float: left;

    border: 1px solid gray;

    padding: 0.25em;

    margin: 0 0 1.5em 1em;

}

figcaption {

    text-align: center;

    font: italic 0.9em Georgia, "Times New Roman", Times, serif;

}

<figure>

    <img src="splash.jpg" alt="A toddler’s face is obscured by a rippled and dimpled wall of water thrown up by her hands slapping into the surface of the swimming pool in whose waters she sits.">

<figcaption>SPLASH SPLASH SPLASH!!!</figcaption>

</figure>

同样的,我们来实现这样的功能,而使用的是过去版本的HTML和CSS,代码可以这样写

.figure {

    float: left;

    border: 1px solid gray;

    padding: 0.25em;

    margin: 0 0 1.5em 1em;

}

.figcaption {

    text-align: center;

    font: italic 0.9em Georgia, "Times New Roman", Times, serif;

}

<div class="figure">

    <img src="spring.jpg" alt="A small child with twin pigtail braids, her back to the camera, swings away from the camera on a playground swingset while the late afternoon sun peeks over the crossbar of the swingset.">

    <div class="figcaption">Swinging into spring.</div>

</div>

看到了吗,这是一个非常棒的主意,至少在IE浏览器不支持HTML5之前是一个近乎完美的解决方案。很可能我们很多聪明的读者已经在这样做了。

网站建设发展到今天的情况下,良好的HTML结构和友好的用户体验是非常重要的。