PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 3, 2022

[FIXED] How to I position two elements on opposite sides of a table cell

 August 03, 2022     alignment, css, html-table     No comments   

Issue

I have a table cell with text and an icon. I want both elements to link to the the same place. I want the text to align to the left side and the icon to align to the right side of a table cell. Code could look something like this:

<td><a href="#">Text<span>icon</span></a></td>

EDIT: I edited the code to represent some requirements that I did not originally include. Both the text and icon must be links.

In addition, I am grabbing the width of the <a> tag when the user clicks on it. If I cut the text and icon into two different a tags my measurement will be inaccurate.


Solution

How about something like this?

<table>
    <tr>
        <td>Foobar</td>
        <td>
            <div class="left">
                <a href="#">Text</a>
            </div>
            <div class="right">
                <a href="#">icon</a>
            </div>
        </td>
 <table>

td {
    width: 150px;
}

.left {
    float: left;
}

.right {
    float: right;
}

UPDATE: How about keeping the <a> tag outside the <div>s then? Not pretty, but works: jsFiddle



Answered By - chopper
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing