Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Last active October 23, 2020 14:37
Show Gist options
  • Save jamiebuilds/b403c07806f20815cb5ac32a674bf1b3 to your computer and use it in GitHub Desktop.
Save jamiebuilds/b403c07806f20815cb5ac32a674bf1b3 to your computer and use it in GitHub Desktop.

A way to address clipping

Problem: The inner element will have its outline clipped by the outer element

outer {
  display: inline;
  overflow: hidden;
}

inner:focus {
  display: inline;
  outline: 2px solid blue;
  outline-offset: 2px;
}

Solution: Unknown

outline-offset configure sides

This allows you to match the shape of an element more closely

element:focus {
  outline-offset: <all>;
  outline-offset: <top/bottom> <right/left>;
  outline-offset: <top> <right/left> <bottom>;
  outline-offset: <top> <right> <bottom> <left>;
}

outline-radius

This allows you to match the shape of an element more closely

element:focus {
  outline-radius: <same as border-radius>;
}

Style an ancestor element based on a specific child element having focus (imagine a message box that contains an input and several buttons)

child:focus {
  outline: none;
}
ancestor:has(child:focus) {
  outline: 2px solid blue;
}

Select the best outline color based on the current background color.

element:focus {
  outline: 2px solid color-contrast(...);	
}

currentBackgroundColor (proposed for colors spec)

Select the best outline color based on the current background color.

element:focus {
  outline: 2px solid color-contrast(currentBackgroundColor blue, yellow);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment