News for hackers. Stuff that matters.
Re:The Tilde is an Amazing CSS Selector by alanh on Thursday May 17, 2012 @01:30AM (#3985592)
Careful not to misunderstand the syntax. The linked article confusingly has this example:

    input:checked ~ #main > #findMe
… described thusly: “With the tilde character on #container input:checked would be able to target #findMe …”

Please note the tilde has nothing to do with #findMe. The tilde only relates the input element and #main, which are in-order siblings. (Adjacent in-order siblings, in fact, so + would have worked just as well as ~ in this example.)

Please also note that ~ does not select siblings; it selects following siblings.

    <i>italic</i> <a href="#">link</a> <b>bold</b>
With the above HTML, the following selectors are NOT equivalent:

    i ~ b {
       /* this will match the bold tag above */
    }
    b ~ i {
       /* this will NOT match any elements in this example */
    }
Re:The Tilde is an Amazing CSS Selector by grk on Thursday May 17, 2012 @03:14AM (#3985852)
Thanks for clarifying this.
Re:The Tilde is an Amazing CSS Selector by ricardobeat on Thursday May 17, 2012 @12:46AM (#3985474)
Unfortunately the tilde selector is crippled: it doesn't target all siblings, only the ones after the base selector.

To illustrate:

    <p>1</p>
    <p class="two">2</p>
    <p>3</p>
   
    .two ~ p { color:red; }
    // only "3" will be red
That prevents what would be the most useful cases, like unmarking sibling menu items, slides and the like.
Re:The Tilde is an Amazing CSS Selector by sirclueless on Thursday May 17, 2012 @12:05AM (#3985346)
This post abuses IDs. If you have something with the ID #main, it should be unique anyways or else you have invalid markup. If it's unique, why do you need a sibling selector to find it?

This post could be improved by using classes:

    #container input:checked ~ .main > .findMe { ... }
But really, the sibling selector is powerful enough that you might not need classes at all. I think the following selector makes a much more powerful statement of the kind of thing you can do now that you couldn't before:

    input:checked ~ div span { ... }
Re:The Tilde is an Amazing CSS Selector by alanh on Thursday May 17, 2012 @01:14AM (#3985551)
Two things very wrong with your last suggestion:

1. total lack of semantic value - you cannot possibly get more meaningless than “span inside a div” there. It makes for extremely brittle CSS.

2. You should be using classes rather than elements in your selectors when possible, not only to make the code more maintainable and flexible, but also because it’s more performant (if you care).

Re:The Tilde is an Amazing CSS Selector by ars on Thursday May 17, 2012 @04:55AM (#3986076)
> If it's unique, why do you need a sibling selector to find it?

That selector is not to find it, it's to say #main IS a sibling. If #main exists but is not a sibling then apply different css to it.

Re:The Tilde is an Amazing CSS Selector by sgdesign on Wednesday May 16, 2012 @10:40PM (#3985101)
Can't say I understood what it does from that post, so here's another description:

http://reference.sitepoint.com/css/generalsiblingselector

Re:The Tilde is an Amazing CSS Selector by latch on Wednesday May 16, 2012 @11:36PM (#3985268)
I had no idea what ~ did after reading that post. Should have simply stated that:

"The tilde (~) selector lets you target a sibling element. That is, an element that shares the same parent"

Could then explain how it's different than the + selector.

"This differs from the + selector which will only find an adjacent sibling (immediately following)."

I'd consider comparing it to the child and descendant selector, if I could word it properly. This is what I have which I'm not happy with:

"In some ways, the differences between + and ~ are like the differences between the child selector (>) and the descendant selector (a space), in that #header > a will only a elements directly under #header, while header a will target all a elements under #header, regardless of depth.

Re:The Tilde is an Amazing CSS Selector by alanh on Thursday May 17, 2012 @01:08AM (#3985535)
“…sibling element. That is, an element that shares the same parent.”

Unfortunately, that is not true. It only matches following siblings.

See my JSFiddle demo: http://jsfiddle.net/alanhogan/sSVCG/

(Also, HTML comments between elements apparently mess up IE7 and IE8.)

Re:The Tilde is an Amazing CSS Selector by StavrosK on Thursday May 17, 2012 @05:23AM (#3986148)
"+ will select the immediately following sibling, ~ will select any (one?) subsequent sibling" is plenty clear, I think?
Re:The Tilde is an Amazing CSS Selector by neduma on Thursday May 17, 2012 @12:15AM (#3985380)
This is far better then original article. +1
Re:The Tilde is an Amazing CSS Selector by bstar77 on Wednesday May 16, 2012 @11:29PM (#3985238)
It looks like it's just taking the place of having to attach an event to the radio button, doing a lookup on the sibling #find_me element and manipulating it's style via JS.

These types of things are great, the more we move away from JS DOM hacks the better.

Re:The Tilde is an Amazing CSS Selector by freditup on Wednesday May 16, 2012 @11:27PM (#3985232)
Thanks, I was confused too :D
Re:The Tilde is an Amazing CSS Selector by X-Istence on Thursday May 17, 2012 @12:21AM (#3985404)
Am I missing something, but that isn't valid CSS. You can't have selectors inside of a selector block in CSS...
Re:The Tilde is an Amazing CSS Selector by recursive on Thursday May 17, 2012 @12:34AM (#3985440)
You are definitely right. That isn't CSS. I'm not sure what it is.
Re:The Tilde is an Amazing CSS Selector by charliesome on Thursday May 17, 2012 @12:36AM (#3985450)
It's SCSS
Re:The Tilde is an Amazing CSS Selector by uxp on Thursday May 17, 2012 @02:50AM (#3985802)
The appropriate traditional CSS should be

    #container #findMe { /* ... */ } 
    #container input:checked ~ #main > #findMe { /* ... */ }
(or)

    #container > #findMe { /* ... */ }
    #container > input:checked ~ #main > #findMe { /* ... */ }
Re:The Tilde is an Amazing CSS Selector by drgath on Thursday May 17, 2012 @12:37AM (#3985453)
"Powered by Yii Framework + LESS"
Re:The Tilde is an Amazing CSS Selector by erma87 on Thursday May 17, 2012 @12:36AM (#3985452)
It's syntax from LESS/Sass, which allows nested selectors and will generate the appropriate CSS.
Re:The Tilde is an Amazing CSS Selector by alanh on Thursday May 17, 2012 @01:16AM (#3985554)
Oh, that’s what he meant by slider?

Why do some people call these sliders?

Things that show a series of images are called carousels (because they rotate!). And what if your “slider” (carousel) fades instead of transitioning with a horizontal wipe? Not sliding then! Sliders are things you drag and drop to select a value within a range (like a volume slider).

Had not seen carousels called “sliders” until two days ago, but I hate this misnomer more than anything.

Please also note that both Bootstrap and YUI call this pattern a “carousel,” and some of the most popular jQuery plugins do, as well.

Re:The Tilde is an Amazing CSS Selector by StavrosK on Thursday May 17, 2012 @05:27AM (#3986155)
I agree with you. Slider already has a meaning in windowing toolkits, carousel is what I've always known this HTML element to be called. No need to confuse things, we might want to implement actual sliders in HTML.
Re:The Tilde is an Amazing CSS Selector by snowwrestler on Thursday May 17, 2012 @01:35AM (#3985604)
If your "carousel" uses fade transitions, then it is not "rotating".

I don't think there is an accepted universal term. I try to stick to what it is actually doing...if it fades, it's a fader. If it slides it's a slider.

Re:The Tilde is an Amazing CSS Selector by alanh on Thursday May 17, 2012 @01:38AM (#3985608)
The problem is ambiguity. Overloading, as we programmers say.

Why choose an ambiguous word when a specific one exists?

Keep in mind the point of calling it anything at all is communication, and communication is a lot harder if people don’t hear what you mean.

Call it carousel, and someone either gets it, or asks what a carousel is.

Call it a slider, and half of your audience assumes you meant something else entirely.

(Also, saying a term is not “universal” is pretty much a tautology in the real world, and it is not a valid argument. And a carousel that fades between items is still rotating, just as ads are “in rotation” on the radio even though nothing turns around: yes, rotation is a somewhat ambiguous word, too.)

Re:The Tilde is an Amazing CSS Selector by UntitledNo4 on Thursday May 17, 2012 @01:42AM (#3985628)
It comes from Slide Show.
Re:The Tilde is an Amazing CSS Selector by tim_heap on Thursday May 17, 2012 @01:38AM (#3985611)
I wrote up something that actually demonstrates the idea of matching :checked elements to change the state of another element. Think styleable checkboxes!

http://jsfiddle.net/3CUvm/

Re:The Tilde is an Amazing CSS Selector by StavrosK on Thursday May 17, 2012 @05:20AM (#3986139)
Hmm, I wonder if we can simulate a Turing machine in css nowadays...
Re:The Tilde is an Amazing CSS Selector by evincarofautumn on Thursday May 17, 2012 @08:00AM (#3986549)
We can. Rule 110 has been implemented in CSS3[1]. (It can be done without any HTML, but that’s just silly.)

[1] http://eli.fox-epste.in/rule110-full.html

Re:The Tilde is an Amazing CSS Selector by StavrosK on Thursday May 17, 2012 @02:09PM (#3988260)
That's great! Although, how does it work? I can't set any bits...
Re:The Tilde is an Amazing CSS Selector by stesch on Thursday May 17, 2012 @05:02AM (#3986091)
This isn't CSS he is writing.