skip to Main Content

<td style="text-align:center"> is great, but let’s say I need to do 1000 of them,
and … I am not allowed to use stylesheets.
So what can I put in <table style="what"> that will let me just use just <td>‘s with no attributes?

3

Answers


  1. Chosen as BEST ANSWER

    Use

    <table border="1" style="text-align: center;">
    

    It worked. I don't know why. Chrome browser rendering:

    chrome rendering

    of HTML:

     <table border="1" style="text-align: center;">
      <tr>
       <th>Flight</th>
       <td>HX657/CRK657</td>
       <td>HX641/CRK641</td>
      </tr>
    
      <tr>
       <th>Registration</th>
       <td>B-LND</td>
       <td>B-LHI</td>
      </tr>
    
      <tr>
       <th>Origin</th>
       <td>OKA/Okinawa</td>
       <td>FUK/Fukuoka</td>
      </tr>
    
      <tr>
       <th>Destination</th>
       <td colspan="2">HKG Hong Kong</td>
      </tr>
    
      <tr>
       <th>Aircraft</th>
       <td colspan="2">Airbus 330-343</td>
      </tr>
    
      <tr>
       <th>Altitude (ft)<br></th>
       <td>38000</td>
       <td>40000</td>
      </tr>
     </table>
    

    OK, it works for the special case of style="text-align: center;". I didn't test it for the general case.


  2. If you cannot use styles tag, you cannot. You will need to inline the style attribute to ALL TDs.

    If you are not allowed to use a CSS file, but can still add HTML, you could add styles inline.

    you could do this:

    <style>
    #myTable td{
    border:1px solid black;
    }
    </style>
    <table id="myTable">
    ...
    </table>
    
    Login or Signup to reply.
  3. You cannot. The style attribute affects only the element it’s on and contains no selectors. Is an inline <style></style> tag possible, rather than an external stylesheet file?

    For e-mail, especially older or strict clients that don’t support the tag, tools such as this "CSS inliner" were created.

    It looks through a <style></style> tag and will add a style attribute to all tags that match the selectors.

    For example, this:

    <style>
    p { color: red; }
    a { color: green; }
    </style>
    
    <p>Visit 
    <a href="https://example.com">a website</a> 
    to read things.</p>
    

    Renders as:

    <p style="color: red;">Visit 
    <a href="https://example.com" style="color: green;">a website</a> 
    to read things.</p>
    

    Note that some things that are possible in stylesheets, such as a:hover{}, can’t be expressed in a style attribute.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search