theagilecoder
As my Phoenix project has grown bigger, all the custom CSS for all the pages put in a single app.css file feels wierd and problematic. What is the best practice in this regard ? Is there any way I can use separate CSS files for separate pages in my Phoenix app ?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thojanssens1
Use css imports?
theagilecoder
Thanks for the reply. In your suggestion, if I have
h1 {color: red}inreset.cssandh1 {color: blue}invariables.css, then how will that be correctly resolved? As far as I know, webpack just combines all the css into a single css file at runtime.thojanssens1
I use BEM class name conventions, so such conflicts don’t happen to me.
You can also use render_existing/3 in your layout template to include a CSS file per page.
lkuty
I use
render_existing/3and for example I have for CSS:and for JS:
In my
PageView, I have code to provide links to CSS and JS:In my live views, I use customized links:
Thus, the layout calls functions to render (provide HTML
linkandscript) CSS and JS. Note thatwebpack.config.jshas to have an entry for every use case or the file won’t be available since they are not imported fromapp.js.lucaong
This will be resolved according to the CSS cascading rules. It’s not something specific to Phoenix, it is about CSS in general.
In short, if you have two CSS rules that both could apply to an element:
The most specific one wins (e.g. if you have
<span class="danger">...</span>and the CSS rulesspan.danger { color: red; }andspan { color: black; }, the first would win because it is more specific (it targets and element and a class). Specificity is an important concept in CSS, worth a deeper look, as it has deeper ramifications than in this simple example.If the two rules are equally specific, the one that appears last in the code wins, by overriding the previous one.
You can use specificity of rules at your advantage to apply style to some elements and not to others. BEM class naming is one such way.
Allow me to make a pledge to all web engineers to take the due time to learn CSS well
It is a truly amazing language, one of the pillars of the web, and too often disregarded as a secondary topic. Good mastery of CSS is a powerful skill to have in a developer’s toolbox.
theagilecoder
Yes , I learned BEM today and will be using it from now on.