Solved

Table cell  margin problem

Posted on 2007-04-10
7
5,926 Views
Last Modified: 2012-06-21
Hello,

I may have a very simple question.
I am trying to make a table with cell margins like this:

<html>
<head>
<title>test</title>
</head>

<body class="body">
  <table border="1" width="250">
   <tr>
    <td style="margin-left:50px" height="30">testing</td>
  </tr>
</table>
</body>
</html>

Somehow the margin isn't shown in my browser...
What is wrong with code above??

Mkraan
0
Comment
Question by:mkraan
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:TName
ID: 18882436
To see the cell border, you need more than 1 cell :)


<html>
<head>
<title>test</title>
</head>

<body class="body">
  <table border="1" width="250">
   <tr>
    <td style="margin-left:50px" height="30">testing</td>
    <td style="margin-left:50px" height="30">testing</td>
  </tr>
</table>
</body>
</html>
0
 
LVL 28

Expert Comment

by:TName
ID: 18882489
But I'm not sure what you are trying to achieve by setting the cell's margin? -> style="margin-left:50px"
A cell is part of a table, not an independent entity that you can freely position or shift...
0
 

Author Comment

by:mkraan
ID: 18882547
Hello TName, i'm not trying to position the cell,
i'm just trying to have a cell with the text in it left margin 50 px.

with 2 cells it isn't working either.
0
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.

 

Author Comment

by:mkraan
ID: 18882558
Copy and paste this code and u'll see no left-margin

<html>
<head>
<title>test</title>
</head>
<body>
  <table border="1" width="250">
   <tr>
    <td style="margin-left:50px;" height="30">testing</td>
  </tr>
</table>
</body>
</html>
0
 

Author Comment

by:mkraan
ID: 18882900
Ok i found the solution :

replace margin-left with padding-left  that's it

I don't know why but margin-left doesn't work on table cells
0
 
LVL 28

Accepted Solution

by:
TName earned 50 total points
ID: 18883023

Sorry, was busy for a while...

Padding sets the margins *for the content* of the element (in your case, the text in a cell), margin is the margin of the element itself...
Margin cannot work on table cells, as mentioned above, they are not independent elements like a <div> or a <p>, you can only set e.g. the cell-spacing for the whole table...

But what you need here is indeed "padding" (we could call it "the inner margin" of a element).
If for instance you wrap the text in a span and put that span inside a cell, you can give that span a margin either by setting the *span's* margin, or by setting the *cell's padding*.

Have a look at the w3 box-model:
http://www.w3.org/TR/REC-CSS2/box.html
0
 

Author Comment

by:mkraan
ID: 18883049
Ty TName,

I'm a lot wiser now!!
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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Find out what you should include to make the best professional email signature for your organization.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

860 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