0

0

圆角的例子(div+css)_html/css_WEB-ITnose

php中文网

php中文网

发布时间:2016-06-24 12:32:15

|

1209人浏览过

|

来源于php中文网

原创

http://www.html.it/articoli/niftycube/index.html(虽然是英文的,但相信大家耐心点还是可以看的懂的) by Alessandro Fulciniti

more than one year has passed from the first version of nifty corners. while it was more of a proof of concept, and the second version presented some big improvements, there was still something missing. so here i present nifty corners cube, that are simpler and more flexible than the previous versions. let's start.

New features

If you're new to Nifty Corners, I suggest to look in particular at the article on the first version to understand the concept behind them. Basically, Nifty Corners are a solution based on CSS and Javascript to get rounded corners without images.

There are several improvements and new features introduced in Nifty Corners Cube which make it more versatile and simpler to use than the previous versions:

The numbers of parameters has been reduced from four of the first version and five of the second version to just two, of which one is optional. It's not necessary specify the colors anymore, since they are detected automatically. They're easier to integrate into the design process, since the padding (both horizontal and vertical) of elements to round is preserved It's easier to use them with other scripts The support of CSS selectors has been improved and expanded Just a single line in the head section is now needed for the whole library: even if they're still based on both CSS and javascript, the presentational CSS for Nifty Corners is loaded automatically by js They're now released under GPL licence.

Together with the many novelties, that we'll discover through several examples, two features of the previous version has been abandoned. First, the support in Internet Explorer 5.0/Win has been totally dropped. Users of this browser will simply see squared corners, just as users with javascript disabled. The support remains very good however: the examples of the articles have all been tested successfully in IE5.5, IE6 and IE7 beta 2 preview, Opera 8.5, Firefox 1.5 and Safari 2.0. I had to drop even Nifty Corners with borders for compatibility issues I've had with IE and the new approach of the script.

Nifty Corners Cube: introduction

Nifty Corners Cube are a solution to get rounded corners without images, and this third version is build by three main components:

立即学习前端免费学习笔记(深入)”;

A javascript file, named "niftycornerscube.js" A CSS file, named "niftycorners.css" The javascript calls specific for the pages

Now we're now ready to look at the first example: it's a div with big rounded corners thanks to Nifty Corners. As I said before, the CSS file it's added automatically by javascript. In fact, the only reference to an external file in the example is the following:

Regarding the third point, as is the javascript calls needed for the page, the code for the example is the following:

In bold I've reported the part of the script that depends on the page, and that is the call for the function Nifty. This function is the core of the whole library, and receives two parameters that are the strength point of the script. Parameters have to be specified between quotes and separated by a comma. The first parameter is for the CSS selector that targets the elements to round, while the second parameter is for options for default cases could be omitted. Let's see them in depth.

The parameters

The first parameter is for the CSS selector to targets the elements on which apply Nifty Corners. The CSS selectors accepted are: tag selector, id selector, descendant selector (with id or class) and grouping. The following table show some example:

Selector Example tag selector id selector class selector descendant selector (with id) descendant selector (with class) grouping (any number and combination of the previous selectors)
"p"
"h2"
"div#header"
"h2#about"
"div.news"
"span.date"
"p.comment"
"div#content h2"
"div#menu a"
"ul.news li"
"div.entry h4"
"h2,h3"
"div#header,div#content,div#footer"
"ul#menu li,div.entry li"

Talking about options: they're identified by keywords and they can be specified in any order and number. Let's see them:

keyword meaning tl tr bl br top bottom left right all (default) none small normal (default) big transparent fixed-height same-height
top left corner
top right corner
bottom left corner
bottom right corner
upper corners
lower corners
left corners
right corners
all the four corners
no corners will be rounded (to use for nifty columns)
small corners (2px)
normal size corners (5px)
big size corners (10px)
inner transparent, alias corners will be obtained. This option activates automatically if the element to round does not have a background-color specified.
to be applied when a fixed height is set via CSS
Parameter for nifty columns: all elements identified by the CSS selector of the first parameter will have the same height. If the effect is needed without rounded corners, simply use this parameter in conjuction with the keyword none.

We'll meet the selectors and options through the many examples I've prepared. Let's start.

Example 1: a single div

The first example has been already presented. The code to round the div with id="box" is the following:



window.onload=function(){
Nifty("div#box","big");
}

The first line is needed to link the nifty corners library, while the others are for the specific page. Background colors of the page and the div id="box" are detected automatically by the script. Another thing to note is that the padding of the div (20px on vertical sides in this case) is preserved.

The part reported in bold is the call to the Nifty function. For the sake of brevity, starting from the next example, I'll report just the calls for this function, but please keep in mind that these have to be incorportated in an embedded script tag or, even better, in an external js file.

Example 2: two divs

In the second example nifty corners were used to round two divs with one single call:

Nifty("div#content,div#nav");

In this case just the first parameter has been used, as is the CSS selector with grouping: the two id selector are separated by a comma. The second parameter hasn't been used, therefore nifty corners will be of medium size (5px) and with antialias by default.

Example 3: transparency

In the example three nifty corners were applied on a div with a gradient background. In such cases the use of inner transparency could be really useful, and will be obtained via the transparent option. Let's see the javascript call:

Nifty("div#box","transparent");

The transparency option is compatible with all others, and is used by default on elements with no background-color set.

Example 4: nifty tabs

The fourth example is one of the major request on nifty corners: a tabbed menu without images. The javascript call is the following:

Nifty("ul#nav a","small transparent top");

Links are rounded on the top side, with small and transparent inside corners. Inner transparency is essential for the rollover effect. In the case rollover with background-color is not needed, here's a small variant where each tab is smooth-rounded and has got a different color. The js call in this case is:

Nifty("ul#nav a","top");

There's a thing to highlight, as is the fact that in both examples the tabs are perfectly elastic, since they're em-dimensioned.

Example 5: nifty buttons

In the fifth example a mini-navigation, suitable for blogs and such, is obtained with nifty corners. The code is the following:

Nifty("ul.postnav a","transparent");

In this markup, a class for the buttons has been used, so it would be possible to get several sets of of link-buttons in the same page. On the nifty corners side, the descendant selector with a class has been therefore used.

Example 6: boxes

In the sixth example nifty corners are used to round six divs with fixed height and bold corners. Each of div has a different color, even the lower-right one which is white like the background of the page. Antialias is automatically done, and padding of the list-items, both vertical and horizontal, has been preserved. But in order to honour the fixed height specified via CSS, the fixed-height keyword has to be specified. Here's the only js call used:

Nifty("div#about li","tl bottom big fixed-height");

AVCLabs
AVCLabs

AI移除视频背景,100%自动和免费

下载
Example 7: nifty columns

With the seventh example we introduce one of the biggest new features of nifty corners: nifty columns. This feature allow to get a faux-column effect without background. The option that does the trick is same-height, and the elements must be specified within the first parameter. The call for the example is:

Nifty("div#content,div#nav","same-height");

The option same-height tells the script to detect the height of the elements targetted by the css selector and to assign them the same height, as is the maximum value detected, without the need for background-images.

Example 8,9 and 10: more nifty columns

The examples eight, nine and ten are built on the same markup, which is the following:



  •   

    Title


      
    Content



  •   

    Title


      
    Content


  •   

    Title


      
    Content


The only things that vary are in fact CSS and the calls to nifty corners, which use nifty columns in the three cases. In the example height the javascript call is the following:

Nifty("ul#split li","same-height");

In example 9 two calls were used: one for the headings, and one, with the same-height options, for lower divs:

Nifty("ul#split h3","top");
Nifty("ul#split div","bottom same-height");

If you don't need rounded corners on the lower part, but you'd like to get anyway elements with the same height, as in the example 10, simply specify the none option:

Nifty("ul#split h3","top");
Nifty("ul#split div","none same-height");

Example 11 and 12: Nifty Corners Layout

We've arrived to two major examples of the article, as is Nifty Corners Layouts. In the example eleven and twelve nifty corners are used extensively for layout and page elements.

In example eleven, as in the previous examples, I left for ease of consultation the CSS and the script embedded in the page. The javascript section is the following:

window.onload=function(){
Nifty("div#container");
Nifty("div#content,div#nav","same-height small");
Nifty("div#header,div#footer","small");
}

When the page has loaded, Nifty Corners are applied on container, small and with faux columns on content and sidebar for navigation, and just small on the footer. The effect o a white border around all the page is achieved with a padding on the container.

The example twelve represent a two-column layout, tabbed navigation and some elements (like dates and comments) common in blog design. In this case CSS and javascript are kept in external files, here is the regarding code in the head section:



Apart from the CSS, two javascript files are linked in; one is the library for nifty corners, while the second one contain the specific call for the page:

window.onload=function(){
Nifty("div#menu a","small transparent top");
Nifty("ul#intro li","same-height");
Nifty("div.date");
Nifty("div#content,div#side","same-height");
Nifty("div.comments div");
Nifty("div#footer");
Nifty("div#container","bottom");
}

The option same-height has been used in two cases: on the three boxes of introduction and between content and navigation. In this second case, rounded corners are not visible, since they're done with transparency inside because the content has not a background-color specified.

Example 13: NiftyLoad

We've finally arrived at the last example. One of the frequent reported question is in fact how to make coexist Nifty Corners with other script, given the fact only one assignation to window.onload is possible.

In the example 13 an alert message, attached to window.onload, is shown before nifty corners proceed. This is done thanks to the function NiftyLoad, that will preserve a previous window.onload function. The javascript section, embedded on the page this time, is the following:

NiftyLoad=function(){
Nifty("div#box","big");
}

In order to make nifty corners work together with other script, you just have to use NiftyLoad instead of window.onload. Obviously the function could go even in an external file, the only important thing is that the two script blocks for nifty corners, as is the library and the page-centric calls, are the last two script blocks of head section of the page. The NiftyLoad function can also be used when nifty corners are the only script of the page, as is in any of the previous examples we've seen.

Troubleshooting and problem solving

While making Nifty Corners Cube I've tried to mantain the script as simple and robust as possible, and I hope to have inspired readersthrough the many example,.

The examples was also a way to test cross-browser compatibility, but this doesn't mean one might never get problems.

Even if javascript knowledge is not necessary, a working knowledge of CSS and HTML is, and it's also good practice to use always validate the code. If you do encounter problems, the first thing is to remove temporarily nifty corners and see if they persist. A general approach of development, that I've used on preparing the examples of this article, is getting the HTML and CSS entirely written before adding Nifty Corners to the page.

Two features introduced in this version should simplify Nifty Corners usage. Colors are detected automatically, and could be changed in the CSS without the need to update the javascript calls. Padding, both vertical and horizontal, is now preserved. Especially for vertical padding, it's suggested to specify a pixel value at least equal to the size of the corners.

The examples should be a good starting point: one thing to keep in mind is that in some case I've used ID, but if you'd need more than one element on a page you should use class or descendant selector, since an id in a page, according to HTML specification, should be unique.

Credits, licencing and download

I'd like to thanks David Lindquist for his help in getting things right in Safari. The idea of nifty columns was inspired by CSS balanced Columns, a very clever way to get faux columns without background.

Nifty Corners Cube are released under the GNU GPL licence and were published on the 22 March 2006 both in italian and english.

The examples and code the code is available for download. Enjoy!

相关文章

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
Python 自然语言处理(NLP)基础与实战
Python 自然语言处理(NLP)基础与实战

本专题系统讲解 Python 在自然语言处理(NLP)领域的基础方法与实战应用,涵盖文本预处理(分词、去停用词)、词性标注、命名实体识别、关键词提取、情感分析,以及常用 NLP 库(NLTK、spaCy)的核心用法。通过真实文本案例,帮助学习者掌握 使用 Python 进行文本分析与语言数据处理的完整流程,适用于内容分析、舆情监测与智能文本应用场景。

10

2026.01.27

拼多多赚钱的5种方法 拼多多赚钱的5种方法
拼多多赚钱的5种方法 拼多多赚钱的5种方法

在拼多多上赚钱主要可以通过无货源模式一件代发、精细化运营特色店铺、参与官方高流量活动、利用拼团机制社交裂变,以及成为多多进宝推广员这5种方法实现。核心策略在于通过低成本、高效率的供应链管理与营销,利用平台社交电商红利实现盈利。

109

2026.01.26

edge浏览器怎样设置主页 edge浏览器自定义设置教程
edge浏览器怎样设置主页 edge浏览器自定义设置教程

在Edge浏览器中设置主页,请依次点击右上角“...”图标 > 设置 > 开始、主页和新建标签页。在“Microsoft Edge 启动时”选择“打开以下页面”,点击“添加新页面”并输入网址。若要使用主页按钮,需在“外观”设置中开启“显示主页按钮”并设定网址。

16

2026.01.26

苹果官方查询网站 苹果手机正品激活查询入口
苹果官方查询网站 苹果手机正品激活查询入口

苹果官方查询网站主要通过 checkcoverage.apple.com/cn/zh/ 进行,可用于查询序列号(SN)对应的保修状态、激活日期及技术支持服务。此外,查找丢失设备请使用 iCloud.com/find,购买信息与物流可访问 Apple (中国大陆) 订单状态页面。

136

2026.01.26

npd人格什么意思 npd人格有什么特征
npd人格什么意思 npd人格有什么特征

NPD(Narcissistic Personality Disorder)即自恋型人格障碍,是一种心理健康问题,特点是极度夸大自我重要性、需要过度赞美与关注,同时极度缺乏共情能力,背后常掩藏着低自尊和不安全感,影响人际关系、工作和生活,通常在青少年时期开始显现,需由专业人士诊断。

7

2026.01.26

windows安全中心怎么关闭 windows安全中心怎么执行操作
windows安全中心怎么关闭 windows安全中心怎么执行操作

关闭Windows安全中心(Windows Defender)可通过系统设置暂时关闭,或使用组策略/注册表永久关闭。最简单的方法是:进入设置 > 隐私和安全性 > Windows安全中心 > 病毒和威胁防护 > 管理设置,将实时保护等选项关闭。

6

2026.01.26

2026年春运抢票攻略大全 春运抢票攻略教你三招手【技巧】
2026年春运抢票攻略大全 春运抢票攻略教你三招手【技巧】

铁路12306提供起售时间查询、起售提醒、购票预填、候补购票及误购限时免费退票五项服务,并强调官方渠道唯一性与信息安全。

122

2026.01.26

个人所得税税率表2026 个人所得税率最新税率表
个人所得税税率表2026 个人所得税率最新税率表

以工资薪金所得为例,应纳税额 = 应纳税所得额 × 税率 - 速算扣除数。应纳税所得额 = 月度收入 - 5000 元 - 专项扣除 - 专项附加扣除 - 依法确定的其他扣除。假设某员工月工资 10000 元,专项扣除 1000 元,专项附加扣除 2000 元,当月应纳税所得额为 10000 - 5000 - 1000 - 2000 = 2000 元,对应税率为 3%,速算扣除数为 0,则当月应纳税额为 2000×3% = 60 元。

35

2026.01.26

oppo云服务官网登录入口 oppo云服务登录手机版
oppo云服务官网登录入口 oppo云服务登录手机版

oppo云服务https://cloud.oppo.com/可以在云端安全存储您的照片、视频、联系人、便签等重要数据。当您的手机数据意外丢失或者需要更换手机时,可以随时将这些存储在云端的数据快速恢复到手机中。

121

2026.01.26

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3实现按钮特效视频教程
CSS3实现按钮特效视频教程

共15课时 | 3.2万人学习

CSS3  最新版参考手册
CSS3 最新版参考手册

共21课时 | 17.4万人学习

Web前端入门基础教程
Web前端入门基础教程

共251课时 | 34.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号