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 Layout Techniques Positioning Schemes Positioning Schemes Challenge

How can I shorten this code without taking out any functionality?

I correctly completed the challenge, but it seems like I wrote more than I needed to... If not, then just ignore this post :p

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Positioning</title>
    <link rel="stylesheet" href="page.css">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="main-wrapper">  
        <header class="main-header">
            <h1 class="main-logo"><a href="#">My Work</a></h1>
            <ul class="main-nav">
                <li><a href="#">Design</a></li>
                <li><a href="#">Coding</a></li>
                <li><a href="#">Writing</a></li>
                <li><a href="#">Hire Me!</a></li>
            </ul>
        </header>
        <div class="content-row">
            <div class="primary col">
                <h1>I'm a Designer</h1>
                <p>I design beautiful user interfaces, then bring them to life with HTML, CSS, and JavaScript. I love including personal photographs of nature, people and everyday things in my designs.</p>
                <p>If you need a front-end designer for your next project, <a href="#">take a look at my work</a>, then <a href="#">get in touch</a>!</p>
            </div>
            <div class="secondary col">
                <h2>I Also Write</h2>
                <p>I like teaching others about the latest web in technology. So when I'm not designing or coding websites &amp; apps, you'll find me writing <a href="#">articles for my blog</a>.</p>
            </div>
        </div>
    </div>
</body>
</html> 
style.css
/* Complete the challenge by writing CSS below */
.main-header {
  position: relative;
}

.main-logo,
.main-nav {
  position: absolute;
}

.main-logo {
  top: 25px;
  left: 25px;
}

.main-nav {
  right: 25px;
  bottom: 30px;
}

.content-row {
  position: relative;
}

.col {
  top: 0;
  position: absolute;
}

.primary {
  left: 0;
}

.secondary {
  right: 0;
}

1 Answer

Stephen Bone
Stephen Bone
12,359 Points

Hi Frederik

Here's what I came out with.

Other than using existing rules for content-row's relative positioning and col absolute positioning they are basically the same.

.main-header, .content-row {
  position: relative;
}

.main-logo, .main-nav, .col {
  position: absolute;
}

.main-logo {
  top: 25px;
  left: 25px;
}

.main-nav {
  bottom: 30px;
  right: 25px;
}

.primary {
  left: 0px;
}

.secondary {
  right: 0px;
}

.col {
  top: 0;
}

Hope it helps!

Stephen