Solved

TD padding

Posted on 2011-09-13
11
330 Views
Last Modified: 2012-05-12
I have one table that I want the style to have padding of 3 points on all 4 points. If I put this in the td style, it works. If I put it in a class and add it to the td coding, it doesn't. If I put it in a style and add to coding, it doesn't. HOw do I fix this?

Doesn't work:
 <td valign="top" align="left" width="100%" style="padding: 3px 3px 3px 3px;">

Open in new window


doesn't work:
<td valign="top" align="left" class="tdHome">

Open in new window


.tdHome td
{
    vertical-align: top;
    padding: 3px 3px 3px 3px;
}

or 

#tdHome td
{
    vertical-align: top;
    padding: 3px 3px 3px 3px;
}

Open in new window


Does work:
td
{
    vertical-align: top;
    padding: 3px 3px 3px 3px;
}

Open in new window


But I don't want to put it in the 'td' because I only want the padding for THIS table, not for every table.

thanks.
0
Comment
Question by:Starr Duskk
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 16

Assisted Solution

by:SSupreme
SSupreme earned 250 total points
ID: 36533238
if this: <td valign="top" align="left" class="tdHome"> try this: .tdHome {vertical-align: top; padding: 3px 3px 3px 3px;}
or td .tdHome {vertical-align: top; padding: 3px 3px 3px 3px;} ;
last one is inefficient selector
0
 
LVL 7

Assisted Solution

by:Ironhoofs
Ironhoofs earned 125 total points
ID: 36535450
Like SSupreme said, its an notation problem:

.tdHome  //refers to elements with class="tdHome"
#tdHome //refers to a element with id="tdHome"

The difference between ID and CLASS is that ID should be unique inside the webpage, while a class can be used multiple times.

.tdHome TD // refers to any TD inside a element with class="tdHome"

Example:

<table>
  <tr>
    <td class="tdHome">
      <table>
        <tr><td>.tdHome TD changes this</td></tr>
        <tr><td>.tdHome TD changes this too]</td></tr>
    </table>
  </td>
</tr>
</table>
0
 
LVL 8

Expert Comment

by:MelMc
ID: 36537138
Also, if you specifically want 3px and no more, you should add cellPadding="0" within your <table> tag
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 2

Author Comment

by:Starr Duskk
ID: 36537530
Sorry. I failed to mention I had already tried that, and I just tried it again. It doesn't work. This is what I have:

td
{
    margin: 0;
    padding: 0;
    border: 0;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline;
    vertical-align: top;
    text-align: left;
    font-weight: normal;
}

.tdHome
{
        text-align: left;
    vertical-align: top !important;
    padding: 3px 3px 3px 3px !important;
}

Open in new window


Here is my table:
                    <table width="1075px" >
                        <tr>
                            <td valign="top" align="left" class="tdHome">
                                <div id="swishmenu">
                                    <uc:MenuPanelBar ID="MenuPanelBar" runat="server" />
                                    <asp:Label ID="lblError" runat="server"></asp:Label>
                                </div>
                            </td>
                            <td valign="top" align="left" width="100%"  class="tdHome">
                                <div class="swishtext">
                                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                                    </asp:ContentPlaceHolder>
                                </div>
                            </td>
                            <td valign="top" align="center" width="15"  class="tdHome">
                                <asp:Panel ID="panPrintablePage" runat="server">
                                    <uc:PrintablePageIcon ID="PrintablePageIcon" runat="server" />
                                </asp:Panel>
                            </td>
                        </tr>
                    </table>

Open in new window

0
 
LVL 16

Assisted Solution

by:SSupreme
SSupreme earned 250 total points
ID: 36537868
This work as you want, I tested it:
.tdHome
{
    vertical-align: top;
    padding: 3px 3px 3px 3px;
}
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 36538210
As I indicated. It simply is not working with my code.

It only works if I put those values in the "td" CSS, and then it applies to every table, not just the on table. My .tdHome class does not override or do anything. It's as though it doesn't exist. It only does with the "td" does.

Oh well. Thanks to everyone anyway.
0
 
LVL 8

Assisted Solution

by:MelMc
MelMc earned 125 total points
ID: 36538244
In the original example you named your class .tdHome td
This naming convention will apply the styling to all of the <td> tags that come after any element with the class .tdHome. If you want to apply styling to the element with the class tdHome reference it in your style sheet as .tdHome or TD.tdHome
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 36538599
Yes, I did in my original example, and Ironhoofs explained that. Thanks both of you for the explanation. Sadly, it doesn't help my situation.

But in my next example, I indicated that I failed to mention that I had already tried .tdHome by itself, and I again demonstrated the example code I am using showing that I used class="tdHome" and the CSS.

So yes, I've tried what the final recommendations are, shown the source code, and it isn't working for me. So I don't know why mine is failing. It should work. That's what I had tried in the first place, but after trying everything else, failed to report that in my initial post.

Anyway, thanks all. Everything I have tried should work, but it is not. Frustrating. I'll close this out.
0
 
LVL 7

Expert Comment

by:Ironhoofs
ID: 36541962
Styles will sometimes not be applied correctly because of errors in the HTML or CSS. Do you have a working URL where we could see the problem? If not, the full CSS en HTML (not the ASP.NET code) should be sufficient...
0
 
LVL 2

Accepted Solution

by:
Starr Duskk earned 0 total points
ID: 36546630
I figured out the problem. I was redefining a master page in the page: me.masterpagefile = and somehow that was ignoring the classes within the table.
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 36565536
found reason for problem.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in page 3 56
Slider Moving to right hand side CSS? 2 22
Remove third quote mark from widget 6 23
Not seen Link button 5 37
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
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.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

808 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