td宽度,不工作? [英] td widths, not working?

查看:74
本文介绍了td宽度,不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这里的代码:

 < table& 
< tr>
< td width =200pxvalign =top>
< div class =left_menu>
< div class =menu_item>
< a href =#>首页< / a>
< / div>
< / div>
< / td>
< td width =1000pxvalign =top>内容< / td>
< / tr>
< / table>

  .left_menu {
background:none repeat scroll 0 0#333333;
border-radius:5px 5px 5px 5px;
font-family:Arial,Helvetica,sans-serif;
font-size:12px;
font-weight:bold;
padding:5px;
}

.menu_item {
background:none repeat scroll 0 0 #CCCCCC;
border-bottom:1px solid#999999;
border-radius:5px 5px 5px 5px;
border-top:1px solid #FFFFCC;
cursor:pointer;
padding:5px;
}

它在我的浏览器上正常工作,我已经测试它在每个浏览器和PC,但有人抱怨 td width 200不断变化宽度。我不知道他在说什么。有人知道为什么他或她看到 td

解决方案

它应该是:

 < td width =200> 

 < td style =width:200px> 

请注意,如果您的单元格包含某些不适合200像素的内容$ c> somelongwordwithoutanyspaces ),单元格将伸展,除非你的CSS包含 table-layout:fixed b
$ b

EDIT



正如kristina childs在她的回答中指出的,你应该避免 width 属性并使用内联CSS(使用 style 属性)。这是一个很好的做法,尽可能分离风格和结构。


So I have this code here:

<table>
    <tr>
        <td width="200px" valign="top">
            <div class="left_menu">
                <div class="menu_item">
                    <a href="#">Home</a>
                </div>
            </div>
        </td>
        <td width="1000px" valign="top">Content</td>
    </tr>
</table>

with the CSS

.left_menu {
    background: none repeat scroll 0 0 #333333;
    border-radius: 5px 5px 5px 5px;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 12px;
    font-weight: bold;
    padding: 5px;
}

.menu_item {
    background: none repeat scroll 0 0 #CCCCCC;
    border-bottom: 1px solid #999999;
    border-radius: 5px 5px 5px 5px;
    border-top: 1px solid #FFFFCC;
    cursor: pointer;
    padding: 5px;
}

It works fine on my browser and I have tested it in every browser both mac and PC, but someone is complaining that the td with the width of 200 keeps changing width. I have no idea what he is talking about. Does anyone know why he or she is seeing the width change on the td?

解决方案

It should be:

<td width="200">

or

<td style="width: 200px">

Note that if your cell contains some content that doesn't fit into the 200px (like somelongwordwithoutanyspaces), the cell will stretch nevertheless, unless your CSS contains table-layout: fixed for the table.

EDIT

As kristina childs noted on her answer, you should avoid both the width attribute and using inline CSS (with the style attribute). It's a good practice to separate style and structure as much as possible.

这篇关于td宽度,不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆