Center Text Of Table Data Connected With Colspan="2" With .css ...

    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 center text of table data connected with colspan="2" with .css " Select td with attribute colspan="2" " Ask Question Asked 10 years, 4 months ago Modified 7 years ago Viewed 74k times 26

Hi I have a table where certain columns in a row are connected with the colspan="2" attribute.

In the moment it looks like this:

enter image description here

I want that the text of the connected columns in a row is centered, but only the text in the connected columns

The table data of this row (unlimited ) has the following code

<tr class="row-4 even"> <td colspan="2" class="column-3 footable-last-column" style="display: table-cell;">unlimited</td> </tr>

I can not change the code of the table because it is automatically created by the Wordpress plugin tablepress

What I can do is to add a custom .css file.

My Question is, if it is possible to select only the table data with the attribute colspan="2" with .css, so that I can do { text-align: center } only for table data with the attribute colspan="2"

Share Improve this question Follow asked Aug 31, 2014 at 17:42 Viktor Carlson's user avatar Viktor CarlsonViktor Carlson 1,0081 gold badge20 silver badges39 bronze badges 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) 37

The CSS selector [attribute="value"] is what you want, so you should add

td[colspan="2"] { text-align: center; }

to center the cell that spans two columns.

If you want to center cells that span any number of columns, you can use

td[colspan]:not([colspan="1"]) { text-align: center; }

to select all cells that have a colspan attribute set to a value other than 1.

Share Improve this answer Follow edited Dec 14, 2017 at 17:20 answered Aug 31, 2014 at 17:50 JackW's user avatar JackWJackW 99911 silver badges22 bronze badges 1
  • what if i am USING Div and tr class which convert that div to TR tag how to add colspan for div tag which refer as TR – ravipatel Commented Jan 9, 2023 at 21:40
Add a comment | 22

This should do the trick if you are applying the CSS inline:

<td colspan="2" style="text-align:center;">unlimited</td> Share Improve this answer Follow answered Nov 27, 2015 at 4:08 Dut A.'s user avatar Dut A.Dut A. 1,15811 silver badges23 bronze badges 1
  • what if i am USING Div and tr class which convert that div to TR tag how to add colspan for div tag which refer as TR – ravipatel Commented Jan 9, 2023 at 21:41
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
  • The ghost jobs haunting your career search
  • Breaking up is hard to do: Chunking in RAG applications
  • Featured on Meta
  • The December 2024 Community Asks Sprint has been moved to March 2025 (and...
  • Stack Overflow Jobs is expanding to more countries

Linked

0 Horizontally Centering text inside a table 361 How to center the contents of an HTML table? 1 Centering a two column table with CSS 0 Center text in HTML table 0 How can I center the text in a table? 0 Horizontally Centering text inside a table 1 Center the text in a row of an HTML table 2 Html Table : td data to be center. vertically and horizontally 0 Centering a column in a table 1 Center Text in Table column 1 CSS Styling - Can't centre text in a table

Hot Network Questions

  • How do you remove this T4 G9-pin light bulb from this Kichler pendant light?
  • Is it important to account for transient voltage when designing an electric circuit?
  • What is the angle?
  • Is mathematics just "a part of physics", as stated by Arnold in 1997?
  • Does buddhist Tripitaka or Sutta literature mention Vishnu or Shiva?
  • The global wine drought that never was (title of news text that seems like truncated at first sight)
  • Citing volatile sources
  • Charge position in 7-norbornyl cation?
  • Practicality of weaponizing civilian container ships
  • 2012 vs 2022 Chevrolet Vehicle and Coolant Consumption
  • Relationship related to sum of squared deviations
  • How to make an iron star visually appealing
  • Maximum possible speed of Mechas?
  • How to place a heavy bike on a workstand without lifting
  • What movie has a classroom clock tick backwards?
  • Name that logic gate!
  • Can i travel to India if my passport expires in 25 March 2025?
  • How to report abuse of legal aid services?
  • Conditional anchor positioning based on pgf keys
  • Could We Tackle a DIY Bathroom Renovation to Fix Previous Owner’s Quick Fixes?
  • \colorstretch from chickenize does not work anymore
  • When interpreting results, should I report the coefficient for the quadratic term in a regression as-is or report the square root?
  • Draw a TikZ picture with forces and a rope
  • Why does energy stored in a capacitor increase with the square of voltage?
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 Colspan Align Center