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

Different behavior of my html elements while my css is the same...

Hi,

I am having some issues with a header I am building I am using flexbox and media queries to change the width of my pages on my wanted breakpoints.

However I am experiencing some weird behavior, sometimes when I go past a breakpoint my html elements change according to my media query and the styles put in to this media query, and sometimes at the exact same breakpoint they don't change whilst all the code is 100% the same I still get a different outcome from time to time...

Anybody has any idea what could be causing this? I would add pictures but I don't see an upload button here :/

Can you show some of your code?

1 Answer

So the problem occurs in the navbar

Here is html:

'''html <nav class="navbar-styles"> <div class="inside-nav-wrapper"> <a href="index.php"><img class="headerlogo" src="images/mobilelogo2.png" /></a> <ul> <div class="border-container"> <li><a class="headerlinks" href="assortiment.php">Assortiment</a></li> <li><a class="headerlinks" href="overons.php">Over ons</a></li> <li><a class="headerlinks" href="contact.php">Contact</a></li> <li id="link4"><a class="headerlinks headerlinks-webshop" href="webshop.php">Webshop</a></li> <li id="link5"><a class="headerlinks headerlinks-login" href="#">Log in</a></li> </div> </ul> </div> </nav> <div class="nav-border"> </div> '''

And here is the css:

'''css @media screen and (min-width: 1024px) {

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

PAGE NAV CONTENT STYLES

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

.navbar-styles{ border-radius: 0px; min-height: 100px; margin-bottom: 0; background-color: #4A4A4A; display:flex; justify-content: center; box-shadow: black 0px 0px 2px 2px; -webkit-box-shadow: black 0px 0px 2px 2px;

}

.headerlogo{ width: 300px; height: 150px; float:left; position:relative; display:inline; margin-left: 14px;

}

.inside-nav-wrapper{ width: 1024px; display: flex; justify-content: center;

}

.navbar-styles ul{ display: flex; flex-wrap: wrap; justify-content: left; padding-left: 15px; height: 125px;

}

.border-container{ border-left: 2px solid rgba(255,255,255,0.1); display: flex; flex-wrap: wrap; height: 100px; padding-top: 50px; margin-top: 25px;

}

.navbar-styles li { list-style-type: none; text-decoration: none; text-shadow: 3px 2px 4px rgba(0,0,0,0.50); width: 100px; padding: 7.5px; height: 30px; margin-left: 5px; text-align: center; font-weight: 400; font-size: 16px; cursor: pointer; }

.navbar-styles li:first-child{ margin-left: 15px; }

.navbar-styles li:last-child{ margin-left: 15px; }

.headerlinks{

position:relative;
text-decoration: none;
list-style-type: none;
color: #E5e5e5;

}

.headerlinks:hover{ color: white; text-decoration: underline; }

.headerlinks-webshop{

position:relative;
text-decoration: none;
list-style-type: none;
color: #4A4A4A;

}

.headerlinks-webshop:hover{ color: black; text-decoration: none;

}

.headerlinks-login{ position:relative; text-decoration: none; list-style-type: none; color: #4A4A4A;

}

.headerlinks-login:hover{ color: black; text-decoration: none;

}

link4{

background-color: #ffa500;
border-radius: 3px;
text-align: center;
box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
-webkit-box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
text-shadow: none;

}

link4:hover{

box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
-webkit-box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
opacity: 0.9;
text-decoration: none;
color: black;

}

link5{

background-color: #ffa500;
border-radius: 3px;
text-align: center;
box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
-webkit-box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
text-shadow: none;

}

link5:hover{

box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
-webkit-box-shadow: rgba(255,255,255,1.0) 0px 0px 2px 2px;
opacity: 0.9;
text-decoration: none;
color: black;

}

.nav-border{ width: 100%; height: 5px; background: #BF0B21; -webkit-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.75); -moz-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.75); box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.75); z-index: 200; position:relative;

}

}

@media screen and (min-width: 1024px) and (max-width: 1299px) {

.headerlogo{ width: 250px; height: 125px; margin-left: -50px; margin-top: -20px; margin-right: 50px; }

.border-container{

height: 60px;
padding-top: 25px;
margin-top: 20px;

}

.navbar-styles ul{ height: 75px; }

.navbar-styles li { padding: 5px; text-align: center }

.navbar-styles li:first-child { margin-left: 100px; }

.navbar-styles li:last-child { margin-left: 25px; }

}

@media screen and (min-width: 1300px) and (max-width: 1599px) {

.flex-wrapper-content{ width: 1250px; }

.flex-wrapper-content-bottom{ width: 1250px; }

.inside-nav-wrapper{ width: 1250px; }

.navbar-styles ul{ height: 85px; }

.navbar-styles li { width: 125px; font-size: 20px; padding: 5px; margin-left: 50px;

}

.navbar-styles li:first-child { margin-left: 50px; }

.navbar-styles li:last-child { margin-left: 50px; }

.headerlogo{ width: 250px; height: 125px; margin-left: -50px; margin-top: -15px; margin-right: 50px; }

.border-container{

height: 75px;
padding-top: 37.5px;
margin-top: 20px;

}

}

@media screen and (min-width: 1600px) and (max-width: 100000px) {

.inside-nav-wrapper{ width: 1600px; display: flex; justify-content: center;

}

.headerlogo{ margin-left: 0px; }

.border-container{ padding-left: 50px; }

.navbar-styles ul{ padding-left: 25px; border-style:none; }

.navbar-styles li { font-weight: 400; font-size: 22px; margin-left: 50px !important; width: 150px; height: 50px; padding: 15px;

}

.flex-wrapper-content{ width: 1600px; }

.flex-wrapper-content-bottom{ width: 1600px; }

}

'''