tags:

views:

613

answers:

4

Hello,

Below is some sample code, which has all the links right-justified. I would like to change the CSS so the "Left" link is left-justified, the others are right-justified, but they are all on the same line. How do I do that?

Thanks in advance,

John

The HTML:

<div class="mainlinks">
    <a href="left.php" class="links">Left</a>
    <a href="right1.php" class="links">Right1</a>
    <a href="right2.php" class="links">Right2</a>
</div>

The CSS:

.mainlinks
    {
    text-align:right;
    margin-top:3px;
    margin-right:10px;
    margin-bottom:0px;
    padding:0px;
    }

 a.links:link {
    color: #FF0000; text-decoration: none;
    text-align:center;
    margin-left:8px;
    margin-top:300px;
    margin-bottom:0px;
    padding:2px;
    font-family:Arial, Helvetica, sans-serif;
    font-size: 14px;
    }
A: 

you need to put it to separate blocks (div) or override via more specific CSS applying to the link as proposed by @skurpur

i believe you must add display:block to the link to position it - e.g. only block elements can be positioned.

dusoft
I tried that, and the left link was a line above the right link. I want them on the same line.
well, you need to study CSS more to understand the box model. you need to float one element to the left and the other one to the right (or both to the left setting width to 50% - assuming no other padding/margin and borders are set).
dusoft
+1  A: 

Put each in a seperate div. Float one left, one right. Set the widths.

<div class="mainlinks">
    <div class="left">    
        <a href="left.php" class="links">Left</a>
    </div>
    <div class="right">
        <a href="right1.php" class="links">Right1</a>
        <a href="right2.php" class="links">Right2</a>
    </div>
</div>

CSS

.mainlinks .left {
    float:left;
    width: 49%;
}

.mainlinks .right {
    float:right;
    width: 49%;
}
Rich Bradshaw
This assumes that there is no margin/border on the divs. The percentages would be better as px for the lengths of the divs.
Rich Bradshaw
I have a "<div class="line"></div>" directly beneath my links, but with your set-up above, my links are now below the line. Moreover, the link I would like to be at the left side of the screen is now in the center. The right-links are in place as usual.
You'll need to clear the floats. Stick a div with a style of clear:both underneat the mainlinks div.
Rich Bradshaw
+2  A: 
<style>
.mainlinks
    {
    text-align:right;
    margin-top:3px;
    margin-right:10px;
    margin-bottom:0px;
    padding:0px;
    }

 a.links:link {
    color: #FF0000; text-decoration: none;
    text-align:center;
    margin-left:8px;
    margin-top:300px;
    margin-bottom:0px;
    padding:2px;
    font-family:Arial, Helvetica, sans-serif;
    font-size: 14px;
    }

.right { float: right }
.left { float: left }

</style>
<div class="mainlinks">
    <a href="left.php" class="links left">Left</a>
    <a href="right1.php" class="links right">Right1</a>
    <a href="right2.php" class="links right">Right2</a>
</div>
rahul
I tried this setup, and it drastically altered the appearance of my page. Maybe I'll keep tinkering.
A: 

Float the left to the left

.left {float:left;}

    <div class="mainlinks">
        <a href="left.php" class="links left">Left</a>
        <a href="right1.php" class="links">Right1</a>
        <a href="right2.php" class="links">Right2</a>
    </div>

But you need to remove the margin-top:300px from a.links:link otherwise the left will be 300px below the right.

Emily
Thanks, Emily. Your simple solution worked perfectly. Also, thanks for helping me yesterday by suggesting Firebug for the other question I asked.