0
I recently started doing small projects using HTML& CSS but I find one thing doubtful when I look at other projects!
So, I use the class attribute in div tag and also in form tag and give their properties..but many people are writing the class in as many tags as possible.. Is what I am doing is correct? Or should I mention a class attribute for every tag in div tags or form tags and mention their properties..like many others do!! Can anyone explain why do anyone keep many class attributes?
9 odpowiedzi
+ 3
An ID can only reference one html element, however a class can 'group' elements so they can be referenced as a group. For instance, you have 5 divs, you want all the divs the same size so you give all of them a class which is written the exact same in all divs <div class="sizeclass">. This let's you style these in css by using one '.sizeclass {width...}. What if you want 3 of the divs purple and 2 green along with the uniform size? Then you do this: <div class="sizeclass purpleclass" or add an extra class="" but dont have to> for all the divs you want purple or green.
+ 1
I would say using a class in multiple Tags isn't necessary right or wrong but Just more comfortable.
Let's say you make a web-code which have four quarders with different lenght but same color, margin, allignment and etc. at that Point would I make one class named "Quarder" and use in line css to Change the size.
When you multiply a existing element like with a Blog multiple text "fields" why make always something new when you already have it and when you change size or something you need to Change the value one time instead of multiple Times.
+ 1
Oh! Ok. If it is, I have to use it then! It will be much easier I guess. I think it might make sense or I can understand this usage when I make a big project or projects which require every element property to change!
Thanks!! Felix.
+ 1
Set only class for elements you need to style, and make sure your code is dry (dont repeat yourself).
If you type same styling or group of styling more than 2 time it is good to use class and dont repeat yourself. So if you have many elements with for example red color, make class for it..
If you ever used bootstrap you will see benefit of classes because it allow you to type style much organized and faster. You can also make your own styling template and reuse it in many codes, like color palete, font styling, spacing (padding, margin...)
+ 1
PanicS I'm still learning CSS.. haven't started Bootstrap yet.. I will try for my next project and yes the code should be dry!.. to get a better understanding.
Thanks!
+ 1
pHANTOM|sTEELE Yes, I got this..in many projects..I have seen people using classes like the above "sizeclass purpleclass" I understood, will try for my next project.
Thanks!
+ 1
Prasuna For some feature you need JavaScript but not all of tham, better learn JavaScript before so you wont have problem to understand some of this.
Also there are similar libraries as bootstrap, like tailwind css, materialize and many more, bootstrap is very popular.
https://www.spec-india.com/blog/bootstrap-alternatives
My suggestion is to practice css and build lot of things before learning bootstrap, so you will have a strong css knowledge.
0
PanicS should I learn bootstrap after CSS or after JavaScript?
0
Ok! Thanks a lot!!PanicS