Unable To Create Text Color Within Tag In Html And CSS

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 Unable to create text color within <th> tag in html and CSS Ask Question Asked 3 years, 8 months ago Modified 3 years, 8 months ago Viewed 1k times 0

I am trying to color Name and Salary in white within <th> tag. Also need background color for <th> is green. I have done background color in green but unbale to color my text in white. My code is given below:

<table style="width:90%"; border= 1px solid black;> <tr> <th style="background-color:#0C7D18"; colspan="2">Name</th> <th style="background-color:#0C7D18";>Salary</th> </tr> </table>

Unable to create text color for Name and Salary in white within <th> tag.

Share Improve this question Follow edited Mar 19, 2021 at 9:32 Ali Esmailpor's user avatar Ali Esmailpor 1,2013 gold badges12 silver badges23 bronze badges asked Mar 15, 2021 at 19:01 Shaon Paul's user avatar Shaon PaulShaon Paul 1531 gold badge4 silver badges16 bronze badges 4
  • 5 You should use "color" to change color of your text – Evren Commented Mar 15, 2021 at 19:03
  • <table style="width:90%"; border= 1px solid black;> <tr> <th style="background-color:#0C7D18;color:#FFF;" colspan="2">Name</th> <th style="background-color:#0C7D18;color:#FFF">Salary</th> </tr> – KodeFor.Me Commented Mar 15, 2021 at 19:06
  • Its works perfect. Great Thanks – Shaon Paul Commented Mar 15, 2021 at 19:07
  • 1 Does this answer your question? Change color of text using css – Heretic Monkey Commented Mar 15, 2021 at 19:11
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) 1

You have more problems than just the header color and background. Your table element syntax is wrong.

  • Remove the quote after 90%
  • Replace the = after border with a colon :
  • Put quote after the end of your style black;">
  • Add white to your headers color:#FFFFFF;

I revised the markup to include the thead and tbody and added some rows to allow a clear visual of the results.

I also put a second example in using CSS which for many circumstances is a better way to style things than in-line. For example if you have 10 header you would only need one place to change it not 10, and makes the markup a bit cleaner.

<table style="width:90%; border:1px solid black;"> <thead> <tr> <th style="background-color:#0C7D18; color:#FFFFFF" colspan="2">Name</th> <th style="background-color:#0C7D18; color:#FFFFFF">Salary</th> </tr> </thead> <tbody> <tr> <td>one</td> <td>two</td> <td>three</td> <td>up the</td> <td>hill</td> </tr> </tbody> </table>

.my-table { width: 90%; border: 1px solid black; } .my-header { background-color: #0C7D18; color: #FFFFFF; } <table class="my-table"> <thead> <tr> <th class="my-header" colspan="2">Name</th> <th class="my-header">Salary</th> </tr> </thead> <tbody> <tr> <td>one</td> <td>two</td> <td>three</td> <td>up the</td> <td>hill</td> </tr> </tbody> </table>

Share Improve this answer Follow answered Mar 18, 2021 at 12:18 Mark Schultheiss's user avatar Mark SchultheissMark Schultheiss 34.1k12 gold badges72 silver badges107 bronze badges Add a comment | 1

background-color is used to set the color of the background.

Use color to target text color;

<table style="width:90%"; border= 1px solid black;> <tr> <th style="color:white; background-color:#0C7D18"; colspan="2">Name</th> <th style="color:white; background-color:#0C7D18";>Salary</th> </tr>

Share Improve this answer Follow answered Mar 15, 2021 at 19:09 0stone0's user avatar 0stone00stone0 42.9k5 gold badges50 silver badges78 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...

Linked

2 Change color of text using css 1 changing html text colors with css 0 I Have a CSS text colour problem 3 color text in html code 2 Style <th> with classes in CSS 0 text color not changing in html 0 CSS text not changing color 2 Changing text color in html doesen't work 0 Trying to get the color to show 1 Two different colors in the same text by using html and css 1 HTML giving an issue when I try to make a color changing text CSS

Hot Network Questions

  • Bash builtin 'command' ignoring option '-p'
  • What is this Stardew Valley item?
  • Do I need Letter of invitation to Iceland?
  • Publishing corollaries of previously published results
  • Why gap between arrow-head and smooth line
  • If "de-" means "down" or "off" and "sub-" means "under", what is the latin prefix- meaning "up"?
  • What powers do police have to force people onto trains?
  • Spellcheck I Before E
  • How can I solve my equation with the best numerical precision?
  • Why don't routers answer ARP requests for IP addresses they can handle even if they aren't assigned that IP address themselves?
  • Can you please advise on kerning?
  • Can the US President and Vice President swap places to avoid 22nd Amendment?
  • Table structure with multiple foreign keys and values
  • Does "binary" affect our Being?
  • Angular orientation of exact solution of the Hydrogen Schrödinger Equation
  • Groups with no proper non-trivial fully invariant subgroup
  • How do different observers decide if they are looking at the same thing?
  • Creating table from polygon or closed polylines in QGIS
  • Path from plane
  • What would T-Rex cavalry be used for?
  • "Eligible" vs "Elected" in the drafting of the 22nd amendment
  • Function works when evaluated in the `*scratch*` buffer, but not when evaluated in an Org Source Block. Why?
  • Why is Anarchism not considered fundamentally against the "democratic order" in Germany?
  • Static vs dynamic certificate pinning
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 Colors