td width is 162px even though style="width:25px" for td and th
I've put this in my css file
table, td, th {
border: 1px solid black;
}
table {
border-collapse:collapse;
}
table.narrow th, td {
width:50px;
}
It doesn't work. The last one there is supposed to take a table with class="narrow" and make all its descendent th and td elements 50px wide. And chrome shows Matched CSS Rules:
.narrow th, td { width: 50px; }
So chrome is reading it and ignoring it? Or CSS is just idiotic? Or I am? Why can't CSS just do what you tell it, like a normal programming language?
SO, I tried putting style="width:25px" right in the 1st column td AND th tags and still, doesn't work. Chrome shows:
element.style { width:25px; }
but it won't tell me why the hell it's displaying it at 162px.
Anyone have any clues? Thank you.
Edit: Kolink gave me the clue I needed. Form text fields inside the tags were causing a large minimum width. I added this style to shrink the table:
.narrow input{
width:80px;
}
It reduced the width of all the inputs inside the class="narrow" table and hence reduced the width of the table.
To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.
By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.
The HTML <td> width Attribute is used to specify the width of a table cell. If width attribute is not set then it takes default width according to content. Attribute Values: pixels: It sets the width of table in terms of pixels.
Just add the property : white-space: nowrap; to your table or the cells you want to have dynamic width. That's it!
Set table-layout: fixed;
on the table's styles. Otherwise table layout is loose and width
is treated more like min-width
.
Your definition is for all TDs
table.narrow th, td {
width:50px;
}
You have to repeat the affected element in the enumeration
table.narrow th, table.narrow td {
width:50px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With