This repository was archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from mobify/desktop-override-mixin
Add a desktop override mixin
- Loading branch information
Showing
6 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Check if the current selector is nested | ||
// | ||
// @return [Boolean] | ||
|
||
@function parent-exists() { | ||
@if & { | ||
@return true; | ||
} | ||
@else { | ||
@return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
// Style override | ||
// === | ||
// | ||
// Allows overriding existing styles with extreme specificity while keeping | ||
// source code clean and readable. Only use this for overriding 3rd-party CSS | ||
// that cannot be changed. Does not override !important or inline styles; those | ||
// must be dealt with separately. | ||
|
||
|
||
// Configurable variables | ||
// --- | ||
|
||
// The default selector used to build the override. Must select the <head> tag. | ||
// The default value selects <head id="!"> which is short (since it’s prepended | ||
// to every wrapped selector) and obscure (to help guarantee uniqueness). Since | ||
// it’s a special character in CSS, the `!` must be escaped. Since the '\' is a | ||
// special character in SCSS, the '\' for the '!' must be escaped. | ||
|
||
$style-override-head-selector: '#\\!' !default; | ||
|
||
|
||
// Style override | ||
// --- | ||
// | ||
// @param $degree [Number]: The “force” of the override. Effectively the number | ||
// of id-level selectors you need to override. | ||
// @param $head-selector [String]: An id selector that matches the <head> tag. | ||
|
||
@mixin style-override($degree: 1, $head-selector: $style-override-head-selector) { | ||
$selector-chain: ''; | ||
|
||
// Build an id selector by chaining the same id onto itself once more than | ||
// the specified degree. So if degree: 4, we get #id#id#id#id#id. | ||
|
||
@for $i from 1 through $degree + 1 { | ||
$selector-chain: $selector-chain + $head-selector; | ||
} | ||
|
||
// Since <body> is a following sibling of <head>, we confer nested selectors | ||
// anywhere in the <body> with the extra specificity by wrapping them in | ||
// this: | ||
|
||
@if parent-exists() { | ||
@at-root #{$selector-chain} ~ body & { | ||
@content; | ||
} | ||
} | ||
@else { | ||
@at-root #{$selector-chain} ~ body { | ||
@content; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters