5

I am seeing this behavior for Chrome on a Mac (haven't tested it on Windows yet). Also, as this work is for a chrome extension, I am okay with getting a solution that is relevant for Chrome only (does not have to work cross-browser for now).

Issue: The browser seems to be drawing the "outline" differently around elements depending on whether the outline-style is "auto" or not.

When drawing an outline around an tag that is the parent of an "img", for something like this:

 <a href="image.com">
   <img class="profile_photo_img" src="imageSrc.jpeg" width="50" alt="Steve Jobs" height="50">
 </a>
  • If the outline-style is "auto", the outline is drawn correctly. i.e. Chrome takes into account the dimensions of the inner image to render an outline around the tag. (see the green outline in the screenshot).

enter image description here

  • If the outline-style is "solid" or any other regular style, the outline is drawn only around the outer tag disregarding the dimensions of the inner child.

enter image description here

The CSS that I am applying looks like this:

.class-name:focus {
   outline: 4px auto #068065 !important;
   outline-offset: 2px !important;
 }

1) Is there a way to fix this or work around this i.e. have the browser draw the outline correctly for outline-style "solid" as well?

2) Where should I look to read more about this? Maybe some informal documentation or access to the relevant code?

tanushree
  • 763
  • 1
  • 7
  • 20
  • 1
    Recently ran into a related issue on Chrome on Windows: http://stackoverflow.com/questions/17141865/outline-offset-does-not-get-applied-on-chrome-windows-when-outline-style-is-aut – tanushree Jun 17 '13 at 11:46
  • Draw your outline on img, I've already seen this behavior with links few times but never yet in chrome, since i avoid this for long :) (to myself: funny how you get habits and never rethink it ) – G-Cyrillus Jun 17 '13 at 12:00
  • I am changing the style of the element that gets the focus on tabbing. The "a" element gets the focus, the "img" does not. I am hoping to keep things clean by applying the style only to the element that receives focus (instead of its children etc). Makes sense? – tanushree Jun 17 '13 at 12:10
  • a:focus img ? doesn't work ? why should it be nonsense ?, you may add tabindex="0" to img if you it to catch focus on click ;) – G-Cyrillus Jun 17 '13 at 12:14
  • Sometimes anchor tags contain several elements (not just one image). In that case, we need the outline to be applied to the anchor tag container and not the contained image only. So I don't want to make a special case for scenarios when there is only one image in an anchor tag. This is my understanding at the moment. Maybe I am missing something. – tanushree Jun 17 '13 at 13:49
  • Linking a similar question: http://stackoverflow.com/questions/3975587/outline-applied-to-an-anchor-containing-an-image-isnt-the-right-height-in-chrom? – tanushree Jun 17 '13 at 13:50
  • oki, i understand about the strict a:focus. :) – G-Cyrillus Jun 17 '13 at 13:51

1 Answers1

2

... Set display:inline-block to your link, so layout is activated :)

test : http://codepen.io/gcyrillus/pen/GFzrs

I see no auto outline in FF 21.0

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129