473,573 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cellpadding for one column

I have one table. When I change the cellpadding of the table it fixes
the fact that the text doesn't touch the edge of the table. Yet it
causes problems with other parts of the table. Is there anyway in CSS
to basically do cell-padding for just one column so it won't affect
that other columns in the table? I just don't want my text to be
hitting the edge of the table.
Jul 20 '05 #1
10 6771

"Mark Constant" <co*******@mi x-net.net> wrote...
Is there anyway in CSS
to basically do cell-padding for just one column so it won't affect
that other columns in the table? I just don't want my text to be
hitting the edge of the table.


You can make a CSS rule and apply that rule to the individual td
elements in that particular column:

CSS:

.pad {
padding: 0 .25em 0 .25em;
}

html:

<table>
<tr>
<td>1, 1</td>
<td>2, 1</td>
<td class="pad">3, 1</td>
<td>4, 1</td>
</tr>
<tr>
<td>1, 2</td>
<td>2, 2</td>
<td class="pad">3, 2</td>
<td>4, 2</td>
</tr>
</table>

The CSS rule above will apply a left and right padding of .25em to any
element with the attribute class="pad". I applied the rule to every
third td element and consequently, to the 3rd column.

regards,
Jim Roberts

Jul 20 '05 #2

"Mark Constant" <co*******@mi x-net.net> wrote...
Is there anyway in CSS
to basically do cell-padding for just one column so it won't affect
that other columns in the table? I just don't want my text to be
hitting the edge of the table.


You can make a CSS rule and apply that rule to the individual td
elements in that particular column:

CSS:

.pad {
padding: 0 .25em 0 .25em;
}

html:

<table>
<tr>
<td>1, 1</td>
<td>2, 1</td>
<td class="pad">3, 1</td>
<td>4, 1</td>
</tr>
<tr>
<td>1, 2</td>
<td>2, 2</td>
<td class="pad">3, 2</td>
<td>4, 2</td>
</tr>
</table>

The CSS rule above will apply a left and right padding of .25em to any
element with the attribute class="pad". I applied the rule to every
third td element and consequently, to the 3rd column.

regards,
Jim Roberts

Jul 20 '05 #3
*Jim Roberts* <jr******@msn.c om>:

.pad {padding: 0 .25em 0 .25em;}

<tr><td>1, 1</td><td>2, 1</td><td class="pad">3, 1</td><td>4, 1</td></tr>
<tr><td>1, 2</td><td>2, 2</td><td class="pad">3, 2</td><td>4, 2</td></tr>

The CSS rule above will apply a left and right padding of .25em to any
element with the attribute class="pad". I applied the rule to every
third td element and consequently, to the 3rd column.


You'd achieve almost the same result with:

td:first-child+td+td {padding: 0 0.25em}
.pad {padding: 0 0.25em}

<table><col><co l><col class="pad"><co l>
<tr><td>1, 1</td><td>2, 1</td><td>3, 1</td><td>4, 1</td></tr>
...

At least as long as you don't need 'colspan'.

--
A magician pulls rabbits out of hats.
An experimental psychologist pulls habits out of rats.
Jul 20 '05 #4
*Jim Roberts* <jr******@msn.c om>:

.pad {padding: 0 .25em 0 .25em;}

<tr><td>1, 1</td><td>2, 1</td><td class="pad">3, 1</td><td>4, 1</td></tr>
<tr><td>1, 2</td><td>2, 2</td><td class="pad">3, 2</td><td>4, 2</td></tr>

The CSS rule above will apply a left and right padding of .25em to any
element with the attribute class="pad". I applied the rule to every
third td element and consequently, to the 3rd column.


You'd achieve almost the same result with:

td:first-child+td+td {padding: 0 0.25em}
.pad {padding: 0 0.25em}

<table><col><co l><col class="pad"><co l>
<tr><td>1, 1</td><td>2, 1</td><td>3, 1</td><td>4, 1</td></tr>
...

At least as long as you don't need 'colspan'.

--
A magician pulls rabbits out of hats.
An experimental psychologist pulls habits out of rats.
Jul 20 '05 #5

"Christoph Paeper" <ch************ **@nurfuerspam. de> wrote:
You'd achieve almost the same result with:

td:first-child+td+td {padding: 0 0.25em}
.pad {padding: 0 0.25em}

<table><col><co l><col class="pad"><co l>
<tr><td>1, 1</td><td>2, 1</td><td>3, 1</td><td>4, 1</td></tr>
...

At least as long as you don't need 'colspan'.


Cool. I was trying to think of an easy way that would work in IE as
well. Forgot about the <col> element.

You could also group the selectors:

td:first-child+td+td, .pad {padding: 0 0.25em}

Regards, Jim Roberts

Jul 20 '05 #6

"Christoph Paeper" <ch************ **@nurfuerspam. de> wrote:
You'd achieve almost the same result with:

td:first-child+td+td {padding: 0 0.25em}
.pad {padding: 0 0.25em}

<table><col><co l><col class="pad"><co l>
<tr><td>1, 1</td><td>2, 1</td><td>3, 1</td><td>4, 1</td></tr>
...

At least as long as you don't need 'colspan'.


Cool. I was trying to think of an easy way that would work in IE as
well. Forgot about the <col> element.

You could also group the selectors:

td:first-child+td+td, .pad {padding: 0 0.25em}

Regards, Jim Roberts

Jul 20 '05 #7
*Jim Roberts* <jr******@msn.c om>:

Cool. I was trying to think of an easy way that would work in IE as
well. Forgot about the <col> element.
I actually didn't look at the property to apply and am not sure whether it
works for 'padding' as intended (I doubt it), but does so fairly for
instance for the more commonly needed 'text-align'. It shouldn't, though.
You could also group the selectors:

td:first-child+td+td, .pad {padding: 0 0.25em}


IIRC a parser MUST NOT apply rule sets if it doesn't support all of its
selectors.
IE---claimed to be a CSS level 1 browser with some extra support for level 2
(and 3)---does not understand ':first-child' and '+'.

--
To be or not to be---that's no question, it's a decision.
Jul 20 '05 #8
*Jim Roberts* <jr******@msn.c om>:

Cool. I was trying to think of an easy way that would work in IE as
well. Forgot about the <col> element.
I actually didn't look at the property to apply and am not sure whether it
works for 'padding' as intended (I doubt it), but does so fairly for
instance for the more commonly needed 'text-align'. It shouldn't, though.
You could also group the selectors:

td:first-child+td+td, .pad {padding: 0 0.25em}


IIRC a parser MUST NOT apply rule sets if it doesn't support all of its
selectors.
IE---claimed to be a CSS level 1 browser with some extra support for level 2
(and 3)---does not understand ':first-child' and '+'.

--
To be or not to be---that's no question, it's a decision.
Jul 20 '05 #9

"Christoph Paeper" <ch************ **@nurfuerspam. de> wrote...
I actually didn't look at the property to apply and am not sure whether it works for 'padding' as intended (I doubt it), but does so fairly for
instance for the more commonly needed 'text-align'. It shouldn't, though.

I tested this with ie6 and it worked fine. Not sure about earlier
versions.
You could also group the selectors:

td:first-child+td+td, .pad {padding: 0 0.25em}


IIRC a parser MUST NOT apply rule sets if it doesn't support all of

its selectors.
IE---claimed to be a CSS level 1 browser with some extra support for level 2 (and 3)---does not understand ':first-child' and '+'.


I'll have to look up more information about that. I tested the above
with IE6 and Firefox .8. It worked in both. Again, I'm not sure about
other browsers. It's probably a better bet to make a separate rule for
each selector.

Thanks for the info.
Jim

Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12182
by: Graham J | last post by:
Apologies for the partial post that mysteriously escaped as I was composing. I shall try again. For many years I have been happily and successfully coding tables such that the WIDTH specified in a TD is the complete column width including any CELLPADDING. For example for a 400 pixel wide table with four 100 pixel wide columns and 10 pixel...
15
3525
by: Mark Richards | last post by:
For a table cell I want to have a padding of 3 pixel between the cell border and the text inside. How do I specify this attribute in a <TD> resp. css ? Mark
2
7935
by: Bart Plessers \(artabel\) | last post by:
Hello, I need a style that defines -table cellspacing -table cellpading -alignment I tried <table class="TBLpageframe"> <tr class="TRpageframe">
4
29378
by: Wim Roffal | last post by:
On my webpage (http://www.classiccat.net/index.htm) I tried to transfer the cellpadding/spacing attributes to my stylesheet. However, somehow it doesn't work. I tried to look it up on the internet, but it seems to me that I am doing everything right, which is obviously not the case. It concerns the tables in the alphabetic part of the page....
0
1929
by: virendra.chandra | last post by:
in datagrid cellpadding is not working. can u suggest what could be the possible error. this is my code <asp:datagrid id="test1" Runat="server" Width="700" Enabled="True" AutoGenerateColumns="False" Font-Size="8pt" PagerStyle-Wrap="True" AllowSorting="True" CellSpacing="2" CellPadding="3" GridLines="Vertical" ItemStyle-Wrap=True...
1
2099
by: yawnmoth | last post by:
Say I had a cellpadding of 3 but that for a single row in the table, I wanted a cellpadding of 0. Any ideas as to how I might go about doing this - as to how I might go about changing the cellpadding midway through a table and then restore it after that row?
0
869
by: Uriah Piddle | last post by:
Hi, In an asp.net 2.0 datagrid if I set the cell padding prop, it applies to the first column only. All subsequent cells have 0 padding. Thanks for any ideas. Steve
2
4264
by: Big Bill | last post by:
What's the CSS equivalent for that frequently found table coding? Roughly speaking? I know that speaking of equivalents can itself lead one into a semantic nightmare but, loosely speaking, what would you guys put? BB -- http://www.kruse.co.uk/internet-marketing-small-business.htm http://www.kruse.co.uk/close-ended-questions.htm
3
5409
by: Seth Watson | last post by:
I've seen so many answers on the net I am not sure which one is right or if there's one answer that will work in all browsers First off - Table - cellspacing and cellpadding What is the CSS equivalent for each? Is this also cross browser compatible? ** Posted from http://www.teranews.com **
0
7793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8039
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8092
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5606
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1049
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.