Too many classes vs flexibly readable css classes [closed] - html

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm working on a responsive theme that I want to sell. I really want to make it easy to understand at a glance what's going on. One of the tradeoffs of moving from foundation 3 to bootstrap 3 and Foundation 4 (in my opinion, and as noted elsewhere), is the nearer - verbose naming you have to adopt when designing for multpile screen sizes.
Thus, I've tried as much as possible to achieve something like this:
<a class="button soluks_button square_round no_bold">Button</a>
OR This
<a class="custom-button green square-round button-in-navbar text-shadow">Button</a>
Given I'm building my styles on top of bootstrap and foundation, is this too much? or is it okay as long as its readable?

You should make use of a CSS preprocess such as SASS or LESS to keep the HTML semantic and significantly easier for your end-users to work with.
Using the SASS directive #extend, you could give class names as you are currently doing, but extend them in the css rather than forcing the user to remember to include each one in the html. However, by using #extend, the classes could still be applied individually if needed/ if the user wanted to change the default. Something like this:
.button {
display: inline-block;
}
.square-round {
#extend .button;
border-radius: 5px;
}
.no-bold {
font-weight: normal;
}
.soluks_button {
#extend .square-round; // which extends .button by inheritance
background: blue;
}
Then your html could be much more semantic and just give the class of the actual element itself:
<a class="soluks_button no-bold">button</a>
And for the purpose of a versatile theme, to change the default or add an additional style a user could still do:
button

Related

Is it recommended to use simple CSS classes like .text-center? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm learning HTML/CSS, and I've seen some examples like using .text-center for text-align: center; (in Bootstrap3).
That is a little bit strange for me, because these classes' css style will never change, so I have to change their class when I need to change their style. For example, if I have to change an element with class="text-center" to text-align: right;, I'll change the class it uses to class="text-right" instead of changing class text-center's style.
Is there a detailed reason to use these fixed classes?
If so what is the general rule for using/not using fixed classes?
It depends how you manage your css.
Many avoid inserting style tags or css classes in their html tags, to avoid spending too long modifiying it afterwards.
However, sometimes, you can't make your css specific enough to apply a "text-center" to a tag without changing it somewhere else. So adding it directly to your html tag will allow specific modification.
Using classes instead of style tags makes your code look cleaner and you have one less parameter to check when going through it.
I hope I answered your question!

css ID with or without HTML element? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
In a css file, is it better to use css ID's with or without the HTML element?
For example, with HTML element:
div#header {
font-size: 2em;
}
Without HTML element:
#header {
font-size: 2em;
}
I understand that both examples will do the same thing, but I'm wondering if either example will affect SEO or loading times. I'm leaning towards using the example without the HTML element as this will result in a smaller CSS file, but I'm wondering if anyone else has thoughts/opinions/experience on this.
div#header {
font-size: 2em;
}
Will only be applied if the element holding the id is a div.
#header {
font-size: 2em;
}
Will work regardless of the element.
Since you should only use an id once you'd usually go for the second approach: it saves characters and therefore a tiny bit of loading time - not really noticable though.
If you are having several pages using the css but the #header element can be different using div#header can be a way to decide which style to apply to which page. If this is the case however, you probably want to use a class here.

Css utils class performance [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I see the trend of css utils class and I am wondering if there is an impact on performance for this style.
What will be a better way?
One - make your html element with bunch of utils classes like:
<div class="padding flex justifyCenter alignCenter textRight"></div>
Two - make your css ( with preprocessor like sass ) like this:
%flex {
// code
}
%textRight {
// code
}
div {
#extend %flex;
#extend %textRight;
}
h1 {
#extend %flex;
#extend %textRight;
}
Will output:
div, h1 {
// with flex and text right
}
Utility Classes will almost always be the optimal solution based off of the two examples you've provided.
The corresponding styles for the utility class tend to be quite small and the reference from HTML promotes reuse of these definitions. From a performance perspective they will have negligible impact since complex algorithms implemented in browsers and hashing allow them to reference rules and apply styles extremely quickly.
Using #extend or an equivalent can lead to huge files when generated from e.g. SASS since the selectors for the rules become massive with many clauses.
It is generally bad practice to use #extend a lot when creating styles as mixins are typically favourable.
If you've ever opened developer tools on a site with CSS where e.g. the grid elements all comprise of extended selectors then the performance is horrible as the browser tries to manage the selectors.
I'm not saying not to use extend but it should be used sparingly.
If you are in a situation where you need to use these utility classes often and have a preprocessor at your disposal you might be best making flex and textRight mixins and just #include them where you want those corresponding styles. This will give you the optimal CSS output since a preprocessor can condense the rules and prevent repetition.
If you are not using a preprocessor you're also fine using the defined utility classes in your HTML. It still beats inline css to apply a small rule e.g. text-align.

OO CSS/CSS components [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am wondering, which way is real objective oriented CSS where you can reuse components really quickly in a clean way.
Scenario 1:
HTML:
<button class="button button-submit">Submit</button>
CSS:
.button {
/* basic styles */
}
.button-submit {
/* special styles for submit button */
}
Scenario 2:
HTML
<button class="button submit">Submit</button>
CSS
.button {
/* basic styles */
}
.button.submit {
/* special styles */
}
I only see two negative aspects, one in each scenario.
In scenario 1 you might end up having really long class names.
In scenario 2, if you define .submit as it's own element/component, you end up with the old problem where you cannot reuse code fragments to stay the same in any place.
Scenario 1 would probably be the more OO one but like all technologies and methodologies I would use the one that suits your needs best and you are going to enjoy writing.
Currently I am rebuilding an ecommerce platform from the ground up and when researching wanted to adopt similar methods. I ended up ignoring ways similar to your first example due to the long class names like you mentioned.
The idea behind all of it is to make writing code easier, quicker and more reusable. As soon as one of those factors is impacted too much while trying to satisfy the other, the whole idea behind trying them in the first place is voided.
Just to note this is a purely subjective answer and everyone is different.
Some good articles on the various methodologies and practices that I used to help make a decision:
http://www.smashingmagazine.com/2012/04/16/a-new-front-end-methodology-bem/
http://webuild.envato.com/blog/how-to-scale-and-maintain-legacy-css-with-sass-and-smacss/
https://smacss.com/book/
http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
Hope this helps!
CSS is not OOP, you can however, use frameworks which allow to you code CSS in a DRY manner.
SASS
LESS

Should we give id's to <hr> <br> etc? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Just had a discussion on some html concepts and the question arises should we give id's to hr and br tags. Both do not contain/handle the content in any way and both have fixed functionality. So invoking the DOM on basis of id's is a good coding practice or not?
Take scenario suppose I want to apply css to a hr tag. One option is giving hr an id/class like
<hr id="hrIdName"></hr>
and use css like
#hrIdName
{
}
Other is enclose hr in div and then use selector to implement the css
<div id="hrIdName">
<hr>
</div>
and use CSS like
#hrIdName hr
{
}
Out of two which is a better approach and meets good coding practice?
I wouldn't do either. I have been working a lot recently with jQuery Mobile and the interesting thing about that is they assign classes based on the CSS function you want.
So for example, if you wanted a HR to have margin and padding, you could use:
<hr class="margin-padding">
It would be better this way because you could re-use your classes on the same page (as you would likely want to with a hr). Also you cant repeat id's.
EDIT
Or as peopel have aid on your comments, dont use them at all because div and span elements should be used.