question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: auto-escape special-characters in selectors

See original GitHub issue

Large-scale css codebases need special class name patterns that provide better structure. For instance two white-paper-like sites on the topic:

One major problem I see with these systems is the convoluted syntax, i.e.:

  • smacss sugests to call layout styles like .l-<class-name> (http://smacss.com/book/type-layout)
  • bem suggests to represent bem elements with a class like <block-name>__<element-name> or menu__item

Looking through either it is clear that expressive syntax is a real issue. Yet it shouldn’t be since we can use any characters in our selector names!

We could create much nicer class naming systems with more characters. For instance if we wanted bem block-names to be indicated with a class name like .@<block-name we could write it like this in our css code:

.\@block-name
    color red

.\@block-name {
    color: #f00;
 }

Escaping our css selectors sucks and scares away a good idea. It’s also error-prone to try and remember how to correctly escape every possible character. But there is a perfect solution: let stylus do the escaping for us! I’ll rewrite the above code for example:

.@block-name
    color red

.\@block-name {
    color: #f00;
 }

I think this would be an awesome feature of stylus because it woud make an awesome feature of css available to the masses.

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Jan 17, 2012

Was just wondering if Stylus supported this today. It is actually a good (imo) way to write more readable selectors. I could see it being used for module:marked-list or m:marked-list.

At least, while reading SMACSS I personally really didn’t like the way prefixing different types of selectors by b- instead of b: looks. A colon is much more descriptive and not easily confused with the name of the item.

0reactions
kreocommented, May 4, 2016

simple workaroud .{class}\@xs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support escaped characters in selectors · Issue #1218 - GitHub
Looks like selectors doesn't like special characters in their name ... but we won't support using those characters without escape sequences.
Read more >
Using special characters in selectors - ProcessWire
Looking at the source and the docs it seems like you can't escape special characters and the following aren't allowed:.
Read more >
Need to escape a special character in a jQuery selector string
I have a selector that is created like so (assume val attribute is something[4][2] in this example). var val = $(this). attr('val'); $select....
Read more >
CSS character escape sequences - Mathias Bynens
Basically, to escape any numeric character, just prefix it with \3 and append a space character ( ). Yay Unicode! Special characters in...
Read more >
Use CSS.escape() to escape QuerySelectorAll() - Rick Strahl
escape () function to escape a literal string and encodes any Selector specific characters. This includes encoding the : character which is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found