Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

867 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

21 Experts available now in Live!

Get 1:1 Help Now