使用 CSS 创建圆角

发布于 2024-07-04 17:40:06 字数 21 浏览 7 评论 0原文

如何使用 CSS 创建圆角?

How can I create rounded corners using CSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

暮年慕年 2024-07-11 17:40:08

不要使用CSS,jQuery已经被提到过好几次了。 如果您需要完全控制元素的背景和边框,请提供jQuery 后台画布插件 尝试一下。 它将 HTML5 Canvas 元素放置在背景中,并允许您绘制您想要的每个背景或边框。 圆角、渐变等。

Don't use CSS, jQuery has been mentioned several times. If you need full control of the background and border of your elements give thejQuery Background Canvas Plugin a try. It places a HTML5 Canvas element in the background and allows yo to draw every background or border you want. Rounded corners, gradients and so on.

太傻旳人生 2024-07-11 17:40:08

Opera 还不支持 border-radius (显然会在版本 10 之后的版本中提供)。 同时,您可以使用 CSS 设置SVG 背景创建类似的效果

Opera does not support border-radius yet (apparently it will be in the release after version 10). In the meantime, you can use CSS to set an SVG background to create a similar effect.

二智少女 2024-07-11 17:40:07

jQuery 是我个人处理这个问题的方式。 css 支持很少,图像太繁琐,能够在 jQuery 中选择你想要圆角的元素对我来说非常有意义,尽管有些人无疑会反对。 我最近在工作中使用了一个插件: http://web.archive.org/web/20111120191231/http://plugins.jquery.com:80/project/jquery-roundcorners-canvas

jQuery is the way i'd deal with this personally. css support is minimal, images are too fiddly, to be able to select the elements you want to have round corners in jQuery makes perfect sense to me even though some will no doubt argue otherwise. Theres a plugin I recently used for a project at work here: http://web.archive.org/web/20111120191231/http://plugins.jquery.com:80/project/jquery-roundcorners-canvas

許願樹丅啲祈禱 2024-07-11 17:40:07

没有“最好”的方法; 有些方法适合你,有些方法不适合你。 话虽如此,我在这里发布了一篇关于创建基于 CSS+Image 的流体圆角技术的文章:

使用 CSS 和图像的圆角框 - 第 2 部分

此技巧的概述是使用嵌套 DIV 和背景图像重复和定位。 对于固定宽度布局(固定宽度可拉伸高度),您需要三个 DIV 和三个图像。 对于流体宽度布局(可拉伸的宽度和高度),您需要九个 DIV 和九个图像。 有些人可能认为它太复杂,但恕我直言,它是有史以来最简洁的解决方案。 没有 hack,没有 JavaScript。

There is no "the best" way; there are ways that work for you and ways that don't. Having said that, I posted an article about creating CSS+Image based, fluid round corner technique here:

Box with Round Corners Using CSS and Images - Part 2

An overview of this trick is that that uses nested DIVs and background image repetition and positioning. For fixed width layouts (fixed width stretchable height), you'll need three DIVs and three images. For a fluid width layout (stretchable width and height) you'll need nine DIVs and nine images. Some might consider it too complicated but IMHO its the neatest solution ever. No hacks, no JavaScript.

白云悠悠 2024-07-11 17:40:07

当然,如果它是固定宽度,那么使用 CSS 就非常容易,而且一点也不冒犯或费力。 当你需要它在两个方向上扩展时,事情就会变得不稳定。 有些解决方案需要将数量惊人的 div 堆叠在一起才能实现这一点。

我的解决方案是告诉设计师,如果他们想使用圆角(暂时),则它需要是固定宽度。 设计师喜欢圆角(我也是),所以我发现这是一个合理的妥协。

Sure, if it's a fixed width, it's super easy using CSS, and not at all offensive or laborious. It's when you need it to scale in both directions that things get choppy. Some of the solutions have a staggering amount of divs stacked on top of each other to make it happen.

My solution is to dictate to the designer that if they want to use rounded corners (for the time being), it needs to be a fixed width. Designers love rounded corners (so do I), so I find this to be a reasonable compromise.

毁梦 2024-07-11 17:40:07

Ruzee Borders 是我发现的唯一基于 Javascript 的抗锯齿圆角解决方案适用于所有主要浏览器(Firefox 2/3、Chrome、Safari 3、IE6/7/8),也是唯一一种在圆形元素和父元素都包含背景图像时适用的浏览器。 它还可以处理边框、阴影和发光。

较新的 RUZEE.ShadedBorder 是另一种选择,但它缺乏从 CSS 获取样式信息的支持。

Ruzee Borders is the only Javascript-based anti-aliased rounded corner solution I've found that works in all major browsers (Firefox 2/3, Chrome, Safari 3, IE6/7/8), and ALSO the only one that works when both the rounded element AND the parent element contain a background image. It also does borders, shadows, and glowing.

The newer RUZEE.ShadedBorder is another option, but it lacks support for obtaining style information from CSS.

风向决定发型 2024-07-11 17:40:07

如果您要使用 border-radius 解决方案,可以使用这个很棒的网站来生成 css,使其适用于 safari/chrome/FF。

无论如何,我认为你的设计不应该依赖于圆角,如果你看看 Twitter,他们只是对 IE 和 Opera 用户说 F****。 圆角是一个很好的东西,我个人同意为不使用 IE 的酷用户保留它:)。

当然现在这不是客户的意见。
这是链接:http://border-radius.com/

If you are to go with the border-radius solution, there is this awesome website to generate the css that will make it work for safari/chrome/FF.

Anyway, I think your design should not depend on the rounded corner, and if you look at Twitter, they just say F**** to IE and opera users. Rounded corners is a nice to have, and I'm personally ok keeping this for the cool users who don't use IE :).

Now of course it's not the opinion of the clients.
Here is the link : http://border-radius.com/

烟花易冷人易散 2024-07-11 17:40:07

除了上面提到的 htc 解决方案之外,这里还有另一个解决方案和示例来达到 rounded IE 中的角

To addition of htc solutions mention above, here're another solutions and examples to reach rounded corners in IE.

倾城泪 2024-07-11 17:40:07

我不久前写了一篇关于此的博客文章,因此有关更多信息,请参阅此处

<div class="item_with_border">
    <div class="border_top_left"></div>
    <div class="border_top_right"></div>
    <div class="border_bottom_left"></div>
    <div class="border_bottom_right"></div>
    This is the text that is displayed
</div>

<style>
    div.item_with_border
    {
        border: 1px solid #FFF;
        postion: relative;
    }
    div.item_with_border > div.border_top_left
    {
        background-image: url(topleft.png);
        position: absolute;
        top: -1px;
        left: -1px;     
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_top_right
    {
        background-image: url(topright.png);
        position: absolute;
        top: -1px;
        right: -1px;        
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_bottom_left
    {
        background-image: url(bottomleft.png);
        position: absolute;
        bottom: -1px;
        left: -1px;     
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_bottom_right
    {
        background-image: url(bottomright.png);
        position: absolute;
        bottom: -1px;
        right: -1px;        
        width: 30px;
        height: 30px;
        z-index: 2;
    }   
</style>

效果很好。 不需要 JavaScript,只需要 CSS 和 HTML。 HTML 对其他内容的干扰最小。 它与 Mono 发布的内容非常相似,但不包含任何 IE 6 特定的 hack,并且经过检查,似乎根本不起作用。 另外,另一个技巧是使每个角图像的内部部分透明,这样它就不会遮挡角附近的文本。 外部部分不能是透明的,这样它就可以覆盖非圆形 div 的边框。

此外,一旦 CSS3 广泛支持 border-radius,这将成为官方制作圆角的最佳方式。

I wrote a blog article on this a while back, so for more info, see here

<div class="item_with_border">
    <div class="border_top_left"></div>
    <div class="border_top_right"></div>
    <div class="border_bottom_left"></div>
    <div class="border_bottom_right"></div>
    This is the text that is displayed
</div>

<style>
    div.item_with_border
    {
        border: 1px solid #FFF;
        postion: relative;
    }
    div.item_with_border > div.border_top_left
    {
        background-image: url(topleft.png);
        position: absolute;
        top: -1px;
        left: -1px;     
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_top_right
    {
        background-image: url(topright.png);
        position: absolute;
        top: -1px;
        right: -1px;        
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_bottom_left
    {
        background-image: url(bottomleft.png);
        position: absolute;
        bottom: -1px;
        left: -1px;     
        width: 30px;
        height: 30px;
        z-index: 2;
    }
    div.item_with_border > div.border_bottom_right
    {
        background-image: url(bottomright.png);
        position: absolute;
        bottom: -1px;
        right: -1px;        
        width: 30px;
        height: 30px;
        z-index: 2;
    }   
</style>

It works quite well. No Javascript needed, just CSS and HTML. With minimal HTML interfering with the other stuff. It's very similar to what Mono posted, but doesn't contain any IE 6 specific hacks, and after checking, doesn't seem to work at all. Also, another trick is to make the inside portion of each corner image transparent so it doesn't block text that is near the corner. The outer portion must not be transparent so it can cover up the border of the non-rounded div.

Also, once CSS3 is widely supported with border-radius, that will be the official best way of making rounded corners.

风情万种。 2024-07-11 17:40:07

随着较新版本的 Firefox、Safari 和 Chrome 实现了对 CSS3 的支持,查看“Border Radius”也会有所帮助。

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

与任何其他CSS简写一样,上面的内容也可以以扩展格式编写,从而实现左上、右上等不同的边框半径。

-moz-border-radius-topleft: 10px;  
-moz-border-radius-topright: 7px;  
-moz-border-radius-bottomleft: 5px;  
-moz-border-radius-bottomright: 3px;  
-webkit-border-top-right-radius: 10px;  
-webkit-border-top-left-radius: 7px;  
-webkit-border-bottom-left-radius: 5px;  
-webkit-border-bottom-right-radius: 3px;

With support for CSS3 being implemented in newer versions of Firefox, Safari and Chrome, it will also be helpful to look at "Border Radius".

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

Like any other CSS shorthand, the above can also be written in expanded format, and thus achieve different Border Radius for the topleft, topright, etc.

-moz-border-radius-topleft: 10px;  
-moz-border-radius-topright: 7px;  
-moz-border-radius-bottomleft: 5px;  
-moz-border-radius-bottomright: 3px;  
-webkit-border-top-right-radius: 10px;  
-webkit-border-top-left-radius: 7px;  
-webkit-border-bottom-left-radius: 5px;  
-webkit-border-bottom-right-radius: 3px;
似梦非梦 2024-07-11 17:40:07

正如 Brajeshwar 所说:使用 border-radius css3 选择器。 现在,您可以分别为基于 Mozilla 和 Webkit 的浏览器应用 -moz-border-radius-webkit-border-radius

那么,Internet Explorer 会发生什么情况呢? 微软有很多行为让Internet Explorer拥有一些额外的功能并获得更多的技能。

这里:一个 .htc 行为文件,用于从 CSS 中的 border-radius 值获取圆角。 例如。

div.box {
    background-color: yellow; 
    border: 1px solid red; 
    border-radius: 5px; 
    behavior: url(corners.htc);
}

当然,行为选择器并不是一个有效的选择器,但是你可以将它放在带有条件注释的不同css文件中(仅适用于IE)。

行为 HTC 文件

As Brajeshwar said: Using the border-radius css3 selector. By now, you can apply -moz-border-radius and -webkit-border-radius for Mozilla and Webkit based browsers, respectively.

So, what happens with Internet Explorer?. Microsoft has many behaviors to make Internet Explorer have some extra features and get more skills.

Here: a .htc behavior file to get round-corners from border-radius value in your CSS. For example.

div.box {
    background-color: yellow; 
    border: 1px solid red; 
    border-radius: 5px; 
    behavior: url(corners.htc);
}

Of course, behavior selector does not a valid selector, but you can put it on a different css file with conditional comments (only for IE).

The behavior HTC file

生来就爱笑 2024-07-11 17:40:07

我建议使用背景图像。 其他方法则没有那么好:没有抗锯齿和无意义的标记。 这不是使用 JavaScript 的地方。

I would recommend using background images. The other ways aren't nearly as good: No anti-aliasing and senseless markup. This is not the place to use JavaScript.

深居我梦 2024-07-11 17:40:07

如果您有兴趣在 IE 中创建角点,那么这可能会有用 - http://css3pie.com/

If you're interested in creating corners in IE then this may be of use - http://css3pie.com/

若沐 2024-07-11 17:40:07

就连 Yahoo 也不鼓励使用圆角(请参阅第一个项目符号点)! 诚然,他们在那篇文章中只讨论了 1 像素圆角,但有趣的是,即使是一家拥有其专业知识的公司也得出结论,它们太痛苦了 让它们在大多数时间工作

如果您的设计没有它们也能生存,那就是最简单的解决方案。

As an indication of how complex it is to get rounded corners working, even Yahoo discourages them (see first bulleted point)! Granted, they're only talking about 1 pixel rounded corners in that article but it's interesting to see that even a company with their expertise has concluded they're just too much pain to get them working most of the time.

If your design can survive without them, that's the easiest solution.

抱着落日 2024-07-11 17:40:07

总是有 JavaScript 方式(参见其他答案),但由于它纯粹是样式,我有点反对使用客户端脚本来实现这一点。

我更喜欢的方式(尽管它有其局限性)是使用 4 个圆角图像,您将使用 CSS 将它们放置在框的 4 个角中:

<div class="Rounded">
  <!-- content -->
  <div class="RoundedCorner RoundedCorner-TopLeft"></div>
  <div class="RoundedCorner RoundedCorner-TopRight"></div>
  <div class="RoundedCorner RoundedCorner-BottomRight"></div>
  <div class="RoundedCorner RoundedCorner-BottomLeft"></div>
</div>

/********************************
* Rounded styling
********************************/

.Rounded {
  position: relative;
}

.Rounded .RoundedCorner {
  position: absolute;
  background-image: url('SpriteSheet.png');
  background-repeat: no-repeat;
  overflow: hidden;

  /* Size of the rounded corner images */
  height: 5px;
  width: 5px;
}

.Rounded .RoundedCorner-TopLeft {
  top: 0;
  left: 0;

  /* No background position change (or maybe depending on your sprite sheet) */
}

.Rounded .RoundedCorner-TopRight {
  top: 0;
  right: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: -5px 0;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-TopRight {
  right: -1px;
}

.Rounded .RoundedCorner-BottomLeft {
  bottom: 0;
  left: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: 0 -5px;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomLeft {
  bottom: -20px;
}

.Rounded .RoundedCorner-BottomRight {
  bottom: 0;
  right: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: -5px -5px;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomRight {
  bottom: -20px;
  right: -1px;
}

如前所述,它有其局限性(圆角框后面的背景应该是纯色的)否则角落将与背景不匹配),但它对于其他任何东西都非常有效。


更新:通过使用精灵表改进了实现。

There's always the JavaScript way (see other answers) but since it's is purely styling, I'm kind of against use client scripts to achieve this.

The way I prefer (though it has its limits), is to use 4 rounded corner images that you will position in the 4 corners of your box using CSS:

<div class="Rounded">
  <!-- content -->
  <div class="RoundedCorner RoundedCorner-TopLeft"></div>
  <div class="RoundedCorner RoundedCorner-TopRight"></div>
  <div class="RoundedCorner RoundedCorner-BottomRight"></div>
  <div class="RoundedCorner RoundedCorner-BottomLeft"></div>
</div>

/********************************
* Rounded styling
********************************/

.Rounded {
  position: relative;
}

.Rounded .RoundedCorner {
  position: absolute;
  background-image: url('SpriteSheet.png');
  background-repeat: no-repeat;
  overflow: hidden;

  /* Size of the rounded corner images */
  height: 5px;
  width: 5px;
}

.Rounded .RoundedCorner-TopLeft {
  top: 0;
  left: 0;

  /* No background position change (or maybe depending on your sprite sheet) */
}

.Rounded .RoundedCorner-TopRight {
  top: 0;
  right: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: -5px 0;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-TopRight {
  right: -1px;
}

.Rounded .RoundedCorner-BottomLeft {
  bottom: 0;
  left: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: 0 -5px;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomLeft {
  bottom: -20px;
}

.Rounded .RoundedCorner-BottomRight {
  bottom: 0;
  right: 0;

  /* Move the sprite sheet to show the appropriate image */
  background-position: -5px -5px;
}

/* Hack for IE6 */
* html .Rounded .RoundedCorner-BottomRight {
  bottom: -20px;
  right: -1px;
}

As mentioned, it has its limits (the background behind the rounded box should be plain otherwise the corners won't match the background), but it works very well for anything else.


Updated: Improved the implentation by using a sprite sheet.

夜深人未静 2024-07-11 17:40:07

我个人最喜欢这个解决方案,它是一个.htc,允许 IE 渲染弯曲边框。

http://www.htmlremix.com/css/curved-corner -边框半径-跨浏览器

I personally like this solution the best, its an .htc to allow IE to render curved borders.

http://www.htmlremix.com/css/curved-corner-border-radius-cross-browser

2024-07-11 17:40:07

在 Safari、Chrome、Firefox 中 > 2、IE> 在 CSS 8 和 Konquerer(可能还有其他)中,您可以使用 border-radius 属性在 CSS 中完成此操作。 由于它尚未正式成为规范的一部分,因此请使用供应商特定的前缀...

示例

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

JavaScript 解决方案通常会添加一堆小 div 使其看起来呈圆形,或者使用边框和负数边距制作 1px 的凹口角。 有些还可能在 IE 中使用 SVG。

IMO,CSS 方式更好,因为它很简单,并且会在不支持它的浏览器中优雅地降级。 当然,这只是客户端在不支持的浏览器(例如 IE <<)中不强制执行它们的情况。 9.

In Safari, Chrome, Firefox > 2, IE > 8 and Konquerer (and probably others) you can do it in CSS by using the border-radius property. 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;
    border-radius: 20px;
}

The JavaScript 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. Some may also utilise SVG in IE.

IMO, the CSS way is better, as it is easy, and will degrade gracefully in browsers that don't support it. This is, of course, only the case where the client doesn't enforce them in non supported browsers such as IE < 9.

夜空下最亮的亮点 2024-07-11 17:40:07

这是我最近做的一个 HTML/js/css 解决方案。 IE 中的绝对定位存在 1px 舍入误差,因此您希望容器的宽度为偶数个像素,但它非常干净。

HTML:

<div class="s">Content</div>

jQuery:

$("div.s")
.wrapInner("<div class='s-iwrap'><div class='s-iwrap2'>")
.prepend('<div class="tr"/><div class="tl"/><div class="br"/><div class="bl"/>');

CSS:

/*rounded corner orange box - no title*/
.s {
    position: relative;
    margin: 0 auto 15px;
    zoom: 1;
}

.s-iwrap {
    border: 1px solid #FF9933;
}

.s-iwrap2 {
    margin: 12px;
}

.s .br,.s .bl, .s .tl, .s .tr {
    background: url(css/images/orange_corners_sprite.png) no-repeat;
    line-height: 1px;
    font-size: 1px;
    width: 9px;
    height: 9px;
    position: absolute;
}

.s .br {
    bottom: 0;
    right: 0;
    background-position: bottom right;
}

.s .bl {
    bottom: 0;
    left: 0;
    background-position: bottom left;
}

.s .tl {
    top: 0;
    left: 0;
    background-position: top left;
}

.s .tr {
    top: 0;
    right: 0;
    background-position: top right;
}

图像只有 18 像素宽,并且所有 4 个角都挤在一起。 看起来像一个圆圈。

注意:您不需要第二个内部包装器,但我喜欢在内包装器上使用边距,以便段落和标题上的边距仍然保持边距折叠。
您也可以跳过 jquery,只将内部包装器放在 html 中。

Here's an HTML/js/css solution that I did recently. There's a 1px rounding error with absolute positioning in IE so you want the container to be an even number of pixels wide, but it's pretty clean.

HTML:

<div class="s">Content</div>

jQuery:

$("div.s")
.wrapInner("<div class='s-iwrap'><div class='s-iwrap2'>")
.prepend('<div class="tr"/><div class="tl"/><div class="br"/><div class="bl"/>');

CSS:

/*rounded corner orange box - no title*/
.s {
    position: relative;
    margin: 0 auto 15px;
    zoom: 1;
}

.s-iwrap {
    border: 1px solid #FF9933;
}

.s-iwrap2 {
    margin: 12px;
}

.s .br,.s .bl, .s .tl, .s .tr {
    background: url(css/images/orange_corners_sprite.png) no-repeat;
    line-height: 1px;
    font-size: 1px;
    width: 9px;
    height: 9px;
    position: absolute;
}

.s .br {
    bottom: 0;
    right: 0;
    background-position: bottom right;
}

.s .bl {
    bottom: 0;
    left: 0;
    background-position: bottom left;
}

.s .tl {
    top: 0;
    left: 0;
    background-position: top left;
}

.s .tr {
    top: 0;
    right: 0;
    background-position: top right;
}

Image is just 18px wide and has all 4 corners packed together. Looks like a circle.

Note: you don't need the second inner wrapper, but I like to use margin on the inner wrapper so that margins on paragraphs and headings still maintain margin collapse.
You can also skip the jquery and just put the inner wrapper in the html.

旧竹 2024-07-11 17:40:07

我通常只使用 css 得到圆角,如果浏览器不支持,他们会看到带有平角的内容。 如果圆角对于您的网站来说不是那么重要,您可以使用下面的这些行。

如果您想使用具有相同半径的所有角,这是简单的方法:

.my_rounded_corners{
   -webkit-border-radius: 5px;
           border-radius: 5px;
}

但如果您想控制每个角,这很好:

.my_rounded_corners{
    border: 1px solid #ccc;

    /* each value for each corner clockwise starting from top left */
    -webkit-border-radius: 10px 3px 0 20px;
            border-radius: 10px 3px 0 20px;
}

正如您在每个集合中看到的,您具有浏览器特定的样式,并且在第四行上我们以标准方式声明我们假设,如果将来其他人(希望也包括 IE)决定实现该功能,以使我们的风格也为他们做好准备。

正如其他答案所述,这在 Firefox、Safari、Camino、Chrome 上运行得很好。

I generally get rounded corners just with css, if browser does not support they see the content with flat corners. If rounded corners are not so critical for your site you can use these lines below.

If you want to use all corners with same radius this is the easy way:

.my_rounded_corners{
   -webkit-border-radius: 5px;
           border-radius: 5px;
}

but if you want to control every corner this is good:

.my_rounded_corners{
    border: 1px solid #ccc;

    /* each value for each corner clockwise starting from top left */
    -webkit-border-radius: 10px 3px 0 20px;
            border-radius: 10px 3px 0 20px;
}

As you see in each set you have browser specific styles and on the fourth rows we declare in standard way by this we assume if in future the others (hopefully IE too) decide to implement the feature to have our style be ready for them too.

As told in other answers, this works beautifully on Firefox, Safari, Camino, Chrome.

不寐倦长更 2024-07-11 17:40:07

我在创建 Stack Overflow 的早期就研究过这个问题,但找不到任何创建圆角的方法,不会让我感觉自己刚刚走过下水道。

CSS3 最终定义了

border-radius:

这正是您想要的让它工作。 虽然这在最新版本的 Safari 和 Firefox 中可以正常工作,但在 IE7(我不认为在 IE8 中)或 Opera 中根本不行。

与此同时,一切都在进行黑客攻击。 我很想听听其他人认为目前在 IE7、FF2/3、Safari3 和 Opera 9.5 上执行此操作的最简洁方法。

I looked at this early on in the creation of Stack Overflow and couldn't find any method of creating rounded corners that didn't leave me feeling like I just walked through a sewer.

CSS3 does finally define the

border-radius:

Which is exactly how you'd want it to work. Although this works OK in the latest versions of Safari and Firefox, but not at all in IE7 (and I don't think in IE8) or Opera.

In the meantime, it's hacks all the way down. I'm interested in hearing what other people think is the cleanest way to do this across IE7, FF2/3, Safari3, and Opera 9.5 at the moment..

后eg是否自 2024-07-11 17:40:06

自从 CSS3 引入以来,使用 CSS 添加圆角的最佳方法是使用 border-radius 属性。 您可以阅读该属性的规范,或者获取一些MDN 上的有用实现信息

如果您使用的是不支持的浏览器 实现 border-radius(Chrome pre-v4、Firefox pre-v4、IE8、Opera pre-v10.5、Safari pre-v5),然后下面的链接详细介绍了一大堆不同的方法。 找到一个适合您的网站和编码风格的工具,然后使用它。

  1. CSS 设计:创建自定义角
    & 边框
  2. CSS 圆角“Roundup”
  3. CSS 的 25 种圆角技术

Since CSS3 was introduced, the best way to add rounded corners using CSS is by using the border-radius property. You can read the spec on the property, or get some useful implementation information on MDN:

If you are using a browser that doesn't implement border-radius (Chrome pre-v4, Firefox pre-v4, IE8, Opera pre-v10.5, Safari pre-v5), then the links below detail a whole bunch of different approaches. Find one that suits your site and coding style, and go with it.

  1. CSS Design: Creating Custom Corners
    & Borders
  2. CSS Rounded Corners 'Roundup'
  3. 25 Rounded Corners Techniques with CSS
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文