Answer the question
In order to leave comments, you need to log in
Who uses this approach in writing CSS?
Hi friends.
I switched to a component approach a long time ago, when each block is in its own folder (pug, scss, js, json).
It's scary to even imagine when I wrote all the code in one file (well, almost in one, except for mixins, a file with media and a couple more, but it was still tough), now, when projects are large and css turns into huge files, it was would be simply unrealistic.
But still, when the block is large, even with the help of the preprocessor, it can easily grow to more than 150 - 200 lines, which also starts to get a little annoying, because. when you want to see what you wrote for the screen < 768px, you have to scroll down, then up again, then down again. Yes, the files are certainly not that big, but still I want to minimize this.
Those. before there was this approach:
.container {
background: aqua;
&__item {
display: block;
&_active {
color: #000;
}
}
}
@media (max-width: 767px) {
.container {
background: chocolate;
&__item {
display: inline-block;
&_active {
color: #fff;
}
}
}
}
.container {
background: aqua;
@media (max-width: 767px) {
background: chocolate;
}
&__item {
display: block;
@media (max-width: 767px) {
display: inline-block;
}
&_active {
color: #000;
@media (max-width: 767px) {
color: #fff;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Perfectly normal approach. I write the same example:
.footer {
position: relative;
background-color: @dark-grey-blue;
color: @white;
font-size: 12px;
padding: 20px;
box-sizing: border-box;
@media @desktop {
height: 200px;
padding: 0;
}
&__text {
display: block;
text-align: center;
@media @desktop {
position: absolute;
top: 75px;
left: 15px;
width: 250px;
text-align: left;
}
}
}
The approach is excellent. No need to look for styles for an adaptive in different files, everything is compact and convenient.
I use a similar method.
.heading-line {
margin-left: 100px;
font-weight: 300;
@include mobile-wide {
margin-bottom: 15px;
margin-left: 40px;
}
}
I use the SMACSS methodology and in SASS I break the project into layers like this:
_mixins.scss
_variables.scss
_base.scss - here are all styles for tags, including resets and normalizes
_layout.scss - here are the main blocks like footer, header with naming for example .l-header
_modules.scss - here are styles like div.container, div.product__item
_themes.scss - here are styles that override some elements, for example, a promotional label or a buy button of a different color
_state.scss - here are all the styles that are responsible for the state of the button: active, a:hover and including media queries. So if you need to fix something for mobile layout, I immediately go here
styles.scss imports all of the above files. Read the doc for this preprocessor, it says that files that start with _ it concatenates into 1 file.
Sobsn for this I liked SCSS + SMACSS
This is a normal practice and has the right to life.
Although, for example, it’s more convenient for me to just put all the media in a separate file. This makes the code look cleaner and easier to maintain. But this is subjective, how you like it, how it is more convenient - do it
The approach is certainly very cool, but for 100/200 lines a separate file is somehow too much for me, about media, you can install clean-css in gulp, and run it only on the build, and create mixins with full media in the process)
) it looks like this to me:
.checked, input[type="text"]{
border: 2px solid @white;
background: @white;
position: relative;
font-size: @fontXS;
font-family: @fBold, sans-serif;
color: @fBlack;
padding: 10px ;
&:after{
content: '\f0d7';
font-family: FontAwesome, sans-serif;
color: @Green;
position: absolute;
right: 10px;
top: 13px;
}
.md-media({
margin-top: 10px;
});
.sm-media({
border-radius: 5px;
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question