Style CSS Table Td - Stack Overflow
Có thể bạn quan tâm
-
- Home
- Questions
- Tags
- Users
- Companies
- Labs
- Jobs
- Discussions
- Collectives
-
Communities for your favorite technologies. Explore all Collectives
- Teams
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Try Teams for free Explore Teams - Teams
-
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 CollectivesTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsGet early access and see previews of new features.
Learn more about Labs Style CSS table td Ask Question Asked 13 years, 5 months ago Modified 5 years, 10 months ago Viewed 33k times 4My site allows users to generate tables with PHP. The number of rows and cells is variable but the number of columns is always fixed. The table usually generates two digit numbers. When the table generates three digit numbers the entire table expands to accommodate this and the size of the table increases, ruining my layout. Is there a way to use CSS and style this table's tds so that the table doesn't change size when 3 digit numbers are generated. (3 digits are the longest). I tried adding padding to the table, but its not working.
Also, should I use an id in table or class?
Share Improve this question Follow edited Jan 23, 2019 at 22:51 Brian Tompsett - 汤莱恩 5,87572 gold badges60 silver badges133 bronze badges asked Jun 26, 2011 at 19:37 user780483user780483 3,03310 gold badges30 silver badges32 bronze badges 0 Add a comment |3 Answers
Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 11 td { width: 50px; }I think something like that might work for you. Obviously, you can adjust the actual width to your needs.
And if you multiple table and only want to fix one, give the one in question an id:
<table id="fixed_table">
and then in the css, you could say:
#fixed_table td { width: 50px; }and it would only affect tds in that particular table. Of course, if you wanted to affect some tables but not others, you would use a class instead of an id.
Share Improve this answer Follow answered Jun 26, 2011 at 19:47 jpmjpm 3,16518 silver badges24 bronze badges Add a comment | 3You could use a combination of width and max-width:
td { border: 1px solid #ccc; width: 2em; /* or whatever... */ max-width: 2em; /* or whatever... */ height: 2em; /* or whatever... */ line-height: 2em; /* or whatever... */ text-align: center; /* a personal aesthetic choice... */ overflow: hidden; /* to prevent overflow... */ }JS Fiddle demo.
(Please note that while I use jQuery in the demo, that's only to generate contents and isn't necessary for the demo to work.)
Share Improve this answer Follow answered Jun 26, 2011 at 19:48 David ThomasDavid Thomas 253k53 gold badges381 silver badges417 bronze badges Add a comment | 2Set fixed widths on the columns.
Share Improve this answer Follow answered Jun 26, 2011 at 19:40 joakimdahlstromjoakimdahlstrom 1,5851 gold badge11 silver badges25 bronze badges 1- Yes. either you set it to all columns, like td {width:100px;} or to a class that you give to a specific one, like .col {width:100px;}. – joakimdahlstrom Commented Jun 26, 2011 at 19:53
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 discardedSign up or log in
Sign up using Google Sign up using Email and Password SubmitPost as a guest
Name EmailRequired, but never shown
Post Your Answer DiscardBy 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...
Related
0 CSS styling table tds 0 Html Table styles 1 CSS Style for Table 0 Styling table with CSS 2 Styling table issue 0 CSS - Styling table 1 Css for table td 1 HTML/CSS Table style 0 How to set <table> / <td> styles in HTML? 1 Table td style for CSSHot Network Questions
- How can I solve my equation with the best numerical precision?
- Identifying parts of multipart line in QGIS
- Inheritance Tax: the Estate or the Beneficiaries?
- Schrödinger's cat ++
- Beta sensitivity of the collector current
- Cauchy-Schwarz divergence between multivariate normal distributions
- Is William Dembski’s argument for Intelligent Design self undermining?
- How do I add a trusted check constraint quickly
- C# basic calculator
- Movie about a post apocalyptic world with a scorching hot sun
- Does "bustle about" mean the same thing as "fluster about"?
- How to attribute authorship to personal non-academic friend who made significant contributions
- Plotting wavy curve in Mathematica
- What is the pronunciation of these nikkud?
- How to generate conditions before evaluating integral
- Why don't routers answer ARP requests for IP addresses they can handle even if they aren't assigned that IP address themselves?
- Does synonymy seep down to the fragments of theories?
- Who can be proud of whom? Is there any limit?
- Can you use RS-422 to transmit a clock
- Infinite series and sum of two squares
- See me Once, See me Twice #16
- How can I protect ungrouted tile over the winter?
- will a laptop battery that stay more time connected with charger , be damaged?
- Do referees get to see each other's reports?
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
defaultTừ khóa » Html Td Style Css
-
CSS Styling Tables - W3Schools
-
HTML Td Tag - W3Schools
-
Styling Tables - Learn Web Development | MDN
-
HTML Td Style Attribute - Dofactory
-
A Complete Guide To The Table Element | CSS-Tricks
-
How To Style A Table With CSS | DigitalOcean
-
How Do I CSS Style A Table That Affects TD As Well? - Stack Overflow
-
HTML And CSS Tutorial: How-To's And Miscellaneous
-
17 Tables - W3C
-
Creating Beautiful HTML Tables With CSS - DEV Community
-
HTML Tables - W3Schools
-
How To Style A Table With CSS | Webucator
-
Add Style To Specific Columns Or Rows In Your Table App
-
How To Set Fixed Width For
In A Table ? - GeeksforGeeks Copyright © 2022 | Thiết Kế Truyền Hình Cáp Sông Thu