Workaround to the button outline on focus appearing behind the sibling button with float left

拈花ヽ惹草 提交于 2020-07-06 20:22:17

问题


Given this HTML:

<div>
    <button>Test1</button>
    <button>Test2</button>
</div>

And this stylesheet:

button {
    border: 1px solid #EEE;
    float: left;
}

button:focus {
    outline: thin dotted;
}

SSCCE: http://jsfiddle.net/DKpGA/

In the following jsfiddle the outline stays behind the next element if you focus on the first one (click and "drag" the first button to show just the bordered outline).

It happens in Firefox (edge) and IE10.

I tried to use z-index to control the z position of both element without success. I may be missing something.
Opera handles it gracefully, but Firefox and IE10 refuses to do so...

  1. How do I make the outline to appear in front of the related element and not behind the next for FF and IE10?
  2. Is there any mention in the spec regarding this behavior or this is vendor specific?

Screenshot showing the undesired behavior in FF: undesired behavior


回答1:


z-index only works for a position that is not the default static. So by setting it to relative, you will achieve your effect.

Here's a JSFiddle http://jsfiddle.net/DKpGA/2/

Note that specifying position:relative without top,bottom,left, or right attributes will usually not move your element and ruin the layout, however absolute removes it from the natural flow and puts it outside of other element's scopes, so be careful with it.



来源:https://stackoverflow.com/questions/16288444/workaround-to-the-button-outline-on-focus-appearing-behind-the-sibling-button-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!