Solved

Table cell  margin problem

Posted on 2007-04-10
7
5,919 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

757 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

20 Experts available now in Live!

Get 1:1 Help Now