The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> best practice and speed for repeated elements
turpentyne
post Sep 1 2019, 06:56 PM
Post #1





Group: Members
Posts: 1
Joined: 1-September 19
Member No.: 26,980



Kind of a general question, but I'm wondering if anyone knows for sure which is best.

When I have a stylesheet where a declaration exists several times, I tend to think I can simplify and clean things up by applying it to multiple classes and Ids at a time. This seems best practice, but I wonder if it's really any faster.

example... which is faster, better, best practice? Imagine a scenario where it isn't just three items, but 20 or more. (note: To simplify, I wrote ''several other declarations" rather than a bunch of random declarations.)

This:

.item1 { width: 100%; /* several other declarations */ }
.item2 { width: 100% /* several other declarations */}
.item3 { width: 100% /* several other declarations */}



Or this, which I tend to do... but I'm not sure it's really any quicker... sometimes it even seems like it's More lines, though I'm trying to get rid of duplication:

.item1,
.item2,
.item3 { width: 100%; }

.item1 { /* several other declarations */ }
.item2 { /* several other declarations */ }
.item3 { /* several other declarations */ }



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Ivy Crawford
post Nov 4 2019, 06:00 AM
Post #2


Newbie
*

Group: Members
Posts: 10
Joined: 4-November 19
Member No.: 27,030



I'd listen to Christian J, you really need to keep in mind to have complexity and CSS/HTML code balanced.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th February 2020 - 06:16 AM