不用图像构造圆角框

不用图像构造圆角框

日期:2006-01-07 11:06:53  点击:1003  作者:  来源:

Stripe it to get it rounded

The basic idea of Nifty Corners is to get some coulored lines to get the rounded effect. This is the markup to get a rounded div: 数据挖掘论坛

<div id="container">
 <b class="rtop">
  <b class="r1"></b> <b class="r2"></b> <b class="r3"></b> <b class="r4"></b>
 </b>
 <!--content goes here -->
 <b class="rbottom">
  <b class="r4"></b> <b class="r3"></b> <b class="r2"></b> <b class="r1"></b>
 </b>
</div>
 

数据挖掘交友

And here"s it the basic CSS:

.rtop, .rbottom{display:block}
.rtop *, .rbottom *{display: block; height: 1px; overflow: hidden}
.r1{margin: 0 5px}
.r2{margin: 0 3px}
.r3{margin: 0 2px}
.r4{margin: 0 1px; height: 2px}
  

You can see the final effect on this simple example . A few words on the use of the <b> element. I needed an inline element to obtain the rounded corners, since it could be nested in almost every kind of tag mainting the markup valid. So the choice fell on b because it doesn"t have semantical meaning and it"s shorter than span, like Eric Meyer said. 数据挖掘实验室

The technique works even on floated, absolute positioned or percentage-width elements. It fails on element with fixed height, or with padding. Both of the problem could be easily solved with an extra wrapper around the content. 数据挖掘实验室

Known bugs are: text-indent won"t work on the element that has been rounded in Opera, and IE (both Mac & version 6 PC) would mess up on floated elements without specific width. 数据挖掘工具

The support should be extended to all modern browsers: the technique has been tested with success in Internet Explorer 6, Opera 7.6, FireFox 1.0, Safari 1.1 Mac IE. It fails on IE 5.x PC. 数据挖掘论坛

Easy, isn"t it? But we can do much better.

Looking forward with DOM

In the example we saw how to get rounded corners without images, sparing about 6-8Kb of page weight. But we love webstandards and semantic markup and we"d like to maintain the HTML clean and light.

数据挖掘实验室

Nifty Corners with CSS and Javascript

So, the next step was to provide the unnecessary <b> elements with javascript and DOM making some functions to get rounded corners on almost every element on the page without adding a single line of extra HTML or CSS apart from the basic rules we saw. Let"s have a look at the example with Nifty Corners. As you can see from the source code, no extra markup is in it. The solution is a combination of CSS and Javascript. The technique is made up of four essential parts:

  1. CSS file for the screen
  2. CSS file for the print
  3. Javascript library to get Nifty Corners
  4. the javascript calls to round the elements you want

The first three components just don"t need changes, whatever you want to accomplish. They need just to be declared in the head section of any HTML page like this:

数据挖掘工具

<link rel="stylesheet" type="text/css" href="niftyCorners.css">
<link rel="stylesheet" type="text/css" href="niftyPrint.css" media="print">
<script type="text/javascript" src="nifty.js"></script>
 数据挖掘交友 

To understand how to implement the fourth part, you need first to understand how the javascript library for Nifty Corners is implemented. Don"t worry: you aren"t requested to know javascript to use Nifty Corners...

The javascript functions

If you see the code of the example, you"ll notice that I left embedded the CSS and part of the javascript to show how the page is build. Let"s see the embedded javascript code:

数据挖掘交友

<script type="text/javascript">
 window.onload=function(){
 if(!NiftyCheck())
  return;
 Rounded("div#nifty","#377CB1","#9BD1FA");
 }
</script>
 数据挖掘研究院 

The function NiftyCheck performs a check for DOM support and excludes IE5.x PC for running the script. If the test has passed, the Rounded function is called. It accepts four parameters: 数据挖掘论坛

  1. A CSS selector that indicates on wich elements apply the function
  2. Outer color of the rounded corners
  3. Inner color of the rounded corners
  4. an optional fourth parameter, that if is setted to "small" would render small Nifty Corners

The real strenght of the function is that is capable of accepting a CSS selector to target the elements to round. The accepted parameters are:

数据挖掘交友

  • Tag selector, i.e. "p" or "blockquote" or "h2"
  • Id selector, with specified tag of the element: for example "div#content" or "p#news" or "li#home"
  • Class selector, with specified tag of the element: for example "div.entry" or "h2.highlight"
  • Descendant selector, with some limitation: this has to be composed by an id selector followed by a tag selector. Valid examples are: "div#news div" or "ul#menu li"

About the colors: they should be specified in hex code with # symbol in three or six digits. The outer color could be also set to transparent. 数据挖掘实验室

The fourth parameter is optional and must be setted to "small" to get small rounded corners. Let"s see an example: 数据挖掘工具

window.onload=function(){
 if(!!NiftyCheck())
  return;
 Rounded("div#header","transparent","#C3D9FF","small");
}
 数据挖掘研究院 

I" ve provided also two additional functions that you could find very useful: RoundedTop and RoundedBottom that receive the same parameters of the Rounded function and allow to get rounded corners just on the top or on the bottom of page elements, or all four corners but with upper ones that differ in color from the lower. 数据挖掘工具

Now.. let"s see some examples.

The examples

Now the fun part.. I did some examples to show the possibilities of Nifty Corners. For each example will be reported on this page just the javascript calls to Rounded, RoundedTop and RoundedBottom functions, but keep in mind that these calls should be included in the following code:

数据挖掘论坛

window.onload=function(){
if(!NiftyCheck())
  return;
/* here the calls to add Nifty Corners */
}
 

数据挖掘论坛

Now, let"s begin! 数据挖掘研究院

Example one: a single div

This is the example we saw in the opening. The javascript call is: 数据挖掘工具

Rounded("div#nifty","#377CB1","#9BD1FA");
 数据挖掘论坛 

Example two: 2 divs

In this example, two divs were rounded. The js calls are: 数据挖掘论坛

Rounded("div#content","#fff","#9DD4FF");
Rounded("div#nav","#fff","#E5FFC4");
  

Example three: small corners

In this example the heading has small rounded corners. The code:

数据挖掘论坛

Rounded("div#header","transparent","#C3D9FF","small");
Rounded("div#box","#FFF","#E4E7F2");
 数据挖掘工具 

Example four: newsboxes

In this example we"ll see how to make 2-colour newsboxes. The code is:

RoundedTop("div.news","#FFF","#91A7E3");
RoundedBottom("div.news","#FFF","#E0D6DF");
 

数据挖掘工具

Example five: transparent, tabbed menu

This example show the power of the discendant selector and transparency to get a tabbed menu with a single javascript call:

数据挖掘实验室

RoundedTop("div#nav li","transparent","#E8F0FF");
  

Example six: a liquid image gallery

I rounded-framed an unordered list used for an image gallery here. The javascript call is:

Rounded("div#minipics li","#DDD","#FFF");
 数据挖掘工具 

Example seven: rounding a form

In this example, I rounded a form and its labels with two js calls:

Rounded("form","#FFF","#BBD8FF");
Rounded("label","#BBD8FF","#FFF","small");
 数据挖掘研究院 

Example eight: final example

This is the final example wich uses some of the techniques we saw in the previous ones. In this case, I did not use embedded css or javascript. The head section contains the following lines: 数据挖掘交友

<link rel="stylesheet" type="text/css" href="roundedPage.css">
<link rel="stylesheet" type="text/css" href="niftyCorners.css">
<link rel="stylesheet" type="text/css" href="niftyPrint.css" media="print">
<script type="text/javascript" src="nifty.js"></script>
<script type="text/javascript" src="final.js"></script>
 数据挖掘交友 

The final.js contains all the javascript calls, let"s see its content:

window.onload=function(){
 if(!NiftyCheck())
  return;
 RoundedTop("div#container","#FFF","#e7e7e7");
 RoundedBottom("div#container","#FFF","#E9F398");
 RoundedTop("ul#nav li","transparent","#E8F0FF");
 Rounded("div#box","#C0CDF2","#E4E7F2");
 Rounded("div#minipics li","#C0CDF2","#FFF");
 RoundedTop("div.gradient","#C0CDF2","#B8B8B8");
 RoundedBottom("div.gradient","#C0CDF2","#ECECF2");
}
 数据挖掘交友 

A good practice is in fact avoiding using embedded javascript or CSS in the head section. 数据挖掘交友

Quite easy, isn"t it? If we"d use one of the css techiques based on background images, probably we"d used 18 images, maybe some extra and non-semantic wrapper and a lot of css declaration. Could you imagine the kilobytes that were spared? Probably, about 18-20Kb or so.

[数据挖掘专家] [数据挖掘研究院] [数据挖掘论坛] [数据挖掘实验室]
上一篇:如何下载网页中的flash SWF文件
下一篇:如何下载网页中的flash SWF文件
最新评论共有 0 位网友发表了评论 , 查看所有评论
发表评论( 不能超过250字,需审核,请自觉遵守互联网相关政策法规。 )
匿名?
数据挖掘网站导航 数据挖掘论坛导航
  • 数据挖掘工具
  • 数据挖掘论坛
  • DataCruncher - Cognos
  • MineSet - MathSoft
  • Intelligent Miner - GainSmarts
  • Sqlserver - SAS - Clementine
  • CART - Weka - WizSoft
  • NeuroShell - ModelQuest
  • data mining tools - Darwin
  • 数据挖掘交友
  • 数据挖掘博客
  • 数据挖掘工具
  • 数据挖掘资源
  • 数据挖掘技术算法
  • 数据挖掘相关期刊、会议
  • 研究院联盟合作专区
  • 数据挖掘基础与相关技术
  • 数据挖掘厂商与就业
  • 数据挖掘研究者乐园
  • 知名厂商数据挖掘工具资料
  • 国内数据挖掘实验室
  • Foreign Data Mining Lab
  • 热点关注
  • 新年矢量素材下载大集合
  • frame高度宽度固定
  • JavaScript语言参考手册_目录
  • 用XMLHTTP Post Form时的表单乱码解决方案
  • 使用Filter实现动态页面的静态HTML缓冲
  • javascript 通用库(二)
  • 用CSS制作鼠标经过图像
  • javascript 差错功能函数
  • 急死了~~checkbox传值的问题
  • javaScript基础
  • 论坛最新话题
  • Foundations of Statistical Natural Langu
  • Game Theory meet Data Mining: A Recent P
  • System Building: How does it help or hin
  • 数据挖掘与Clementine培训
  • 新手报到
  • 求 SASEM 客户流失预测分析
  • 数据挖掘工程师/搜索研究院—北京——无线
  • 数据挖掘入门介绍(如何着手数据挖掘)
  • Information Overload Survey Results
  • The INEX 2005 Workshop on Element Retrie
  • 相关资讯
  • javascript lanscape打印
  • javascript 差错功能函数
  • javascript 通用库(二)
  • javascript 通用库(一)
  • javascript 正则表达式
  • 脚本攻击防范策略完全篇
  • javaScript基础
  • 用XMLHTTP Post Form时的表单乱码解决方案
  • 中文排版CSS心得
  • 使用Filter实现动态页面的静态HTML缓冲
  • 数据挖掘实验室资料
  • 数据挖掘博客地址
  • 数据挖掘实验室网站地址
  • Prepare for Medicare audits by using dat
  • 注册成为SAS用户与爱好者俱乐部会员
  • 水南梅
  • 明日烟
  • 新人报道
  • 下载
  • 厦门服务器托管,450元/月—0592-5177319 高
  • 买空间送域名--0592-5177319 高静