1

I am very new to coding. In my first try i am not able to set column width of table using CSS. I have created fiddle also, please help.Tried different methods but resulting in equal width of each column. Want to fix column width in table. Pl help.

Refer jsfiddle http://jsfiddle.net/h8LmU/14/

html code:

<table summary="other expenses" id="otherexpense_table">
        <col class="oc1" />
        <col class="oc2" />
        <col class="oc3" />
        <col class="oc4" />
        <col class="oc5" />
        <thead>
            <tr>
                <th align="left" colspan="5"><strong>DETAILS OF OTHER
            EXPENSES</strong>
                </th>
                </tr>
            <tr>
                <th align="center"><strong>Sl.
            No.</strong>
                </th>
                <th align="center"> <strong>Date/Time</strong>
                </th>
                <th align="center"> <strong>Details</strong>
                </th>
                <th align="center"> <strong>Amount</strong>
                </th>
                <th class="oremove" align="center"> <strong>Edit/Remove</strong>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr id="tr_other_01">
                <td align="center" id="tdosrno_01"></td>
                <td align="center" id="tdodate_01"></td>
                <td align="left" id="tdodetails_01"></td>
                <td align="center" id="tdoamount_01"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_01" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_01" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_02">
                <td align="center" id="tdosrno_02"></td>
                <td align="center" id="tdodate_02"></td>
                <td align="left" id="tdodetails_02"></td>
                <td align="center" id="tdoamount_02"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_02" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_02" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_03">
                <td align="center" id="tdosrno_03"></td>
                <td align="center" id="tdodate_03"></td>
                <td align="left" id="tdodetails_03"></td>
                <td align="center" id="tdoamount_03"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_03" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_03" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_04">
                <td align="center" id="tdosrno_04"></td>
                <td align="center" id="tdodate_04"></td>
                <td align="left" id="tdodetails_04"></td>
                <td align="center" id="tdoamount_04"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_04" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_04" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_05">
                <td align="center" id="tdosrno_05"></td>
                <td align="center" id="tdodate_05"></td>
                <td align="left" id="tdodetails_05"></td>
                <td align="center" id="tdoamount_05"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_05" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_05" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_06">
                <td align="center" id="tdosrno_06"></td>
                <td align="center" id="tdodate_06"></td>
                <td align="left" id="tdodetails_06"></td>
                <td align="center" id="tdoamount_06"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_05" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_05" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_07">
                <td align="center" id="tdosrno_07"></td>
                <td align="center" id="tdodate_07"></td>
                <td align="left" id="tdodetails_07"></td>
                <td align="center" id="tdoamount_07"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_07" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_07" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_08">
                <td align="center" id="tdosrno_08"></td>
                <td align="center" id="tdodate_08"></td>
                <td align="left" id="tdodetails_08"></td>
                <td align="center" id="tdoamount_08"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_08" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_08" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_09">
                <td align="center" id="tdosrno_09"></td>
                <td align="center" id="tdodate_09"></td>
                <td align="left" id="tdodetails_09"></td>
                <td align="center" id="tdoamount_09"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_09" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_09" value="Remove" />
                </td>
            </tr>
            <tr id="tr_other_010">
                <td align="center" id="tdosrno_010"></td>
                <td align="center" id="tdodate_010"></td>
                <td align="left" id="tdodetails_010"></td>
                <td align="center" id="tdoamount_010"></td>
                <td class="oremove">
                    <input type="button" id="tdotherbtedit_010" value="Edit" />&nbsp;
                    <input type="button" id="tdotherbtremove_010" value="Remove" />
                </td>
            </tr>
            <tr id="tr_othertotal" style="display:none;">
                <td colspan="3" align="right">Total 3:</td>
                <td id="tdothertotal" align="center"></td>
            </tr>
        </tbody>
    </table>

CSS code :

#otherexpense_table {
    table-layout: fixed;
    border: solid #001 2px;
    width: 850px;
}
#otherexpense_table.oc1 {
    width : 1%;
}
#otherexpense_table.oc2 {
    width : 80%;
}
#otherexpense_table.oc3 {
    width : 15%;
}
#otherexpense_table.oc4 {
    width : 1%;
}
#otherexpense_table.oc5 {
    width : 1%;
}
th
{
color : white;
background-color : #6C6CFF;
height : 25;
word-wrap:break-word;
font-size:11pt;
}
td
{
background-color : #CCCCCC;
font-size:10pt;
word-wrap:break-word;
}
3
  • jsfiddle.net/h8LmU/16 Commented May 21, 2014 at 10:04
  • Thanks a lot. What was the error. Commented May 21, 2014 at 10:08
  • You need to add a spaces between id and class like this: '#otherexpense_table .oc1' Commented May 21, 2014 at 14:40

2 Answers 2

2

Please remove the css

table-layout: fixed;

for detail plz go http://www.w3schools.com/cssref/pr_tab_table-layout.asp

Sign up to request clarification or add additional context in comments.

Comments

0
#otherexpense_table {
    table-layout: fixed;
    border: solid #001 2px;
    width: 850px;
}
#otherexpense_table .oc1 { // add spaces between '#otherexpense_table' and '.oc1'
    width : 1%;
}
#otherexpense_table .oc2 { // add spaces between '#otherexpense_table' and '.oc2'
    width : 80%;
}
#otherexpense_table .oc3 { // add spaces between '#otherexpense_table' and '.oc3'
    width : 15%;
}
#otherexpense_table .oc4 { // add spaces between '#otherexpense_table' and '.oc4'
    width : 1%;
}
#otherexpense_table .oc5 { // add spaces between '#otherexpense_table' and '.oc5'
    width : 1%;
}
th
{
color : white;
background-color : #6C6CFF;
height : 25;
word-wrap:break-word;
font-size:11pt;
}
td
{
background-color : #CCCCCC;
font-size:10pt;
word-wrap:break-word;
}

JSFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.