Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

css - Outline is drawn incorrectly on Chrome if outline-style is set to "solid" (and not "auto")

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

... 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...