Comments (7)
Example: circle.md
The code that is actually displayed on the website is within <style>
, notice, it's namespaced with .snippet-demo__
so the styles don't conflict with the global ones or other snippets.
I'm suggesting to autoscope the selectors during the build script and forget about manually creating a demo -- the demo is created via the build script using the actual code.
Current
Snippet creator manually creates the demo, repeating code
#### Demo
<div class="snippet-demo">
<div class="snippet-demo__circle"></div>
</div>
<style>
.snippet-demo__circle {
border-radius: 50%;
width: 2rem;
height: 2rem;
background: #333;
}
</style>
New
The build script does it using the actual code within the blocks automatically.
#### Demo
<!-- Leave this blank, the build script will generate the demo -->
Generated demo
<div class="snippet-demo" data-scope="circle">
<div class="circle"></div>
</div>
<!-- Not sure how to do this reliably -->
<style>
[data-scope="circle"] .circle {
border-radius: 50%;
width: 2rem;
height: 2rem;
background: #333;
}
</style>
Any suggestions on how to do this efficiently would be nice.
from 30-seconds-of-css.
It may be better to generate a SCSS or .less string and pass it to the parse for output because then you merely need to wrap the style with the namespace selector and it should do it for you.
Yeah I was thinking this. I thought a smart parser would be needed because my quick tries with regex were failing.
But with SCSS you can just stick everything inside a single block and it works. It shouldn't be too hard to convert the SCSS to CSS with the script.
from 30-seconds-of-css.
I may be misunderstanding you, but won't generating a custom scope for the styles just repeat the code itself anyways? Or are you suggesting we move the namespacing chore to the build script?
from 30-seconds-of-css.
prepend any CSS selector with a data scope selector?
The problem is that to understand this, the design needs to account for complex cases with several classes in the code. It may be better to generate a SCSS or .less string and pass it to the parse for output because then you merely need to wrap the style with the namespace selector and it should do it for you.
Less and SCSS generators can also be used to generate a giant demo CSS too which may be helpful instead so that the CSS loads with the page, and the demo html gets styled at render so that demo blocks don't need a style tag.
from 30-seconds-of-css.
either that or less, both will namespace inside the single block very similarly. It should be pretty easy and regex should be minimal. Gotta love those build tools right?
from 30-seconds-of-css.
Resolved in #103
from 30-seconds-of-css.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.
from 30-seconds-of-css.
Related Issues (20)
- [FEATURE] Multiline truncation HOT 2
- how to build this? HOT 19
- [BUG] Animation / Button Border Animation not clickable HOT 4
- [QUESTION] Used color scheme? HOT 2
- PWA feature HOT 3
- Chinese translation HOT 8
- Sorry, I am coming again. HOT 1
- Reinstate old UI and website link HOT 30
- [BUG] offscreen snippet links to scetchy/phising website HOT 1
- Scam site linked in one of the snippets HOT 1
- Change the selection color HOT 2
- [Enhancement] Fix typo in about section on the html page HOT 1
- A (hopefully) better Hamburger Button HOT 2
- Adding More Snippets for CSS HOT 5
- Add side effect note for the css rules HOT 2
- The preview image in "Image Rotate on Hover" is broken. HOT 2
- Is 30-seconds-of-css not participating in Hacktoberfest? HOT 2
- CSS Neumorphic Buttons HOT 2
- CSS : Neumorphic Buttons HOT 2
- Website horizontal scroll (CSS issue) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 30-seconds-of-css.