CSS:单元格边框由于某种原因未被舍入

时间:2012-07-13 16:05:04

标签: html css css3 rounded-corners

我想制作一个漂亮的导航栏,但出于某种原因,我无法将条形两端的单元格边框弄圆。如果你仔细观察角落,你应该能够看到背景发生一些圆角,但出于某种原因却看不到边界。

你可以在这里看到我的意思:http://jsfiddle.net/7veZQ/299/

这是我的代码:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
table {
    border-collapse: collapse;
    border: none;
    box-shadow: 0px 5px 10px #BBB;
}
.nav tr td {
    width: 160px;
    height: 40px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    text-transform: uppercase;
    color: #666;
    border: 1px solid #999;
    vertical-align: middle;
    text-align: center;
    background: #eeeeee; /* Old browsers */
    background: -moz-linear-gradient(top, #eeeeee 0%, #cccccc 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#cccccc)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* IE10+ */
    background: linear-gradient(to bottom, #eeeeee 0%,#cccccc 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cccccc',GradientType=0 ); /* IE6-9 */
    text-shadow: 1px 1px 0px #FFFFFF;
    letter-spacing: 3px;
}
.nav tr td:hover {
    background: #F4F4F4; /* Old browsers */
    background: -moz-linear-gradient(top, #F4F4F4 0%, #E0E0E0 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F4F4F4), color-stop(100%,#E0E0E0)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* IE10+ */
    background: linear-gradient(to bottom, #F4F4F4 0%,#E0E0E0 100%); /* W3C */
}
.nav tr td#first {
    border-radius: 5px 0px 0px 5px; 
    -moz-border-radius: 5px 0px 0px 5px; 
    -webkit-border-radius: 5px 0px 0px 5px;
}

.nav tr td#last {
    color: #09C;
    border-radius: 0px 5px 5px 0px; 
    -moz-border-radius: 0px 5px 5px 0px; 
    -webkit-border-radius: 0px 5px 5px 0px;
}
</style>
</head>
<body>
<table class="nav" width="960" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="first">Home</td>
    <td>Options</td>
    <td>Prices</td>
    <td>Showcase</td>
    <td>Help</td>
    <td id="last">Order Now!</td>
  </tr>
</table>

</body>
</html>

那么我做错了什么?

4 个答案:

答案 0 :(得分:4)

  

那么我做错了什么?

使用表格进行布局。

Tables are not layout tools。某些浏览器不会在表格单元格上转角。您有一个数据列表use list markup

答案 1 :(得分:1)

将您的表格css更改为

border-collapse: separate;

答案 2 :(得分:0)

不幸的是,这不是跨浏览器的CSS。并非所有浏览器都能找到CSS3。话虽如此,我建议有一些变化。首先,你不应该真正使用精确的高度和什么宽度。

其次,你应该使用DIV。 Decent forum post as to why...

无论如何,这里是“修复”(我个人反对浮动任何东西,但是很好。有时会发生这种情况:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
.nav {
    float:left;
    width:960px;
    height:40px;
    border: 1px solid #999;
    border-radius: 5px; 
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px;
    box-shadow: 0px 5px 10px #BBB;
}
.nav a {
    float:left;
    display:inline-block;
    margin:0;
    padding:0;
    line-height:40px;
    text-decoration:none;
    width: 160px;
    height: 40px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    text-transform: uppercase;
    color: #666;
    text-align: center;
    background: #eeeeee; /* Old browsers */
    background: -moz-linear-gradient(top, #eeeeee 0%, #cccccc 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(100%,#cccccc)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #eeeeee 0%,#cccccc 100%); /* IE10+ */
    background: linear-gradient(to bottom, #eeeeee 0%,#cccccc 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#cccccc',GradientType=0 ); /* IE6-9 */
    text-shadow: 1px 1px 0px #FFFFFF;
    letter-spacing: 3px;
}
.nav a:hover {
    background: #F4F4F4; /* Old browsers */
    background: -moz-linear-gradient(top, #F4F4F4 0%, #E0E0E0 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#F4F4F4), color-stop(100%,#E0E0E0)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #F4F4F4 0%,#E0E0E0 100%); /* IE10+ */
    background: linear-gradient(to bottom, #F4F4F4 0%,#E0E0E0 100%); /* W3C */
}
.nav a#first {
    border-radius: 5px 0px 0px 5px; 
    -moz-border-radius: 5px 0px 0px 5px; 
    -webkit-border-radius: 5px 0px 0px 5px;
}

.nav a#last {
    color: #09C;
    border-radius: 0px 5px 5px 0px; 
    -moz-border-radius: 0px 5px 5px 0px; 
    -webkit-border-radius: 0px 5px 5px 0px;
}
</style>
</head>
<body>

<div id="main-menu" class="nav">
    <a href="#" id="first">Home</a>
    <a href="#">Options</a>
    <a href="#">Prices</a>
    <a href="#">Showcase</a>
    <a href="#">Help</a>
    <a href="#" id="last">Order Now!</a>
</div>

</body>
</html>

这应该是您工作所需的全部内容......如果您在使用CSS布局时遇到问题,请查看YUI3网格。我是YUI 3的粉丝,所以是的,这是一个可耻的插件。

YUI Library

答案 3 :(得分:0)

看看这个:

http://jsfiddle.net/7veZQ/313/

该表格已转换为div + ul

查看line-height(此处用于垂直居中)。

另外,我将firstlast更改为classes(而非id's),因为它们是非常常见的名称,id's应该是唯一的文档。

最后,看看borders。我们在列表中没有border-collapse,因此last项目与其他项目略有不同。

相关问题