Solved

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

Posted on 2013-01-17
2
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Suggested Courses

615 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