Problem with image border in Chrome

Hi,

I just started doing CSS again after a long break, and I’m trying Chrome for the first time. And it’s already giving me some trouble.

I’m working on this page, who seem to work fine in Firefox:
http://lynxdaemon.net/test/galerie.html

The trouble is that the link border around the images doesn’t appear in Chrome. Any idea why and how to fix it? I tried to put a border-color around the image, but then there’s no difference between the visited or unvisited link.

If you see any other problems, feel free to tell me. I haven’t tested that design in the dreaded IE6/7 yet, only Firefox 3.6 and Chrome.

Thanks for your help.

Hi Daemonia. Welcome to SitePoint!

Hm, did you mean the bottom images/links? http://stommepoes.nl/borderchrome.jpg 'cause I see a border ok on the large kitty.

Your CSS doesn’t really mention a border. While most browsers will automatically add a border to images as part of their default stylesheet, I don’t believe they all do (default stylesheets differ per browser, which is why you have that margin: 0; padding: 0). My “reset” also includes a

img {
vertical-align: bottom;
border: 0;
}
declaration as well. Later, any borders I want, I add explicitly.

warning:
BTW padding: 0 on * (all elements) is a bad practice on any sites which will contain a form… in many browsers, once default padding is removed from form controls (radio buttons, select dropdowns, etc) they cannot be added back in. So instead, I list the 3 or 4 elements who DO have default padding in browsers (there just aren’t many who do) and set just those to padding: 0.


#galerie a{
	color:#064242;
}
#galerie a:visited{
	color:#000;
}
#galerie img:hover{
	border:none;
	margin:2px;
}

I do see some issues with your code, so I’ll get to those in a minute. Re the images:

First, browsers seem different in determining what is “visited” when your link is “#”. IE for example seems to make everyone set to “#” as “visited” if you click any single one (since, makes sense, they all go to the same “address”).

Second, here is how you put borders around image links:


//inside #galerie
<a href="foo">
  <img src="foo" width="width" height="height" alt="where do I go?">
</a>


#galerie a {
  border: 2px solid #thecolour;
}
#galerie a:visited {
  border-colour: #somethingelse;
}
#galerie a img {
  no padding, no margin, no borders;
}

OR


#galerie a img {
  border: 2px solid #thecolour;
}
#galerie a:visited img {
  border-color: #somethingelse;
}

Normally, the inline anchor will be able to encompass the image and surround it with a border.

To go from no border to a border or vice-versa, padding comes into play, and the border can go on the image itself.


//starts with no border let's say
#galerie a img {
  padding: 1px;
}
//border appears on focus, hover, and stays on visited
#galerie a:focus img, #galerie a:hover img, #galerie a:visited img {
  padding: 0;
  border: 1px solid #thecolour;
}

The padding is a placeholder for when there is no border. Chrome makes the images dance around now because of that 2px margin you’ve got going on :hover. And, if the border is going to be on the image, then I’d use padding.

In general, to keep things most accessible, I would put the states like hover etc on anchors and let them affect a:somestate img instead of img:hover. IE6 won’t hover images for example, and keyboarders cannot :focus on non-focusable elements (anchors, form controls, that’s about it for focusable elements).


So, some notes on your page (I should have put that * {padding: 0;} remark down here actually):

font-size:62.5%;

There is a myth still floating around the internets… that setting this on a page is a Good Thing. This is wrong. : ) It was used to make 1em = 10px, however since that ONLY works on browsers who have 16px set as their default setting, it causes issues for those who need a larger default font setting on their browsers or who have their system dpi set higher. Macs and PCs differ on their basis default dpi and anyone with bad sight can increase that setting anyway… with 62.5%, your text will be awfully small for some folks.

You could get away with setting the fonts to 80%, but to be honest, I let the user’s system determine font size (and em size) by just setting it to 100% (setting it at all is done for the benefit of IE, who has a resizing bug which is magically fixed if you state a % font size on your body element). And yeah, I tend to set all these settings on the body, not the html element.


#wrap{
	margin:auto;
	[b]margin-top: 3em;[/b]
	position: relative;
	[b]min-height: 100%;[/b]
	width:760px;
}

Two things wrong with this: the min-height is being ignored, because height and min-height need a parent with a set height… to do the min-height trick, you need to set html and body elements to height: 100%.

After doing that, you cannot then add a top margin… nor top padding. Anyone who is supposed to be at least 100% high cannot then be told to be higher/taller. You can’t eat more than 100% of a candy bar, can you?

Some inner element would have to have the margin-top. This same inner element can have bottom-padding to make room for your footer, which I assume was supposed to be a sticky footer? Right now, it’s sticking to where the bottom of my browser USED to be, so it’s in the middle of the page when I scroll down. If you were doing a sticky footer, getting min-height to work correctly would make that work.

(sticky footer pseudo-code:


<html>
<body>
<#wrap>
<#someinnerelement/>
</#wrap>
<#footer/>
</body>
</html>

html, body {
  height: 100%;
}
#wrap {
  min-height: 100%;
}
/*IE6*/
* html #wrap {height: 100%;}

#someinnerelement {
  margin-top: 3em;
  padding-bottom: height of #footer;
}

#footer {
  position: relative;
  height: set height;
  margin-top: -theheight;
}

that’s basically what works)

links:


#nav a{color:#8dfcf8;}
#nav a:visited{color:#306865;}
#nav a:hover{color:#306865;}

Remember you can do this:
#nav a{color:#8dfcf8;}
#nav a:visited, #nav a:hover{color:#306865;}
but also, do not neglect :focus. Keyboarders generally should get the same benefits as mouse users:

#nav a{color:#8dfcf8;}
#nav a:visited, #nav a:focus, #nav a:focus{color:#306865;}


#active p{
	display:inline;
	display: -moz-inline-box;
	display: inline-block;
	height:29px;
	padding-left:0.6em;
	background-position: left top;
	background-repeat: no-repeat;
	background-image: url(img/btn_left.png);
	margin:-7px;
	font-size:1.5em;
	[b]z-index:1;[/b]
}

z-index can only be set like that on “positioned” elements (relative fixed or absolute). So right now, this is ignored by all browsers.
I’m not sure display: inline is doing anything for you there. If you were going for accomodating IE, it comes afterwards (so then also needs to be hidden from smarter browsers).

p {
display: -moz-inline-box; (sometimes inline-box works better than inline-block but it depends on what you’re doing… also, this is only for Gecko engines running the equivalent of Firefox 2… FF 3 does not need this statement, but K-Meleon does)
display: inline-block;
blah…
}

  • html p {display: inline;} /ie6/
    *+ html p {display: inline;} /ie7/

(or a separate stylesheet for IE, whichever)


#footer{
	clear:both;
	width:100%;
	background-color:#000;
	position: absolute;
	bottom: 0;
}

Since abso-po’d elements are taken out of the flow, I do not believe they have the ability to clear anything anyways. Since you’ve set the bottom to “0”, that’s where it stays… even if I scroll.

Now if you wanted it to always be at the bottom of the browser/viewport (so moves as people scroll) then you want position: fixed… does not work in IE6, but in those cases we give IE6 special position: absolute rules and maybe some Javascript. I find fixed footers have some problems and usually try to avoid them (you can’t scroll from side to side with those of the content inside is wider than the browser viewport for example).

Hope some of that helps.

Hi, thanks for using the sitepoint forums btw. And welcome to sitepoint!

Well i tried it in chrome and i must say i do like the layout; however, regarding your issue. When I switch browsers i dont see any lack of a border in chrome.
The only difference i see in chrome is that the bottom image on Hover seem to grow slightly bigger and have get an extra space in between them.

First, thanks a lot for the time you took to answer my question :slight_smile: My CSS skills are obviously a bit rusty. And yes, my problem is with the bottom images.

Good to know, I’ll probably do the same as from now. I’ve never encounter that problem, but I guess better prevent it.

For now, the anchor are there only as placeholder… I’m not shure yet if I’ll show all the image on the same page or different. The alt and height properties will be created with PHP. I’ll try to remember that.

Here’s the result with the first solution: http://lynxdaemon.net/test/link_problem.jpg :confused: (I put the link in red to better show the problem) Unless I’ve forgotten something… Changing the padding/margin doesn’t help.

This works, thanks!

I forgot about that. Thanks for the reminder :slight_smile: shame on me

Funny, I found that trick in a Sitepoint book, and it was the first time I was trying it :wink: I guess I’ll go back to font:100%, as you suggest. Any reason to prefer the body over the html element?

Ok, I see what I was trying to do here, and I miserably failed. I wasn’t trying to do a sticky footer. I just wanted a footer that will be either at the bottom or the page OR the bottom of the html page, whichever is lower. I tried different thing and, not only did it failed, but what you see there are residual try-and-error. I guess I’ll have to scrap that and try again.

Noted, I won’t forgot anymore :slight_smile:

Mmm this came from a tutorial for resizable button. Since the display:inline doesn’t seem to bother the other browser, I may leave it there anyway… just so that I’ll remember why it’s there. I’ll think about it.

You’re right. As I said, I just completely messed up the footer. I’m working on it. I’ve updated the web version with the new change.

You’ve been a great help, Thanks!

Here’s the result with the first solution: http://lynxdaemon.net/test/link_problem.jpg (I put the link in red to better show the problem) Unless I’ve forgotten something… Changing the padding/margin doesn’t help.

Normally the anchors would wrap entirely around the images because, like all inlines, they expand their dimensions to that of their content, but something seems to be limiting the height of the anchors there… maybe some other code I missed?

Funny, I found that trick in a Sitepoint book, and it was the first time I was trying it I guess I’ll go back to font:100%, as you suggest.

I’ve also seen the trick in Dan Cedarholmes’ Bulletproof Web Design (I think that was the name of it). If you do a search on the forums for 62.5% px em, or some similar set of terms, there are two threads floating around (2009? 2008?) that really go all into depth as to where the idea came from and why it’s been rejected… more in depth than I went.

For now, the anchor are there only as placeholder… I’m not shure yet if I’ll show all the image on the same page or different.

I do that all the time while in developement… I just meant, your :visited state my vary per browser when you have many href’s going to #. Of course when you put real urls in there that won’t be an issue anymore.

I wasn’t trying to do a sticky footer. I just wanted a footer that will be either at the bottom or the page OR the bottom of the html page, whichever is lower.

Despite the name, what you just described as wanting is known as a “sticky footer”… sticks either to the bottom of the page or the bottom of the content, but does not ride up like a wedgie to the bottom of content shorter than the viewport. I’m starting to think it’s a silly name, since many people seem to use the term sticky to mean a fixed footer (whose name does make sense because it uses position: fixed).

So, what you said you wanted, you can use a version of the code I posted, as that’s a pretty standard sticky footer (created by SitePoint’s own Paul O’Brien : )

Since the display:inline doesn’t seem to bother the other browser, I may leave it there anyway…

Since it’s getting overridden by the display: inine-block, it’s being ignored and will do no harm.

Any reason to prefer the body over the html element?
There was, but I’ve forgotten it. Though the 100% height thing, that does need to go on both html and body elements together… and if I need two background images, I’ll throw one on the html element because it’s there and it can.

Glad it’s getting where you want it. Good luck.