text align in a link (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


milo3169 -> text align in a link (8/22/2005 12:31:57)

Can I put a text-align in a <a href> Tag? If so, I do I do that?[:D]




Tailslide -> RE: text align in a link (8/22/2005 13:58:39)

It won't work as the link is an "inline element" and text:align only works on "block level elements". This however does:

Either

<p style="text-align:center;"><a href="index.html" >Click here</a></p>


or better still:

in your document head or external stylesheet:

<STYLE TYPE="text/css">
<!--
.centeralign {text-align:center}
-->
</STYLE>


Then in the HTML

<p class="centeralign"><a href="index.html" >Click here</a></p>


You're thinking what's the difference. Difference is with the style declared separately you can change it and it will change all over the page (or site if the style's external) whereas doing it inline (in the p tag) you have to change every one.




milo3169 -> RE: text align in a link (8/22/2005 14:18:01)

That is what my problem is. I wanted to be able to align the link to the right inline with the text. But you are not able to do that?




Tailslide -> RE: text align in a link (8/22/2005 14:26:52)

Ah! Lightbulb moment!

You can't use text:align BUT you can float a link like this:

<a style="float:right;" href="#">Click here</a>


You just need to be a bit careful about positioning the float - you might need to move it around a bit to get it exactly right.

Edit: again as with the last example it'd be better to do it like this:

<STYLE TYPE="text/css">
<!--
.rightalign {float:right}
-->
</STYLE>


then

<a class="rightalign" href="yourlink.html">Click here</a>






milo3169 -> RE: text align in a link (8/22/2005 14:41:43)

Thanks Tailslide,

I will give that a try and see what happens




d a v e -> RE: text align in a link (8/22/2005 15:51:34)

i think you might need to float it in a div...

<div class="rightalign">
<a class="rightalign" href="yourlink.html">Click here</a>
</div>




milo3169 -> RE: text align in a link (8/22/2005 16:03:19)

I have tried all of your suggestions, it does align right, but not in line with the text. It will put it on the next line. I'm not that this can be done.




Tailslide -> RE: text align in a link (8/22/2005 16:10:08)

Strictly speaking they don't need to be inside anything - floats will work on any un-positioned element be they inline or block.

It is always a good idea to have them inside a div or a table or something otherwise they try to float off the screen!




d a v e -> RE: text align in a link (8/22/2005 16:14:10)

of course - that's true!

anyway this works for me
http://members.tiscali.fi/dave_pirjo/test-area/css_stuff/rightalign.htm




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875