I frequently hear that I should not use id
attributes on the HTML elements for styling purposes in CSS. However is this always the case? Let say you have multiple lists in your application (ul
) that have a class horizontal-list
. However you want to apply some unique styling for each ul
can you then add an id
and use it like this?
#food .horizontal-list {
}
#food .horizontal-list li {
}
Here you only use it to separate the elements. Or are you supposed to make a class instead for each unique list. Does "Don't use id's
for styling purposes` only apply if you use it like this?
#food {
/* loads of attributes */
}
Could someone explain when it is okay to use id's?