Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is it best practise to condense your CSS where possible?

Featured Replies

When you have the same values, used in different div's, where appropriate should you condense your code?

 

So if I've got some CSS.....

 

 

/*************************************

Latest Works Styles

**************************************/


#latestWorks {
background: white url('../img/boxBG.jpg') top left repeat-x;
float: left;
width: 591px;
border: 1px solid #bfc5c8;
}	

#latestWorks ul li {
	float: left;
	padding-bottom: 25px;
	width: 50%;
}

	#latestWorks ul li img {
		float: left;
		border: 1px solid #acacac;
		margin-right: 17px;
	}

	#latestWorks ul li p {
		padding-right: 10px;
	}


/*************************************

Latest Posts styles

**************************************/


#latestPosts {
background: white url('../img/boxBG.jpg') top left repeat-x;
float: right;
width: 246px;
border: 1px solid #bfc5c8;
}

#latestPosts ul li {
	padding-bottom: 25px;
}

 

 

Because the <ul>'s in both these divs are lined up horizontally, they both have a padding-bottom of 25px;

 

Is it good or bad practise to, wherever possible, streamline code to the following....

 

 

#latestWorks ul li, #latestPosts ul li {
padding-bottom: 25px;
}

 

 

On one hand it seems it could be more difficult to read if your grouping values in your CSS. On the other hand it's easier to change just one value to all the relevent elements.

 

Thoughts?

 

Ta!

Just think logically about the file as a whole, I'd only ever condense elements together that need to remain consistent with one another.

 

Should you or anyone else amend the file, they can edit one value and not disrupt the consistency of the site too much.

 

On the other hand if you condense absolutely everything, future amendments will be a nightmare as changing one value is going to have a knock on effect on everything else.

 

In the example posted I would condense those values.

It's good if you will always want these two elements to have the same attribute. The best way in this case is to give both containers a class so you can style them the same:

 

.latest ul li

 

Then you give individual styles using their ids if you need to after.

Edited by mrchristoph

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.