In Safari 5.1.3 I have just noticed that, when writing a CSS adjacent sibling selector (er the +
one) and when referencing a <nav>
element - the browser fails to honor the CSS.
So:
h1 + p { ... } /* works fine */
h1+p { ... } /* works fine */
and
h1 + nav { ... } /* works fine */
h1+nav { ... } /* but, does NOT work */
I've tested these with other html 5 elements (section, article, aside) and they seem to work fine. Until you put a nav element into the mix; then it breaks. Here is a jsfiddle.
This is proving frustrating as my rails asset packer is minifying the css and taking out unnecessary spaces. This isn't an issue for IE7, Firefox, Chrome or Opera - but Safari 5..
Anyone else had similar? Know why? Know a way to fix?
Adjacent Sibling Selector (+)The adjacent sibling selector is used to select an element that is directly after another specific element. Sibling elements must have the same parent element, and "adjacent" means "immediately following".
The CSS adjacent sibling selector is used to select the adjacent sibling of an element. It is used to select only those elements which immediately follow the first selector.
With the adjacent-sibling selector, you can apply styles to elements based on the elements which immediately precede them in the document.
The ("element ~ siblings") selector selects sibling elements that appear after the specified "element". Note: Both of the specified elements must share the same parent.
This is definitely a Safari bug and you should report it using Safari > Report Bugs to Apple... on a Mac or Help > Report Bugs to Apple... on a PC (or the toolbar button if it's displayed on your Safari toolbar).
The easiest way out of this is to disable CSS minification if Asset Packager has an option for it.
If it doesn't have such an option, there exists a quick and dirty workaround: if you only have one nav
element directly following your h1
, you can use the general sibling selector ~
instead as Safari doesn't appear to have any problems with it:
h1 ~ nav { ... } /* works fine */
h1~nav { ... } /* works fine */
jsFiddle preview
If you have multiple nav
elements following your h1
, you'll have to override the styles manually for the successive nav
elements using h1 ~ nav ~ nav
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With