Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Foundations Selectors Grouping and Modifying Selectors

DRY?

Maybe this will come up in the next video, but shouldn't the DRY philosophy also apply to HTML? The CSS is efficient, but now the HTML repeats itself.

Let me give an example: In the video, there were 3 shapes - a square, circle, and ellipse. The CSS for each shape was almost identical, except that each shape had its own class name and there were differences in border radius and height. Using DRY, the CSS became more efficient. Back in the HTML, instead of using single class names for each shape, each shape required more information and repetition: square, square circle, square circle ellipse. Seems like it would be more efficient and specific to just say square, circle, and ellipse. The HTML is now less efficient to me, whereas before it was clear.

3 Answers

Ricky Catron
Ricky Catron
13,023 Points

If you learn PHP you can achieve DRY in html using include files. Personally I love this approach because instead of copying and pasting and editing over and over again I can have a section of code contained in an include file then simply call the file.

It is covered early in Build a simple php application http://teamtreehouse.com/library/build-a-simple-php-application

DRY less applies to HTML because the HTML dictates what actually is on the page, so if you need 20 paragraphs, you need 20 <p> tags, no matter how messy it makes your code look. He is copying and pasting paragraphs over and over to quickly show how the selectors do their job.

Aaron Watson
Aaron Watson
2,551 Points

To use an analogy of what John said it's like HTML is the lego bricks and CSS is the instruction manual how they fit together so it's quite different. You can't miss bricks out here and there! But you can use the same instructions how they fit together. :-)