简体   繁体   English

如何使用CSS或JavaScript创建圆角

[英]How to create Rounded Corners using Css or javascript

Duplicate: 重复:

What is the best way to create rounded corners using CSS? 使用CSS创建圆角的最佳方法是什么?

I want to create a table with some colums where each column has a rounded corner. 我想创建一个带有一些列的表,其中每个列都有一个圆角。

I am not an css expert. 我不是CSS专家。 I think js solution should be fine too. 我认为js解决方案也应该很好。

If anyone has done it.. I will really appreciate if they can help. 如果有人做过..如果他们能帮助我,我将非常感谢。

I am not using Jquery. 我没有使用Jquery。

thanks, ben 谢谢,本

Here is a link to 25 different ways to do it with CSS: 这是使用CSS的25种不同方式的链接:

http://www.cssjuice.com/25-rounded-corners-techniques-with-css/ http://www.cssjuice.com/25-rounded-corners-techniques-with-css/

Here is a link to nifty corners to do it with javascript: 这是一个漂亮的角落的链接,可使用javascript做到这一点:

http://www.html.it/articoli/nifty/index.html http://www.html.it/articoli/nifty/index.html

In safari, chrome (I imagine), firefox 2+ and konquerer (and probably others) you can do it in CSS by using 'border-radius'. 在野生动物园,chrome(我想像),firefox 2+和konquerer(可能还有其他)中,您可以在CSS中使用“边界半径”来实现。 As it's not officially part of the spec yet, please use a vendor specific prefix 由于尚未正式纳入规范,因此请使用供应商特定的前缀

example

#round-my-corners-please {
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;

}

The JS solutions generally add a heap of small divs to make it look rounded, or they use borders and negative margins to make 1px notched corners. JS解决方案通常会增加一堆小div,使其看起来很圆,或者使用边框和负边距制作1px的缺口角。

IMO, the CSS way is better, as it looks cool, is easy, and will degrade gracefully in IE. IMO,CSS方法更好,因为它看起来很酷,很容易,并且会在IE中正常降级。 This is, of course, only the case where the client doesn't enforce them in IE. 当然,这仅是客户端未在IE中强制实施的情况。

This is what I'm doing on several projects: 这是我在几个项目上正在做的事情:

For Firefox and WebKit based browsers (although beware Chrome has bugs in this area), use their CSS border-radius based styles for native rounded corners: 对于基于Firefox和WebKit的浏览器(尽管要注意Chrome在此方面存在错误),对于本地圆角,请使用基于CSS边框半径的样式:

-webkit-border-radius: 20px;
-moz-border-radius: 20px;

These also let you specify values for each corner, just note that the syntax is slightly different: 这些还允许您为每个角指定值,只是请注意语法略有不同:

-moz-border-radius-bottomleft: 10px;
-moz-border-radius-bottomright: 10px;
-webkit-border-bottom-left-radius: 10px;
-webkit-border-bottom-right-radius: 10px;

These are based on the CSS3 border-radius style, more information on the different definitions here: CSS: border-radius and -moz-border-radiuss (note the article is a bit out of date but still relevant). 这些基于CSS3 border-radius样式,有关此处的不同定义的更多信息: CSS:border-radius和-moz-border-radiuss (请注意,该文章有些陈旧 ,但仍然适用)。 I haven't researched this but I'm not aware of any browsers that implement the native CSS3 border-radius (please corrent me if I'm wrong). 我还没有对此进行研究,但是我不知道有任何实现本机CSS3边界半径的浏览器(如果我输入错了,请给我指正)。

Then for IE, I use DD_roundies which is the most elegant JavaScript solution I've seen and uses native IE VML to draw the corners. 然后对于IE,我使用DD_roundies ,这是我见过的最优雅的JavaScript解决方案,并使用本机IE VML来解决问题。

If the user has IE without JavaScript or is using Opera, then tough luck they won't get rounded corners, but in the spirit of Progressive Enhancement this shouldn't ever be a problem. 如果用户使用的是不带JavaScript的IE或正在使用Opera,那么倒霉的是他们不会四舍五入,但是按照渐进增强的精神,这永远不是问题。

If you want to stick to CSS the best way is stated already: 如果您想坚持使用CSS,最好的方法已经陈述如下:

-webkit-border-radius: 20px;
-moz-border-radius: 20px;

However you are alienating the Internet Explorer marketshare. 但是,您正在疏远Internet Explorer的市场份额。

To get around this would be to create rounded images for your div. 为了解决这个问题,将为您的div创建圆形的图像。 http://www.roundedcornr.com/ has an image generator and example code. http://www.roundedcornr.com/具有图像生成器和示例代码。

A javascript alternative would be a jQuery plugin like DD_Roundies. 一个JavaScript替代方案是DD_Roundies之类的jQuery插件。 Using the DD_Roundies plugin is by far the easiest way to do this. 到目前为止,使用DD_Roundies插件是最简单的方法。 http://www.dillerdesign.com/experiment/DD_roundies/ You simply tell the div how big you want the radius and on what corners, it will do all the magic (colour, gradient) on its own. http://www.dillerdesign.com/experiment/DD_roundies/您只需告诉div您想要多大的半径以及在哪个角上,它将自行完成所有魔术(颜色,渐变)。

Most of the time I see this it involves using clever image manipulation using css. 我大多数时候都看到这涉及使用CSS进行巧妙的图像处理。 Tables and other such widgets are defined by the browsers so you can't just use them and guarantee everyone to see the same thing. 表格和其他此类小部件是由浏览器定义的,因此您不能仅仅使用它们并保证每个人都能看到相同的东西。

http://designworkx.co.nz/ http://designworkx.co.nz/

Has a simple coming soon page that is a good simple example of this. 有一个即将推出的简单页面,这是一个很好的简单示例。

HTML makeup tags, CSS and javascript is a more flexible way. HTML化妆标签,CSS和javascript是一种更灵活的方法。

This link tells the arithmetic to generate the css of round corner in any radius. 此链接告诉算法生成任意半径的圆角css。 http://www.pagecolumn.com/webparts/rounded_corners.htm http://www.pagecolumn.com/webparts/rounded_corners.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM