Solved

Table cell  margin problem

Posted on 2007-04-10
7
5,929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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