Column Width For Not Working - Stack Overflow

Just browsing Stack Overflow? Help us improve your experience. Sign up for research
    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs Column width for <th> not working Ask Question Asked 10 years, 2 months ago Modified 10 years, 2 months ago Viewed 76k times 15

Here is my html:

<html> <head> <meta charset="utf-8"> <link href="css/bootstrap.css" rel="stylesheet"> <link href="css/bootstrap-theme.css" rel="stylesheet"> </head> <body style="padding-top: 47px;"> <table class="table table-hover table-striped-custom"> <thead> <tr> <th style="width: 5px;"></th> <th>Column2</th> <th>column2</td> </tr> </thead> <tbody> <tr> <td style="background-color: #FF5F5F;width: 5px;"></td> <td>blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td> <td>bla</td> </tr> <tr> <td style="background-color: deepskyblue"></td> <td>bla</td> <td>bla</td> </tr> </tbody> </table>

Problem is when setting width for first column: it won't go under 16px. If I put bigger width(20,50), colored column become larger, but when I try to set them thinner (for example 7px), It doesn't take any effect. How can I do it, without removing any css class from existing template. Colored column have to be first, it's height must be as row's height and I have to be able to set it's width to any value I want.

Share Improve this question Follow edited Sep 15, 2014 at 14:50 j08691's user avatar j08691 208k32 gold badges267 silver badges280 bronze badges asked Sep 15, 2014 at 14:47 Error's user avatar ErrorError 8251 gold badge19 silver badges33 bronze badges 3
  • Seems to work here jsfiddle.net/mendesjuan/qq3L0o77. Oops nevermind, it breaks after you add bootstrap jsfiddle.net/mendesjuan/qq3L0o77/1 – Ruan Mendes Commented Sep 15, 2014 at 14:59
  • something like this? – Litestone Commented Sep 15, 2014 at 15:04
  • @Litestone Read my comment, the problem happens when you add bootstrap – Ruan Mendes Commented Sep 15, 2014 at 15:10
Add a comment |

2 Answers 2

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 10

It's because your bootstrap css is adding 8px padding to the table cells (which is why your min width is 16px: 8px left plus 8px right) - try adding padding:0; for those cells and it should work

Example

Share Improve this answer Follow answered Sep 15, 2014 at 14:58 Pete's user avatar PetePete 58.3k29 gold badges129 silver badges183 bronze badges 3
  • Note that to add it in a CSS section will require a lot of specificity since bootstrap uses .table>thead>tr>td – Ruan Mendes Commented Sep 15, 2014 at 15:15
  • @JuanMendes As OP is using inline styles, they should override the stylesheet styles, otherwise yes they will need to be more specific than the css in the bootstrap – Pete Commented Sep 15, 2014 at 15:18
  • That's what I said, if the OP is going to move to using best practices, they'll need to use high specificity. I never said what you have doesn't work, but I'm sure we agree it's not the best way to do things. – Ruan Mendes Commented Sep 15, 2014 at 15:20
Add a comment | 4

It's possible that bootstrap has set min-width on th or td. If so, I'd add an additional style block (in the HTML, if you can't add/edit external CSS), to allow the first column to be as small as you like:

<style type="text/css"> .table td:first-child, .table th:first-child { min-width: 0; padding: 0; } </style> Share Improve this answer Follow answered Sep 15, 2014 at 14:59 Paul Roub's user avatar Paul RoubPaul Roub 36.4k27 gold badges85 silver badges93 bronze badges Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • Your docs are your infrastructure
  • Featured on Meta
  • More network sites to see advertising test [updated with phase 2]
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...
0 Unable to Fix the width of colum in bootstrap 0 Bootstrap column width 1 html : set column width 0 Style width selector of column 2 Bootstrap Col & Td width 1 Bootstrap Col width 0 Td widths not working 1 table not respecting column width properly 0 Bootstrap css,how to reduce the width of "th" and "td"? 1 Bootstrap Table Column width not getting

Hot Network Questions

  • Group cohomology valued in a bimodule
  • Trump's tariff plan
  • Can you please advise on kerning?
  • Meaning of "I love my love with an S—" in Richard Burton's "Arabian Nights"
  • Solving Large size problems in industry: Tips and Tricks
  • How can I politely decline a request to join my project by a free rider professor
  • Angular orientation of exact solution of the Hydrogen Schrödinger Equation
  • What is this Stardew Valley item?
  • What is another word for when someone’s statement lacks integrity or meaning?
  • Should sudo ask for root password?
  • Publishing corollaries of previously published results
  • Rational divisors on Calabi–Yau threefolds
  • Can one publication contribute to two separate grants?
  • Is it problematic to use percentages to describe a sample with less than 100 people?
  • Table structure with multiple foreign keys and values
  • Can I find the inverse of a polynomial directly in its NTT form?
  • What powers do police have to force people onto trains?
  • Can a German citizen visit Shenzhen for 6 days and go to Hong Kong for a day without a visa?
  • What is this insect found in an apartment in Brazil?
  • What is small arch between two notes and how to play it?
  • Why is it safe to soak an electric motor in isopropyl alcohol but not distilled water?
  • Student is almost always late, and expects me to re-explain everything he missed
  • Schrödinger's cat ++
  • In GR, what is Gravity? A force or curvature of spacetime?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Th Set Column Width