Solved

How do I apply <td> (column) widths as a % of a table width in HTML5 using CSS3?

Posted on 2013-01-17
2
337 Views
Last Modified: 2013-01-22
Hi:

I'm in the middle of coming up to speed with HTML5.
I'm having issues applying a css3 style (via class) to a <td>.

I'm basically trying to do a "flow/responsive" layout where the columns
widths are a % of the table.

What I'd like to do is have Col1 and Col2 be a fixed % of the table width,
while Col3 and Col4 use the remaing width as needed.

My Css3 styles look like:
---------------------------------

div.Wrapper{
        background-color: yellow;
       width: 96%;
}
table{
        border: 3px solid black;
        background-color: aquamarine;
        font-size: .75em;
        width: 98%;
}

thead {
        border: 3px solid black;
        font-weight: bold;
        text-decoration: underline;
        text-align: center;
        color: yellow;
}

td {
        border: 3px solid black;
        background-color: orange;
}

td.Col1{
    width: 39.583%;
    font-height: 30px;
    color: aquamarine;
}

td.Col2 {
    width: 5.20833%;
    font-height: 16px;
    color: green;
}




My html looks like:
---------------------------
<div class='Wrapper'>
<table>
   <thead>
      <tr>
         <td class='col1'>Col 1</td>
         <td class='col2'>Col 2</td>
         <td class='col3'>Col 3</td>
         <td class='col4'>Col 4</td>
      </tr>
   </thead>

   <tbody>
    <tr>
         <td class='col1'>Col 1 Value</td>
         <td class='col2'>Col 2 Value</td>
         <td class='col3'>Col 3 Value</td>
         <td class='col4'>Col 4 Value</td>
      </tr>
    <tr>
         <td class='col1'>Col 1 Value</td>
         <td class='col2'>Col 2 Value</td>
         <td class='col3'>Col 3 Value</td>
         <td class='col4'>Col 4 Value</td>
      </tr>
   </tbody>

</table>
</div>
0
Comment
Question by:jxbma
  • 2
2 Comments
 
LVL 30

Accepted Solution

by:
LZ1 earned 500 total points
ID: 38788765
Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
div.Wrapper{
        background-color: yellow;
       width: 96%;
}
table{
        border: 3px solid black;
        background-color: aquamarine;
        font-size: .75em;
        width: 98%;
		table-layout:fixed;
}

thead {
        border: 3px solid black;
        font-weight: bold;
        text-decoration: underline;
        text-align: center;
        color: yellow;
}

td {
        border: 3px solid black;
        background-color: orange;
}

td.col1{
    width: 39.583%;
    font-height: 30px;
    color: aquamarine;
}

td.col2 {
    width: 5.20833%;
    font-height: 16px;
    color: green;
}
</style>
</head>

<body>
	<div class='Wrapper'>
<table>
   <thead>
      <tr>
         <td class='col1'>Col 1</td>
         <td class='col2'>Col 2</td>
         <td class='col3'>Col 3</td>
         <td class='col4'>Col 4</td>
      </tr>
   </thead>

   <tbody>
    <tr>
         <td class='col1'>Col 1 Value</td>
         <td class='col2'>Col 2 Value</td>
         <td class='col3'>Col 3 Value</td>
         <td class='col4'>Col 4 Value</td>
      </tr>
    <tr>
         <td class='col1'>Col 1 Value</td>
         <td class='col2'>Col 2 Value</td>
         <td class='col3'>Col 3 Value</td>
         <td class='col4'>Col 4 Value</td>
      </tr>
   </tbody>

</table>
</div>

</body>
</html>

Open in new window


The only thing standing in your way is the capitalization of your CSS classes. CSS is case sensitive.
0
 
LVL 30

Expert Comment

by:LZ1
ID: 38805622
Any updates?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question