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 Selectors Advanced Selectors :not() – The Negation Pseudo-Class

Sean Flanagan
Sean Flanagan
33,235 Points

Why does Column C get forced under Column A?

Hi. I used the :not class to exclude Column A, but Column C was forced underneath it. Here's my HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Selectors</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/base.css">
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <div id="container">
        <nav>
            <a href="#col-a">Column A</a>
            <a href="#col-b">Column B</a>
            <a href="#col-c">Column C</a>
        </nav>
        <div class="row group">
            <div id="col-a" class="col">
                <h2>Column A</h2>
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris interdum arcu nisl, at vestibulum purus cursus ultrices. Sed consectetur faucibus velit, quis ultrices nisi.</p>
                <p>Donec rutrum magna mi, vitae congue elit egestas quis. Praesent ultrices rhoncus venenatis. </p>
            </div>
            <div id="col-b" class="col">
                <h2>Column B</h2>
                <p>nteger scelerisque nisl sit amet eleifend mollis. Fusce eu tristique massa, et vehicula risus. Fusce congue convallis enim eget dignissim. Quisque auctor erat et.</p>
                <p>Nulla faucibus, vel lacinia ex lacinia. Nunc ut odio mattis magna vulputate viverra et et ligula.</p>
            </div>
            <div id="col-c" class="col">
                <form>
                    <h2>Column C</h2>

                    <label for="name">Name:</label> 
                    <input type="text" id="name">

                    <label for="email">Email:</label>
                    <input type="email" id="email" placeholder="email@website.com">

                    <input class="btn" type="submit" value="Sign up">
                </form>
            </div>
        </div>
    </div>
</body>
</html>

And my CSS:

:root {
  background: #e3effb;
}

:target {
  background: #384047;
  color: white;
}

#col-c:target {
  background: #eff1f2;
  color: initial;
  box-shadow: 0 0 6px rgba(0,0,0, .2);
}

input:not([type="submit"]) {
  box-shadow: inset 0 2px 0 rgba(0,0,0, .15);
}

.col:not(:first-child) {
  margin-left: 15px;
}

Does anyone know why this happens please?

Thanks

Sean :-)

1 Answer

George Singleton
George Singleton
10,028 Points

Hi Sean. The problem is occurring because when you add the left margin to the columns, the total width becomes greater than the width of the page. This forces the browser to float the last column below the others.

You could either lower the left-margin value under your .col:not(:first-child) selector, or open the base.css file and change the width of the .col class (I changed mine to 30% for testing purposes and this seemed to work fine.)

Hope this helps.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi George. It did help.

Thanks

Sean