473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

border around an A tag not wrapping around the whole box in firefox.

I'm trying to put a border around a link when the mouse rolls over it.
I've made an example below and left out the hover to keep it simple. In
IE the example below draws a box arround the image OK, in Firefox the
box drawn is one line of text in height. If I add any lines of text
inside the A tag it borders each line of text individually.

The solutions I've tried are:

putting a Div tag inside the A and using A:hover .myDiv{boder.....}
unfortunatley this doesn't seem to work in IE

Using both A:hover and A:hover img which works in firefox full size.
Down sides are the not all of the content to be boxed it image based
and it also displays the tiny border aswell as the full sized border in
fireFox.

I'm wondering if I should use javascript instead to change the border
value, that way I can change the border on the DIV that the A is in.

Is this making sense to anyone? Anyway, if someone can work out a way
of getting the below to work in firefox and IE using A:hover instead of
A it would be greatly appreciated ( no borders when you're not
hovering).

I realise it's probably not working due to my lack of CSS knowledge.

Thanks in advance,
Mike.

####### CODE EXAMPLE HERE ########

<head>
<title>Test</title>
<style type="text/css">
<!--
img {border:none;}
A{ border: 4px dashed #99CCCC; margin: -4px; }
-->
</style>
</head>
<body>
<div class="item"><a href="#"><img src="images/notePaper.gif"
width="245" height="150" /></a></div>
</body>
</html>

Sep 12 '06 #1
3 3007
Els
mc**@hotmail.com wrote:
I'm trying to put a border around a link when the mouse rolls over it.
I've made an example below and left out the hover to keep it simple. In
IE the example below draws a box arround the image OK, in Firefox the
box drawn is one line of text in height. If I add any lines of text
inside the A tag it borders each line of text individually.

The solutions I've tried are:
Maybe you're looking for a{display:block;}?

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/

Now playing: Trockener Kecks - Paradijs
Sep 12 '06 #2
Exactly what I was looking for... Was that a RTFM moment :S.

Thanks very much for that.

Mike

Sep 12 '06 #3

mc**@hotmail.com wrote:
If I add any lines of text
inside the A tag it borders each line of text individually.
There's a bunch of stuff involved here.

1. The content of <ais %inline;, not %block; or %flow;.
http://www.w3.org/TR/html4/struct/links.html#edef-A

This means that you can't place block elements like <divor <pinside
an <a>. If you do, then anything could happen.

It _doesn't_ mena that you can't have "lines of text" inside an <a>
though, because <bris an inline element and so it's still permitted.
You don't specify how you were achieving your "lines of text", but I
suspect you were using <prather than <br>

2. <ahas CSS display: inline; by default rather than block.
Although you can still use some "block like" CSS rendering properties
on it, such as "border", then they're not likely to work quite how you
expect. If you want <ato look like a block element, then set the CSS
display: block; property and do it properly.

In particular, bordering inline elements _should_ border each line
separately. After all, they're inline. If you want an overall border
around the whole element, you'll be wanting diaplay: block;

3. You mention IE, but you don't mention a doctype. If you have IE in
Strict rendering mode, by using a proper doctype on your HTML, then
(AFAIK) you will get the same correct behaviour as FF, even though it's
not what you want.

If you're doctype-less, then IE drops into quirks mode and deliberately
mis-renders borders on <awhen inline as if it were block, on the
assumption that this is "what you really wanted". Evil piece of crud
that it is 8-(

If you're trying to do anything width-related to <athen you'll
probably need to set a width on it. The "traditional" way to do this is
to set width: 100%; on the <aand control the width of its containing
element, frequently a <li>

So the real fix is to write valid HTML, to switch <ainto display:
block; rendering if that's what you're after, force IE into standards
mode, then suddenly wonder how it all became so easy to do the rest
8-)

I'm wondering if I should use javascript instead to change the border
value,
That's never the answer to anything, certainly not for presentation.
It's also more complicated and much harder to support. Fortunately you
asked in c.i.w.a.s first!

Here's an example, showing most of the variations. Go play with it.
Then remove the doctype and try viewing it again (in both IE and FF)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>Multi-line A element</title>

<style type="text/css" >

div {
margin: 1em;
width: 20em;
}

a {
border: 3px solid red;
width: 100%;
}

div.a-as-block a {
border-color: blue;
width: 100%;
display: block;
}
</style>

</head><body>
<div class="single-line" >
<a href="#" >A link</a>
</div>
<div class="with-linebreak" >
<a href="#" >Another link<br>with multiple lines</a>
</div>
<div class="with-para" >
<a href="#" >An incorrect link<p>with multiple lines</a>
</div>

<div class="a-as-block" >

<div class="single-line" >
<a href="#" >A link</a>
</div>
<div class="with-linebreak" >
<a href="#" >Another link<br>with multiple lines</a>
</div>
<div class="with-para" >
<a href="#" >An incorrect link<p>with multiple lines</a>
</div>

</div>

</body></html>

Sep 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Vigil | last post by:
I am trying to put a 7px border around a page. If the contents don't fill up the viewport, then the border must appear all around the viewport. If the page is larger than the viewport, then the...
0
by: Red | last post by:
This is apparently an ie display bug, I can't seem to figure out which ie bug this is. a 3 sided border is created by wrapping the 'inner' box in the 'middle' box and padding the 'middle' box...
6
by: Mr. Clean | last post by:
Apparently Mozilla/Firefox doesn't support the bordercolor attribute of the table tag. Here's what I do that works in IE: <table border="1" cellpadding="2" cellspacing="0" width="380"...
3
by: David Stone | last post by:
I'm trying to apply a border to a Flash learning object, which is loaded into a page via <object>. I'm trying to use a style to put a black border around the Flash object. ...
8
by: UJ | last post by:
I have a table with multiple cells and I want to draw a box around the entire table but not around the individual cells. How do I do that? TIA - Jeff.
2
by: jonathandowns | last post by:
i'm trying to put a css border around this box, and it's not working properly in safari and firefox (works fine in IE). can anyone help me fix this? here is a grab so you can see the problem: ...
6
by: Hacking Bear | last post by:
Hi, I still don't quite fully understand how to handle mixing border/margin pixel width with percentage width. In the example below, I want to place side-by-side two DIV boxes inside a box....
0
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I have these three questions and though to post them in a single thread: 1) I have created a textarea: <textarea id="txtCards" cols="50" rows="15" runat="server" wrap="virtual"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.