Solved

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

Posted on 2013-01-17
2
328 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now