Solved

Table cell  margin problem

Posted on 2007-04-10
7
5,927 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

749 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