我看过很多相关代码,但似乎都不能很好地或完全地解决问题。我已经使用了图片来实现圆角,但我需要的是能够使一个<table>
边框变圆的代码。我所找到的唯一解决方案就是在边框周围的单元格中插入图片。还有其他方法可以尝试吗?
尝试:
selector {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
<table>
进行布局。请注意,我认为在表格数据中使用表格标记是可以的,但不应在应使用DIV的地方使用它们。-moz-border-radius-topleft: 3px;
/* ... */
-webkit-border-top-left-radius: 3px;
继续使用topright
或top-right
。
尝试使用CSS 3选择器:
.element {
border-radius:5px
}
对于Safari、Google Chrome(Webkit)和Mozilla,使用以下两个选择器(尽管Mozilla支持CSS 3选择器,但不确定其他浏览器是否支持):
.element {
-webkit-border-radius:5px;
-moz-border-radius:5px;
}
要在所有浏览器上获得支持的唯一方法是在锚标签上使用图像背景,通常还与其容器标记上的图像相结合。
例如,使用以下HTML:
<ul>
<li><a href="">something</a></li>
<ul>
我会将一个图片放在锚点标签上,另一个放在li标签上,这样该元素就可以是可变宽度的,并且仍然具有圆角。
虽然CSS3功能和JS解决方案也可以起作用,但并不完全跨浏览器兼容。
你可以通过CSS将它们圆形化,但只适用于支持的浏览器。
你的其他非图像选项是基于脚本的,比如jQuery Corners或类似的脚本。
这两种方法都有注意事项(IE支持、禁用JavaScript的访问者等)。如果你决定使用它们,我建议你专注于在支持它的浏览器中让它们与CSS配合工作,并确保在IE中没有它们时看起来仍然可接受。
<div class="tl">
<div class="tr">
<div class="bl">
<div class="br">
<div class="t">
<div class="b">
<div class="l">
<div class="r">
<div>Do or do not, there is no try</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
.tl
{
font-family: Verdana, Arial;
font-size: 16px;
position: relative;
left: 30px;
}
.tl, .tr, .bl, .br
{
width: 655px;
height: 250px;
}
.t
{
width: 567px;
height: 250px;
margin: 0 0 0 44px;
}
.b
{
width: 567px;
height: 250px;
}
.l
{
width: 655px;
height: 162px;
margin: 44px 0 0 -44px;
}
.r
{
width: 655px;
height: 162px;
}
.bl
{
background: url(/images/front/rcbla.png) 0 100% no-repeat;
}
.br
{
background: url(/images/front/rcbra.png) 100% 100% no-repeat;
}
.tl
{
background: url(/images/front/rctla.png) 0 0 no-repeat;
}
.tr
{
background: url(/images/front/rctra.png) 100% 0 no-repeat;
}
.t
{
background: url(/images/front/adot.png) 0 0 repeat-x;
}
.b
{
background: url(/images/front/adot.png) 0 100% repeat-x;
}
.l
{
background: url(/images/front/adot.png) 0 0 repeat-y;
}
.r
{
background: url(/images/front/adot.png) 100% 0 repeat-y;
}
我假设上面的圆角CSS在IE6中不起作用。这是你需要记住的事情。
使用带有背景图像的三个堆叠的div是最简单的方法。
<div class="top"> </div>
<div class="mid"> <!-- content --> </div>
<div class="bottom"> </div>
如果您不必与所有浏览器一起工作,请考虑使用border-radius。有关更多信息,请参见http://www.css3.info/preview/rounded-border/。较新的Mozilla和基于Webkit的浏览器支持此标签或moz-border-radius和-webkit-border-radius。
我倾向于使用之前 person-b 提到的 border-radius
选项。
如果我绝对必须支持 IE(即它是设计的基本部分,而不仅仅是小的增强),我曾经尝试过 dd_Roundies,它利用 VML 来完成工作。