Jump to content

And yet even another link - anchor this time


crmamx

Recommended Posts

I have the weirdest problems.

 

I use this code 11 times in a program.

 

<a href="#top" class="center">Back to top</a>

 

The first 9 times are left justified.

 

The 10th time is centered, which it should be.

 

What do I look for?

Link to comment
Share on other sites

You should look for any CSS style class called "center". 

 

Are you trying to center the link?

 

If so, remove the class="center" from the anchor tag and place a div tag to center your link as below.

 

<div align="center"><a href="somesite.htm">Link Here</a></div>

Link to comment
Share on other sites

Something to look for at first is the manual if a book didn't have this info.

this is what it says:

16.2 Alignment: the 'text-align' property

 

'text-align'

    Value:  left | right | center | justify | inherit

    Initial:  a nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl'

    Applies to:  block containers

    Inherited:  yes

    Percentages:  N/A

    Media:  visual

    Computed value:  the initial value or as specified

 

Now the question: is an A element a block element or not? and if not can we align it as if it were a block element?

(answer, no an A element is not a block element, and yes we can use display block on them (but only use it if you know what that does!)

 

So in a nut shell Yes we can: Run the stuff below and see the differences (note though in real life use an external style sheet)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        
        <link type="text/css" rel="stylesheet" href="css/reset.css" />
       
        <title></title>
    </head>
    <body>
<style type="text/css">
    #container1{
        width:300px;
        border:1px solid red;
    }
    #container2{
        width:300px;
        border:1px solid blue;
    }
    #container3{
        width:300px;
        border:1px solid green;
    }
    #container4{
        width:300px;
        border:1px solid pink;
    }
    .center{
        text-align: center; /* used for block elements */
    }
    .block{
        display:block;
    }
    .block2{
        display: block;
        text-align: center;
    }
</style>
        <div id="container1">
            <a class="center" href="">this is a link</a>
        </div>
        <br />
        <div id="container2">
            <p class="center"><a href="">this is a link</a></p>
        </div>
        <br />
        <div id="container3">
            <p><a class="block center" href="">this is a link</a></p>
        </div>
        <br />
        <div id="container4">
            <p><a class="block2"href="">this is a link</a></p>
        </div>
        <br />
    </body>
</html>

 

Now a nice thing to do for you is remove the width property of the container and see what happens than.

Link to comment
Share on other sites

One thing you have drilled into my hard head is:

 

No inline css

 

And I am now working on getting rid of it one page at a time....tables too... :D

Some excellent reasons why:

Inline styles:

- don't separate content from design

- cause more maintenance headaches

- are not as accessible

- make your pages bigger

 

Taken from: http://webdesign.about.com/od/css/a/aa073106.htm

Link to comment
Share on other sites

One thing you have drilled into my hard head is:

 

No inline css

 

And I am now working on getting rid of it one page at a time....tables too... :D

 

I did that on purpose, another reason, is that inline style is redundant. But I hope you do understand, that the answer I gave above does have the word inline in it, but I was talking about inline elements. And that is something different.

 

there are 2 flavours: block elements en inline elements.

Link to comment
Share on other sites

One thing you have drilled into my hard head is:

 

No inline css

 

And I am now working on getting rid of it one page at a time....tables too... :D

 

I did that on purpose, another reason, is that inline style is redundant. But I hope you do understand, that the answer I gave above does have the word inline in it, but I was talking about inline elements. And that is something different.

 

there are 2 flavours: block elements en inline elements.

By the way you can use tables as long as you use them what they are meant for. Maybe have a look at my blog, pretty much all your questions I turned in to an article. (just so you know)
Link to comment
Share on other sites

hehe i'll try problem is screencasts may only take 5 minutes (or i need to buy a screencapture program for 400 dollar  :'(, but I'll, use the elements of repetition and simplicity.

Trust me firebug is very very easy to use. I'll show all the things that are needed.

 

 

Edit:  it's online: http://cssfreakie.blogspot.com/2011/03/using-firebug-for-css.html

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.