I am working on the styles of a series of pages with Bootstrap.
It turns out that recursively I have to use a series of properties. For example:
class="col-md-5 text-center border border-rounded"
This combination works well for me and I want to use it in different files. Under normal conditions, if it were a simple background color adjustment, for example, what I would do is name it the type class="miGenerica"
and then in my file I estilos.css
would add a line defining the style:
miGenerica {
// ... propiedades...
}
However, since it is a Bootstrap system, I do not see it possible to add the data with:
miGenerica {
col-md-5
border
}
So how can I generalize Bootstrap values to an external file so I don't have to copy them from file to file?
One possible answer is using SASS (SCSS) and with @extend , where you can add existing Bootstrap classes (or any other class):
One option that occurs to me, but I don't know if it's practical for what you're trying to do, is to add the recurring classes using Javascript.
In this way, you avoid writing so much code during the layout. However, as @PHPMyGuel points out in his answer , in the face of code review by other developers and later your own reviews, doing it this way is counter-intuitive, as the semantics of the code are lost. at first sight.
For example:
In this way, I have inserted the recursive classes to the appropriate elements (as long as JavaScript is enabled in the browser).
Personally, I wouldn't include the classes that define Bootstrap 's grid system in what you want to do, for the simple reason that on a visual level, they add a lot to the HTML . It is very useful to be able to see at a glance in the HTML the structure that defines Bootstrap . It's not the same to see this:
What to see this other:
Clearer the first, I think, both for you and for anyone who wants to get their hands on your code later.
The rest of your classes are pretty straightforward, you can take the CSS rules from these classes into your own.