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> 8 27108
On 2008-09-19, Patrick <mo*@ici.lawrot e:
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>
Le 19.09.2008 22:34, Ben C a écrit :
On 2008-09-19, Patrick <mo*@ici.lawrot e:
>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>
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)
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
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
On 2008-09-19, Patrick <mo*@ici.lawrot e:
Le 19.09.2008 22:34, Ben C a écrit :
>On 2008-09-19, Patrick <mo*@ici.lawrot e:
>>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.
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)
>>>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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Markus Ernst |
last post by:
Hi
I have a strange problem with vertical-align. The case can be viewed at
http://www.brainput.info/geschichte.html.
HTML code:
<div id="bild"><img src="geschichte.gif" width="274" height="29" alt="Wir
schreiben die Geschichte Ihres Unternehmens."></div>
|
by: Felipe Gasper |
last post by:
I'm trying to make some "sub-cells" in an HTML table and to control
their positioning and content presentation via CSS. In the table at
the following URL:
https://fshn3152.foods.uiuc.edu/~fgasper/erf.html
what I'm immediately trying to do is vertically position the text and
checkboxes in all four "Statement Date" sub-cells (created with <span>
elements).
|
by: smr78 |
last post by:
Hi,
Up to now, I didn't find a solution to align text in the middle of a inline
neither block box in the vertical direction. That's because the
vertical-align property is not active for many boxes.
And when it is, not all the browsers folow it.
I think there is a general solution in surrounding the box with another box,
using the top property and fixing the top position at the middle of the
surrounding box minus the half height of the box...
|
by: chris_culley |
last post by:
Hi,
I'm fairly new to using css, and have been using it to format a
vertical navigation bar on my website, producing a load of buttons on
top of each other, each with a (151 * 33 px) gif as the background.
I've customised the <a> tag as follows:
a.menu {
|
by: tradmusic.com |
last post by:
Sorry to re-post, but my original post didn't seem to appear. Here it is
again:
I am experimenting with a roll-over but am struggling to get the text to
align, vertically, in the middle:
#sidebar a:link, #sidebar a:visited {
border: 1px solid #7A95CA;
display: block;
height: 30px;
| |
by: acunnon |
last post by:
I am trying to put together an login page my problem is getting the three items aligned to the middle verticaly without specifing a height to anything on the page.
CSS
html{
height:100%;
min-height:100%;
}
body{
vertical-align:middle;
|
by: Bill |
last post by:
Hi
How can I have IE7 act correctly on that ?
The rules make the link text go down when hovered. It works in FF , I had to
add a hard space right after the LI tag to have OP9 work but I can't figure
how to have IE7 work. Why?
How can I have it work in all 3 browsers?
http://nrap.selfip.com
|
by: Dave Rado |
last post by:
Hi
See my mock-up at http://tinyurl.com/35tv29. The three icons are
supposed to be vertically aligned on their bottoms (using "vertical-
align: bottom"), but they aren't, they're vertically aligned on their
tops. Is there any way to align them vertically on their bottoms (or
middle for that matter) short of resorting to using a table (where
"vertical-align: bottom" does work)?
Dave
|
by: maya |
last post by:
hi,
how do I get text to vertical-align inside a div?
http://www.mayacove.com/misc/home.html
vertical-align should work, according to this:
http://htmlhelp.com/reference/css/text/vertical-align.html
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |