简体   繁体   English

HTML表格具有100%的宽度,但TD越来越大?

[英]Html Table with 100% width but with growing TD?

I have a table which its width is 100%; 我有一张桌子,它的宽度是100%;

I have 2 TDs. 我有2个TD。

在此处输入图片说明

However I want the second td to be near to the left end. 但是,我希望第二个td靠近left ( right after the ccccccc...) (在ccccccc之后...)

There is a solution which uses 1 more td which its width is 100%. 有一种解决方案 ,使用了多于1的td,其宽度为100%。

Something like 就像是

<table id="mytable"style="width:100%;background:red"><tr>
    <td>TEXT1</td>
    <td>TEXT2</td>
    <td style="width:100%;background:blue">&nbsp;</td>
    </tr></table>

But , I was wondering if there's another solution without another TD ? 但是,我想知道是否还有没有其他TD的解决方案?

Try this: http://jsfiddle.net/Rrkky/144/ Does exactly what you're asking for. 试试这个: http : //jsfiddle.net/Rrkky/144/确实满足您的要求。

HTML 的HTML

<table id="mytable"style="width:100%;background:red">
    <tr>
    <td class="firstcell">aaaa</td>
    <td>TEXT2</td>
    </tr>
    <tr>
    <td class="firstcell">bbbbbbb</td>
    <td>TEXT2</td>
    </tr>
    <tr>
    <td class="firstcell">ccccccccccccccc</td>
    <td>TEXT2</td>
    </tr>
</table>

CSS 的CSS

#mytable td {
    width:50px;
    background:green
}

#mytable td.firstcell {
    background:red;
    width:1%;
}

What about this ? 那这个呢 ?

<table id="mytable"style="width:100%;background:red">
    <tr>
        <td>aaa</td>
        <td width="100%">Royi</td>
    </tr>
    <tr>
        <td>bbbbbb</td>
        <td width="100%">Royi</td>
    </tr>
    <tr>
        <td>cccccccccccccccc</td>
        <td width="100%">Royi</td>
    </tr>
</table>

http://jsfiddle.net/rjsAG/ http://jsfiddle.net/rjsAG/

Just do not add the last TD but use width:100% for the second one 只是不添加最后一个TD而是将width:100%用于第二个TD

CSS 的CSS

tr td:not(:first-of-type){
    width:100%
}

or 要么

tr td{
    width:100%
}
tr td:first-child{
    width:1%
}

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

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