Web Hosting CSS & Stylesheet Forums

Add Me

User Name
Password
Go Back   CSS & Stylesheet Forums > CSS Forumz: Main > Style Sheet In General

Welcome to the CSS & Stylesheet Forums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags:



Reply
  #1 (permalink)  
Old 09-23-2008, 01:42 AM
Patrick
Guest
 
Posts: n/a
Diggs:
Default Vertical align in block link?



Hello,

I'm trying to align a text vertically in a link displayed as a block.
But the text is always at top.
Is there a solution?
Your advices are welcome.

Here is a test page:

<html>
<head>
<style>
a {
display: block;
height: 100%;
text-align: center;
vertical-align: middle;
--
a:hover {
background: #fee;
--
</style>
</head>
<body>
<table width="100%" height="100%">
<tr>
<td valign="middle"><a href="#a">a</a></td>
<td valign="middle"><a href="#b">b</a></td>
</tr>
</table>
</body>
</html>
Reply With Quote


Sponsored Links
  #2 (permalink)  
Old 09-23-2008, 01:42 AM
Ben C
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

On 2008-09-19, Patrick <moi@ici.la> wrote:
> Hello,
>
> I'm trying to align a text vertically in a link displayed as a block.
> But the text is always at top.
> Is there a solution?


Just remove height: 100% from the A and it will be vertically centered
in the table cell.

> Here is a test page:
>
><html>
><head>
><style>
> a {
> display: block;
> height: 100%; > text-align: center;
> vertical-align: middle;
> --
> a:hover {
> background: #fee;
> --
></style>
></head>
><body>
><table width="100%" height="100%">
> <tr>
> <td valign="middle"><a href="#a">a</a></td>
> <td valign="middle"><a href="#b">b</a></td>
> </tr>
></table>
></body>
></html>

Reply With Quote


  #3 (permalink)  
Old 09-23-2008, 01:42 AM
Patrick
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

Le 19.09.2008 22:34, Ben C a écrit :
> On 2008-09-19, Patrick <moi@ici.la> wrote:
>> Hello,
>>
>> I'm trying to align a text vertically in a link displayed as a block.
>> But the text is always at top.
>> Is there a solution?

>
> Just remove height: 100% from the A and it will be vertically centered
> in the table cell.


Yes but I want the whole block to be clickable as a link, from the top
to the bottom of the screen.

Other ideas please?

>
>> Here is a test page:
>>
>> <html>
>> <head>
>> <style>
>> a {
>> display: block;
>> height: 100%; > text-align: center;
>> vertical-align: middle;
>> --
>> a:hover {
>> background: #fee;
>> --
>> </style>
>> </head>
>> <body>
>> <table width="100%" height="100%">
>> <tr>
>> <td valign="middle"><a href="#a">a</a></td>
>> <td valign="middle"><a href="#b">b</a></td>
>> </tr>
>> </table>
>> </body>
>> </html>

Reply With Quote


  #4 (permalink)  
Old 09-23-2008, 01:42 AM
Jim Moe
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

On 09/19/08 09:06 am, Patrick wrote:
>
> I'm trying to align a text vertically in a link displayed as a block.
> But the text is always at top.
> Is there a solution?
>

There is no general solution for vertically aligning objects.
For special cases where the text is fixed in length two methods are common.
1. Set the line-height to fill the space.
2. Adjust either the top margin or padding.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Reply With Quote


  #5 (permalink)  
Old 09-23-2008, 01:42 AM
Jonathan N. Little
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

Jim Moe wrote:
> On 09/19/08 09:06 am, Patrick wrote:
>> I'm trying to align a text vertically in a link displayed as a block.
>> But the text is always at top.
>> Is there a solution?
>>

> There is no general solution for vertically aligning objects.
> For special cases where the text is fixed in length two methods are common.
> 1. Set the line-height to fill the space.
> 2. Adjust either the top margin or padding.
>


It would have to be padding if you set the link to display: block, the
margin would not be the "clickable" part.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Reply With Quote


  #6 (permalink)  
Old 09-23-2008, 01:42 AM
Patrick
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

Le 20.09.2008 04:06, Jonathan N. Little a écrit :
> Jim Moe wrote:
>> On 09/19/08 09:06 am, Patrick wrote:
>>> I'm trying to align a text vertically in a link displayed as a block.
>>> But the text is always at top.
>>> Is there a solution?
>>>

>> There is no general solution for vertically aligning objects.
>> For special cases where the text is fixed in length two methods are
>> common.
>> 1. Set the line-height to fill the space.
>> 2. Adjust either the top margin or padding.
>>

>
> It would have to be padding if you set the link to display: block, the
> margin would not be the "clickable" part.


Thanks for the help. I tried to set height: 50%; padding-top: 50%;
It works more or less in Firefox but not Konqueror (block is only half
height, text not vertically centered).

Is there really no solution (even not pure CSS, I don't care) working
for most browsers?

--
Patrick
Reply With Quote


  #7 (permalink)  
Old 09-23-2008, 01:42 AM
Ben C
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

On 2008-09-19, Patrick <moi@ici.la> wrote:
> Le 19.09.2008 22:34, Ben C a écrit :
>> On 2008-09-19, Patrick <moi@ici.la> wrote:
>>> Hello,
>>>
>>> I'm trying to align a text vertically in a link displayed as a block.
>>> But the text is always at top.
>>> Is there a solution?

>>
>> Just remove height: 100% from the A and it will be vertically centered
>> in the table cell.

>
> Yes but I want the whole block to be clickable as a link, from the top
> to the bottom of the screen.
>
> Other ideas please?


It's not easy.

You could set a big line-height on the A (and no need to set
vertical-align: middle).

But you can't do that because you want "100%", not some known value, and
line-height: 100% doesn't mean 100% of the containing height but 100% of
the font size.

Display: table-cell on the A is another option, but won't work in IE.
You could put a span inside the A and offset it with position: relative
and top: 50%, but it won't be quite centered unless you move it up again
by half its font-size.

You could fake it with Javascript-- centre the A but give the table cell
a click handler.
Reply With Quote


  #8 (permalink)  
Old 09-23-2008, 01:42 AM
Jim Moe
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

On 09/20/08 02:20 am, Patrick wrote:
>>>> I'm trying to align a text vertically in a link displayed as a block.
>>>> But the text is always at top.
>>>> Is there a solution?
>>>>
>>> There is no general solution for vertically aligning objects.
>>> For special cases where the text is fixed in length two methods are
>>> common.
>>> 1. Set the line-height to fill the space.
>>> 2. Adjust either the top margin or padding.
>>>

>
> Thanks for the help. I tried to set height: 50%; padding-top: 50%;
> It works more or less in Firefox but not Konqueror (block is only half
> height, text not vertically centered).
>

Use "line-height", not "height".

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Reply With Quote


  #9 (permalink)  
Old 09-23-2008, 01:42 AM
Patrick
Guest
 
Posts: n/a
Diggs:
Default Re: Vertical align in block link?

>>>> I'm trying to align a text vertically in a link displayed as a block.
>>>> But the text is always at top.
>>>> Is there a solution?
>>> Just remove height: 100% from the A and it will be vertically centered
>>> in the table cell.

>> Yes but I want the whole block to be clickable as a link, from the top
>> to the bottom of the screen.

>
> It's not easy.
>
> You could set a big line-height on the A (and no need to set
> vertical-align: middle).
>
> But you can't do that because you want "100%", not some known value, and
> line-height: 100% doesn't mean 100% of the containing height but 100% of
> the font size.
>
> Display: table-cell on the A is another option, but won't work in IE.
> You could put a span inside the A and offset it with position: relative
> and top: 50%, but it won't be quite centered unless you move it up again
> by half its font-size.
>
> You could fake it with Javascript-- centre the A but give the table cell
> a click handler.


Thanks for the help :-)
The solution with
<span style="position: relative; top: 50%">
works well in Firefox and IE (but not in my version of Konqueror, maybe
a bug).
I'll go with that one.

--
Patrick
Reply With Quote


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 08:29 PM.
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.




Inactive Reminders By Mished.co.uk