Solved

HTML5 CSS - <TD> align left

Posted on 2014-03-06
4
763 Views
Last Modified: 2014-03-07
I am trying to left align content that is in the <td> but I want the table centered on the page.

<!DOCTYPE html >
<html lang="en" >
<head>
    <title>
      Magic By Carlos
    </title>    
    <meta charset="utf-8" />
    <link href="magic.css" rel="stylesheet">

    <!-- This is where your link tag goes when linking to an external style sheet. -->
 
    <!--This is the format you will use when entering JavaScript -->    
    <script type="text/javascript">
    /* <![CDATA[ */

    // your JavaScript instructions will go here

    /* ]]> */
    </script>        
</head>

<body> 
    <div class=aligncenter>        
        <!-- Your XHTML here -->
        <!--
        <header>
            <img src="images/CtM2.jpg" alt="" height="225" width="325"> 
        </header>
        -->
        <h1 class=title>
            Be The Star Of The Show
        </h1>
        <nav>
            <h2>
            <a href="magic.htm"><b>Home</b></a> &nbsp;
            <a href="services.htm"><b>Services</b></a> &nbsp;
            <a href="video.htm"><b>Video</b></a> &nbsp;
            <a href="about.htm"><b>About</b></a>
            </h2>
        </nav>
    </div>    

    <div class=content>
        <table class=tablecenter>
            <tr>
                <td class=valigntop; style="width:500px" text-align:left>
                    <br>
                    <span class="firstLetter">A</span> magician performs magic in front of a person or group of people by creating illusions that seem supernatural.  '
                    Magic is performed many ways, the most commonly known are close-up and stage magic.
                </td>
                <td>
                    <img src="images/CtM2.jpg" alt="Magic By Carlos"
                            height="225" width="325"> 
                </td>
                <td class=valigntop; style="width:500px">
                    <br>
                    <span class="firstLetter">C</span>arlos not only performs mind blowing illusions but volunteers also appear to perform illusions becoming the
                    star of the show.
                    <br><br>
                    Carlos provides the below services:
                    <ul>
                        <li>Illusions</li>
                        <li>Comedy</li>
                        <li>Balloon Animals</li>
                    </ul>
                </td>
            </tr>
        </table>
        <br>
    </div>
    <br><br>

    <div>
        <footer>
            <small><i>Copyright &copy; 2014 Magic By Carlos</i></small><br>
        </footer>
        
        <br><br>
        <!-- external javascript for validation -->  
        <script type="text/javascript" src="../validation.js">
        </script>            
    </div>
</body>
</html>

Open in new window


.title {
    background-color: #630C0C;
    color: white;
    font-size: 65px;
}

.valigntop {
    display: table-cell;
    vertical-align: top;
}

.alignleft {
    text-align: left;
}

.aligncenter {
    text-align: left;
}

.aligncenter {
    text-align: center;
}

.tablecenter {
    margin-left:auto; 
    margin-right:auto;
}

.pretty-table {
    border-collapse: collapse;
    margin-left:auto; 
    margin-right:auto;
}
.pretty-table th, .pretty-table td { padding: 0.5em; }
.pretty-table th[scope=col]
{
  border-bottom: 2px solid #333;
  border-right: 2px solid #333;
}
.pretty-table th+th[scope=col] { border-right: 1px dotted #666; }
.pretty-table th[scope=row] { border-right: 2px solid #333; }
.pretty-table th, .pretty-table td { color: #632a39; }
.pretty-table th[scope=col] { color: #000; background-color: #8fadcc; }
.pretty-table th+th[scope=col] { color: #fff; background-color: #7d98b3; }
.pretty-table th[scope=row] { background-color: #b8cfe5; }

.content {
    background-color: #F6F6FD;
    text-align: center;
}

.firstLetter {
    background-color: #3399FF;
    color: #FFF;
    float: left;
    font-size: 48px;
    margin-right: 10px;
    margin-top: 7px;
    padding: 18px;
    border-radius: 5px;
    box-shadow: 0 0 10px -2px #999999;
}

Open in new window

0
Comment
Question by:CipherIS
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39911739
to center the table, add this style:
.tablecenter {
    margin: 0 auto;
}

but I see you are already doing something similar. It appears fine on my side (Firefox), perhaps you should clear your cache and refresh. I attach a screenshot on how it looks in my browser without changing anything you posted.


The reason the text in the table is aligning center is because of this rule in your styles:
.content {
    background-color: #F6F6FD;
    text-align: center;
}

change the text-align to left
Capture.PNG
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39911893
Tables always act funny.  Your table should be centered but if you want the table content to be aligned left then you need to make the <td>s aligned left.

And this: <td class=valigntop; style="width:500px" text-align:left>

should be: <td class="valigntop" style="width: 500px; text-align: left;" >
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 39914025
Thank you.  That was so frustrating trying to figure it out.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39914074
You're welcome!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make options hidden and show just option that is on 1 29
Button function on table is in trouble 3 22
Do alert on select 6 15
Powershell script does not exit 4 29
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…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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