position fixed for internet explorer - html

When the screen width becomes less than 767, the menu turns into a burger and on IE it looks different.
The alignment of items with flex disappears (the burger button and the basket are pressed), I sin on the menu that is positioned with
using fixed (becomes fixed at the checkpoint), I think that on IE the menu still takes its
the place, because of which the alignment occurs with its consideration. If you comment out the menu, everything will be ok.
How to fix it?
enter image description here
header in static condition
enter image description here
<div class="header_body">
<a href="#">
<h1>ze<span>bra</span></h1>
</a>
<div class="wrap-align">
<nav class="header_menu">
<ul class="header_list">
<li>Home</li>
<li>Products</li>
<li>Shopping</li>
<li>Contact</li>
</ul>
</nav>
<div class="price">
<a href="#">
<img src="img/Shape1.png" alt="">
</a>
<span>$35.00</span>
<span>▼</span>
</div>
<div class="header_burger">
<span></span>
</div>
</div>
</div>
//css
.header_body {
position: relative;
display: flex;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
justify-content: space-between;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
height: 86px;
align-items: center;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
> a {
text-decoration: none;
color: $colorWord_header;
position: relative;
z-index: 5;
display: inline-block;
margin-right: 40px;
}
a > h1 {
font-size: 38px;
font-family: "HelveticaNeueCyr-Bold";
text-transform: uppercase;
}
a > h1 > span {
color: $logo_color;
}
}
.wrap-align {
width: 650px;
display: flex;
justify-content: space-between;
align-items: center;
}
.header_burger {
display: none;
}
.header_menu {
// margin-right: 118px;
}
.header_list {
display: flex;
position: relative;
z-index: 2;
li {
list-style: none;
}
a {
text-decoration: none;
display: inline-block;
color: $colorWord_header;
font-size: 18px;
font-family: "HelveticaNeueCyr-Regular";
padding: 34px 15px;
transition: all 0.3s;
&:hover {
color: #fff;
background-color: $bgc_head;
}
}
}
.price {
position: relative;
z-index: 5;
a {
text-decoration: none;
}
img {
vertical-align: baseline;
}
a + span {
font-size: 24px;
font-family: "HelveticaNeueCyr-Regular";
color: rgb(157, 157, 157);
margin: 0 10px;
}
span + span {
font-size: 18px;
color: rgb(157, 157, 157);
vertical-align: super;
cursor: pointer;
}
}
//#media
.header {
.header_burger {
display: block;
position: relative;
width: 30px;
height: 20px;
position: relative;
z-index: 3;
}
.header_burger:before,
.header_burger:after {
content: "";
position: absolute;
background-color: black;
width: 100%;
height: 2px;
left: 0;
transition: all 0.3s;
}
.header_burger:before {
top: 0;
}
.header_burger:after {
bottom: 0;
}
.header_burger span {
position: absolute;
top: 9px;
left: 0;
background-color: black;
width: 100%;
height: 2px;
transition: all 0.3s;
}
.header_burger.active span {
transform: scale(0);
}
.header_burger.active:before {
transform: rotate(45deg);
top: 9px;
}
.header_burger.active:after {
transform: rotate(-45deg);
bottom: 9px;
}
.header_menu {
position: fixed;
top: -100%;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(255, 255, 255, 0.941);
padding: 130px 0 0 0;
transition: all 0.4s;
z-index: 1;
}
.wrap-align {
width: 300px;
}
.header_menu.active {
top: 0;
}
.header_list {
margin: 0 0 0 20px;
display: block;
li {
// margin: 10px 0;
}
a {
padding: 10px 20px;
}
}
.price {
margin-right: -30%;
}
}

Related

How do I add text under my navigation bar?

Right, so I followed a tutorial and made a navigation bar in HTML, CSS, & JS (Note I am a beginner to web development) Anyways, I have different pages now for each part such as home, about, contact etc. How do I add a title and everything to the page under the navi bar?
let searchBtn = document.querySelector('.searchBtn');
let closeBtn = document.querySelector('.closeBtn');
let searchBox = document.querySelector('.searchBox');
let navigation = document.querySelector('.navigation');
let menuToggle = document.querySelector('.menuToggle');
let header = document.querySelector('header');
searchBtn.onclick = function() {
searchBox.classList.add('active');
closeBtn.classList.add('active');
searchBtn.classList.add('active');
menuToggle.classList.add('hide');
header.classList.remove('open');
}
closeBtn.onclick = function() {
searchBox.classList.remove('active');
closeBtn.classList.remove('active');
searchBtn.classList.remove('active');
menuToggle.classList.remove('hide');
}
menuToggle.onclick = function() {
header.classList.toggle('open');
searchBox.classList.remove('active');
closeBtn.classList.remove('active');
searchBtn.classList.remove('active');
}
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700;800;900&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: #dee1e2;
min-height: 100vh;
overflow-x: hidden;
}
header {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 80px;
background: #fff;
padding: 20px 40px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 15px 15px rgba(0, 0, 0, 0.5);
}
.logo {
color: #333;
text-decoration: none;
font-size: 1.5em;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.group {
display: flex;
align-items: center;
}
header ul {
position: relative;
display: flex;
gap: 30px;
}
header ul li {
list-style: none;
}
header ul li a {
position: relative;
text-decoration: none;
font-size: 1em;
color: #333;
text-transform: uppercase;
letter-spacing: 0.2em;
}
header ul li a::before {
content: ' ';
position: absolute;
bottom: -2px;
width: 100%;
height: 2px;
background: #333;
transform: scaleX(0);
transition: transform 0.5s ease-in-out;
transform-origin: right;
}
header ul li a:hover::before {
transform: scaleX(1);
transform-origin: left;
}
header .search {
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
z-index: 10;
cursor: pointer;
}
.searchBox {
position: absolute;
right: -100%;
width: 100%;
height: 100%;
display: flex;
background: #fff;
align-items: center;
padding: 0 30px;
transition: 0.5s ease-in-out;
}
.searchBox.active {
right: 0;
}
.searchBox input {
width: 100%;
border: none;
outline: none;
height: 50px;
font-size: 1.25em;
background: #fff;
border-bottom: 1px solid rgba(0, 0, 0, 0.5);
}
.searchBtn {
position: relative;
left: 30px;
top: 2.5px;
transition: 0.5s ease-in-out;
}
.searchBtn.active {
left: 0;
}
.closeBtn {
opacity: 0;
visibility: hidden;
}
.closeBtn.active {
opacity: 1;
visibility: visible;
transition: 0.5s;
scale: 1;
}
.menuToggle {
position: relative;
display: none;
}
#media (max-width: 800px) {
.searchBtn {
left: 0;
}
.menuToggle {
position: absolute;
display: block;
font-size: 2em;
cursor: pointer;
transform: translateX(30px);
z-index: 10;
}
header .navigation {
position: absolute;
opacity: 0;
visibility: hidden;
left: 100%;
}
header.open .navigation {
top: 80px;
opacity: 1;
visibility: visible;
left: 0;
display: flex;
flex-direction: column;
background: #fff;
width: 100%;
height: calc(100vh - 80px);
padding: 40px;
border-top: 1px solid rgba(0, 0, 0, 0.5);
}
header.open .navigation li a {
font-size: 1.25em;
}
.hide {
display: none;
}
}
<header>
Matteos Palm Tree
<div class="group">
<ul class="navigation">
<li>Home</li>
<li>About Me</li>
<li>Blog</li>
<li>Contact Me</li>
</ul>
<div class="search">
<span class="icon">
<ion-icon name="search-outline" class="searchBtn"></ion-icon>
<ion-icon name="close-outline" class="closeBtn"></ion-icon>
</span>
</div>
<ion-icon name="menu-outline" class="menuToggle"></ion-icon>
</div>
<div class="searchBox">
<input type="text" placeholder="Search Here . . ." </div>
</header>
<script type="module" src="https://unpkg.com/ionicons#5.5.2/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons#5.5.2/dist/ionicons/ionicons.js"></script>
I tried just adding simple text under all the code in it showed up inside of the navi bar (I used inspect to check where it is)
Because the header is absolutely positioned it's rendered outside the normal flow of the document so the section beneath it is effectively not aware of its existence, so any text after the header is placed underneath the header. We can solve this by setting the top margin of the section element to be the height of the header. I can see that you've set the header size as 80px and you've used this in a few locations so I've set a css variable so you only need to change the height in once place and your page won't break.
Some reading on positioning elements at w3schools.com and from Kevin Powell
let searchBtn = document.querySelector('.searchBtn');
let closeBtn = document.querySelector('.closeBtn');
let searchBox = document.querySelector('.searchBox');
let navigation = document.querySelector('.navigation');
let menuToggle = document.querySelector('.menuToggle');
let header = document.querySelector('header');
searchBtn.onclick = function() {
searchBox.classList.add('active');
closeBtn.classList.add('active');
searchBtn.classList.add('active');
menuToggle.classList.add('hide');
header.classList.remove('open');
}
closeBtn.onclick = function() {
searchBox.classList.remove('active');
closeBtn.classList.remove('active');
searchBtn.classList.remove('active');
menuToggle.classList.remove('hide');
}
menuToggle.onclick = function() {
header.classList.toggle('open');
searchBox.classList.remove('active');
closeBtn.classList.remove('active');
searchBtn.classList.remove('active');
}
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700;800;900&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
:root {
--navbar-height:80px;
--section-top-margin: 20px;
}
body {
background: #dee1e2;
min-height: 100vh;
overflow-x: hidden;
}
header {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: var(--navbar-height);
background: #fff;
padding: 20px 40px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 15px 15px rgba(0, 0, 0, 0.5);
}
.logo {
color: #333;
text-decoration: none;
font-size: 1.5em;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.group {
display: flex;
align-items: center;
}
header ul {
position: relative;
display: flex;
gap: 30px;
}
header ul li {
list-style: none;
}
header ul li a {
position: relative;
text-decoration: none;
font-size: 1em;
color: #333;
text-transform: uppercase;
letter-spacing: 0.2em;
}
header ul li a::before {
content: ' ';
position: absolute;
bottom: -2px;
width: 100%;
height: 2px;
background: #333;
transform: scaleX(0);
transition: transform 0.5s ease-in-out;
transform-origin: right;
}
header ul li a:hover::before {
transform: scaleX(1);
transform-origin: left;
}
header .search {
position: relative;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
z-index: 10;
cursor: pointer;
}
.searchBox {
position: absolute;
right: -100%;
width: 100%;
height: 100%;
display: flex;
background: #fff;
align-items: center;
padding: 0 30px;
transition: 0.5s ease-in-out;
}
.searchBox.active {
right: 0;
}
.searchBox input {
width: 100%;
border: none;
outline: none;
height: 50px;
font-size: 1.25em;
background: #fff;
border-bottom: 1px solid rgba(0, 0, 0, 0.5);
}
.searchBtn {
position: relative;
left: 30px;
top: 2.5px;
transition: 0.5s ease-in-out;
}
.searchBtn.active {
left: 0;
}
.closeBtn {
opacity: 0;
visibility: hidden;
}
.closeBtn.active {
opacity: 1;
visibility: visible;
transition: 0.5s;
scale: 1;
}
.menuToggle {
position: relative;
display: none;
}
#media (max-width: 800px) {
.searchBtn {
left: 0;
}
.menuToggle {
position: absolute;
display: block;
font-size: 2em;
cursor: pointer;
transform: translateX(30px);
z-index: 10;
}
header .navigation {
position: absolute;
opacity: 0;
visibility: hidden;
left: 100%;
}
header.open .navigation {
top: 80px;
opacity: 1;
visibility: visible;
left: 0;
display: flex;
flex-direction: column;
background: #fff;
width: 100%;
height: calc(100vh - var(--navbar-height));
padding: 40px;
border-top: 1px solid rgba(0, 0, 0, 0.5);
}
header.open .navigation li a {
font-size: 1.25em;
}
.hide {
display: none;
}
}
section {
margin-top:calc(var(--navbar-height) + var(--section-top-margin));
}
<header>
Matteos Palm Tree
<div class="group">
<ul class="navigation">
<li>Home</li>
<li>About Me</li>
<li>Blog</li>
<li>Contact Me</li>
</ul>
<div class="search">
<span class="icon">
<ion-icon name="search-outline" class="searchBtn"></ion-icon>
<ion-icon name="close-outline" class="closeBtn"></ion-icon>
</span>
</div>
<ion-icon name="menu-outline" class="menuToggle"></ion-icon>
</div>
<div class="searchBox">
<input type="text" placeholder="Search Here . . ." </div>
</header>
<section>
This is your section text
</section>
<script type="module" src="https://unpkg.com/ionicons#5.5.2/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons#5.5.2/dist/ionicons/ionicons.js"></script>

Item appearing above another rather than to the left of it?

I have a navigation that's horizontally scrollable on mobile devices.
I'd like to add text that says '👉 Scroll' so folks know to do so.
I've set up the text to appear on mobile only but now when I add this next to my nav html it appears above the nav rather than to the left of it. Essentially I'd like the nav links to shift right and accommodate the text.
I'm a massive noob so apologies in advance and I really appreciate any help.
Thanks!
HTML
<nav class="site-nav">
<div class="site-nav-left-wrapper">
<div class="site-nav-left">
{{#if #site.logo}}
<a class="site-nav-logo" href="{{#site.url}}"><img src="{{#site.logo}}" alt="{{#site.title}}" /></a>
{{else}}
<a class="site-nav-logo" href="{{#site.url}}">{{#site.title}}</a>
{{/if}}
<div class="site-nav-content">
<div class="mobileShow">👉 Scroll</div>
{{#if #site.navigation}}{{navigation}}
{{/if}}
{{#is "post"}}
<span class="nav-post-title {{#unless #site.logo}}dash{{/unless}}">{{post.title}}</span>
{{/is}}
</div>
</div>
</div>
<div class="site-nav-right">
{{#if #site.secondary_navigation}}
{{navigation type="secondary"}}
{{else}}
<div class="social-links">
<i class="fab fa-instagram fa-xs"></i>
<i class="fas fa-rss fa-xs"></i>
</div>
{{/if}}
{{#if #labs.members}}
<a class="subscribe-button" href="#subscribe">Subscribe</a>
{{/if}}
</div>
CSS
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1000;
background: #22003a;
}
.site-nav {
position: relative;
z-index: 100;
display: flex;
justify-content: space-between;
align-items: flex-start;
overflow: hidden;
height: 64px;
font-size: 1.3rem;
}
.site-nav-left-wrapper {
position: relative;
flex: 1 0 auto;
display: flex;
}
.site-header-background:not(.responsive-header-img) .site-nav-left-wrapper:after,
.site-nav-main .site-nav-left-wrapper:after {
content: "";
position: absolute;
top: 0;
z-index: 1000;
width: 40px;
height: 100%;
}
.site-header-background:not(.responsive-header-img) .site-nav-left-wrapper:after,
.site-nav-main .site-nav-left-wrapper:after {
right: 0;
}
.site-nav-left {
flex: 1 0 auto;
display: flex;
align-items: center;
overflow-x: auto;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
margin-right: 10px;
padding: 10px 0 80px;
font-weight: 500;
letter-spacing: 0.2px;
text-transform: uppercase;
white-space: nowrap;
-ms-overflow-scrolling: touch;
}
.site-nav-left .nav li:last-of-type {
padding-right: 20px;
}
.site-nav-logo {
position: relative;
z-index: 100;
flex-shrink: 0;
display: inline-block;
margin-right: 32px;
padding: 12px 0;
color: #fff;
font-size: 1.7rem;
line-height: 1.8rem;
font-weight: bold;
letter-spacing: -0.5px;
text-transform: none;
}
.site-nav-logo:hover {
text-decoration: none;
}
.site-nav-logo img {
display: block;
width: auto;
height: 21px;
}
.site-home-header .site-nav-logo {
display: none;
}
.site-nav-content {
position: relative;
align-self: flex-start;
}
.nav {
position: absolute;
z-index: 1000;
display: flex;
margin: 0 0 0 -12px;
padding: 0;
list-style: none;
transition: all 1.0s cubic-bezier(0.19, 1, 0.22, 1);
}
.nav li {
display: block;
margin: 0;
padding: 0;
}
.nav li a {
font-family: 'Noto Sans', sans-serif;
font-weight: 700;
display: block;
padding: 12px 12px;
color: #ff0072;
transition: opacity 0.35s ease-in-out;
}
.nav li a:hover {
color: springgreen;
text-decoration: none;
}
.nav li a:before {
content: "";
position: absolute;
right: 100%;
bottom: 8px;
left: 12px;
height: 1px;
background: #fff;
transition: all 0.35s ease-in-out;
}
.nav li a:hover:before {
right: 12px;
}
.nav-post-title-active .nav {
visibility: hidden;
opacity: 0;
transform: translateY(-175%);
}
.nav-post-title {
visibility: hidden;
position: absolute;
top: 9px;
color: springgreen;
font-size: 1.7rem;
font-weight: 400;
text-transform: none;
opacity: 0;
transition: all 1.0s cubic-bezier(0.19, 1, 0.22, 1);
transform: translateY(175%);
}
.nav-post-title.dash {
left: -25px;
}
.nav-post-title.dash:before {
content: "– ";
opacity: 0.5;
}
.nav-post-title-active .nav-post-title {
visibility: visible;
opacity: 1;
transform: translateY(0);
}
.site-nav-right {
flex: 0 1 auto;
font-size: 1.7em;
display: flex;
justify-content: flex-end;
align-items: center;
padding: 10px 0;
height: 64px;
}
.site-nav-right .nav {
position: relative;
margin: 0;
}
.site-nav-right .nav a {
white-space: nowrap;
}
.site-nav-right .nav a:before {
display: none;
}
.site-nav-right .nav li:last-of-type a {
margin-right: -12px;
}
.social-links {
flex-shrink: 0;
display: flex;
align-items: center;
}
.social-link {
display: inline-block;
margin: 0;
padding: 10px;
}
.social-link:hover {
fill: springgreen;
}
.social-link svg:hover {
fill: springgreen;
}
.social-link svg {
height: 1.8rem;
fill: azure;
}
.social-link-fb svg {
height: 1.6rem;
}
.social-link-wb svg {
height: 1.6rem;
}
.social-link-wb svg path {
stroke: #fff;
}
.social-link-rss svg {
height: 1.9rem;
}
.subscribe-button {
display: block;
margin: 0 0 0 10px;
padding: 4px 10px;
border: #fff 1px solid;
color: #fff;
line-height: 1em;
border-radius: 10px;
opacity: 0.8;
}
.subscribe-button:hover {
text-decoration: none;
opacity: 1;
}
.site-nav-right .nav + .subscribe-button {
margin-left: 24px;
}
.rss-button {
padding: 10px 8px;
opacity: 0.8;
}
.rss-button:hover {
opacity: 1;
}
.rss-button svg {
margin-bottom: 1px;
height: 2.1rem;
fill: #fff;
}
/* Special behaviors for home navigation */
.home-template .site-nav-main {
z-index: 100;
}
.home-template .site-nav-main .site-nav {
opacity: 0;
transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0s;
}
.home-template .site-nav-main .fixed-nav-active {
opacity: 1;
transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1) 0.05s;
}
#media (max-width: 700px) {
.site-home-header .site-nav {
margin-left: -5vw;
}
.site-nav-main {
padding-right: 0;
padding-left: 0;
}
.site-nav-left {
margin-right: 0;
padding-left: 5vw;
}
.site-nav-right {
display: none;
}
}```
Hello I3rett could you try putting this in an < a > tag, the div tag is not inline :D
-> If that doesn't work, try putting the < a > element inside site-nav-logo/nav-left

Dropdown Menu Working in Safari but not Chrome

I made a dropdown menu and it works perfect in safari, however when I open it up in chrome i can't see the dropdown when I hover over the link. Why is this? I obviously need it to work in both browsers for compatibility reasons.
* {
box-sizing: border-box;
}
h1 {
font-family: 'Arial';
font-size: 6vw;
}
h3 {
font-family: Arial;
font-size: 1.7vw;
text-align: center;
}
p {
font-family: 'Arial';
font-size: 1.7vw;
}
p1 {
font-family: 'Arial';
font-size: 3vw;
}
.header {
background-color: whitesmoke;
padding: 20px;
text-align: center;
}
body {
margin: 0;
background: whitesmoke;
font-family: 'Arial';
font-weight: 300;
font-size: 100%;
}
.main-nav {
display: flex;
}
.main-nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
position: sticky;
position: -webkit- sticky;
background-color: #DF744A;
top: 0;
width: 100%;
}
.main-nav li {
float: left;
}
.main-nav li a,
.dropdown {
display: block;
padding: 1.2em 2.2em;
text-decoration: none;
color: black;
text-align: center;
font-family: 'Arial';
font-size: 1.2vw;
}
.main-nav li a:hover {
background-color: #FFAE89;
}
li.products {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #DF744A;
min-width: 8vw;
z-index: 1;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
}
.products:hover .dropdown-content {
display: block;
}
.mainbody {
display: flex;
flex-wrap: wrap;
}
.updates {
flex: 20%;
background-color: #FEDCD2;
}
.section-1 {
flex: 80%;
background-color: whitesmoke;
display: flex;
}
.footer {
padding: 20px;
text-align: center;
background: #bfd8d2;
}
#media screen and (max-width: 600px) {
.main-body {
flex-direction: column;
}
}
.bands {
flex: 50%;
padding: 1em;
}
<div class="header">
<h1>Elle and Belle Design</h1>
<p1>Bespoke Handmade Headbands and Accessories</p>
</div>
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li class="products">
Products
<div class="dropdown-content">
Headbands
Earrings
Other
</div>
</li>
<li>Contact Us</li>
</ul>
</nav>
<div class="mainbody">
<div class="updates">
<h3>Updates</h3>
</div>
<div class="section-1">
<div class="bands">
<img src="oliviaband.jpg" alt="Olivia Band" width="330" height="400">
<img src="goldband.jpg" alt="Gold Band" width="330" height="400">
</div>
</div>
</div>
<div class="footer">
<h2>Footer</h2>
</div>
Few points:
.main-nav ul had overflow: hidden which was hiding .dropdown-content which overflows the ul.
li.products was missing position: relative this stops your .dropdown-content position: absolute spanning full browser width.
.dropdown-content I added left: 0 and right: 0 so it uses the width of the position: relative (li.products) parent.
I've updated your code in the below snippet.
* {
box-sizing: border-box;
}
h1 {
font-family: 'Arial';
font-size: 6vw;
}
h3 {
font-family: Arial;
font-size: 1.7vw;
text-align: center;
}
p {
font-family: 'Arial';
font-size: 1.7vw;
}
p1 {
font-family: 'Arial';
font-size: 3vw;
}
.header {
background-color: whitesmoke;
padding: 20px;
text-align: center;
}
body {
margin: 0;
background: whitesmoke;
font-family: 'Arial';
font-weight: 300;
font-size: 100%;
}
.main-nav {
display: flex;
}
/* This had overflow: hidden; */
.main-nav ul {
list-style-type: none;
margin: 0;
padding: 0;
position: sticky;
position: -webkit- sticky;
background-color: #DF744A;
top: 0;
width: 100%;
}
.main-nav li {
float: left;
}
.main-nav li a,
.dropdown {
display: block;
padding: 1.2em 2.2em;
text-decoration: none;
color: black;
text-align: center;
font-family: 'Arial';
font-size: 1.2vw;
}
.main-nav li a:hover {
background-color: #FFAE89;
}
/* Requires position: relative;*/
li.products {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
left: 0;
right: 0;
background-color: #DF744A;
min-width: 8vw;
z-index: 5;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
}
.products:hover .dropdown-content {
display: block;
}
.mainbody {
display: flex;
flex-wrap: wrap;
}
.updates {
flex: 20%;
background-color: #FEDCD2;
}
.section-1 {
flex: 80%;
background-color: whitesmoke;
display: flex;
}
.footer {
padding: 20px;
text-align: center;
background: #bfd8d2;
}
#media screen and (max-width: 600px) {
.main-body {
flex-direction: column;
}
}
.bands {
flex: 50%;
padding: 1em;
}
<div class="header">
<h1>Elle and Belle Design</h1>
<p1>Bespoke Handmade Headbands and Accessories</p>
</div>
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li class="products">
Products
<div class="dropdown-content">
Headbands
Earrings
Other
</div>
</li>
<li>Contact Us</li>
</ul>
</nav>
<div class="mainbody">
<div class="updates">
<h3>Updates</h3>
</div>
<div class="section-1">
<div class="bands">
<img src="oliviaband.jpg" alt="Olivia Band" width="330" height="400">
<img src="goldband.jpg" alt="Gold Band" width="330" height="400">
</div>
</div>
</div>
<div class="footer">
<h2>Footer</h2>
</div>
first issue is that the main-nav is hiding any content that flows outside of it's borders change to:
.main-nav ul {
overflow: visible;
}
Second is that the menu item you want to snap to needs to have position relative set, this tells any children with position absolute what it's reference container should be
li.products {
position: relative;
}
Lastly set the dropdowns position co-ordinates
.products:hover .dropdown-content {
top: 100%;
left: 0;
position: absolute;
}
.main-nav {
display: flex;
position: fixed;
top: 0;
background-color: rgba(0, 0, 0, 0.35);
z-index: 0.9;
height: 5vw;
width: 100%;
}
.main-nav ul {
list-style-type: none;
margin: 0 0 0 20vw;
padding: 0;
overflow: visible;
top: 0;
width: 100%;
height: 5vw;
}
.main-nav ul li {
display: inline-block;
text-align: center;
margin-left: 2vw;
height: 5vw;
}
.main-nav li {
float: left;
height: 5vw;
}
.logoimg {
height: 5vw;
width: auto;
float: left;
position: fixed;
margin-left: 1vw;
z-index: 1;
}
.main-nav li a, .dropdown {
display: block;
padding: 1.2em 2.2em;
text-decoration: none;
color: whitesmoke;
text-align: center;
font-family: 'tenderness';
font-size: 1.5vw;
height: 5vw;
border-bottom: 0.3vw solid transparent;
}
.main-nav li a:after {
display: block;
content: '';
border-bottom: 0.3vw solid whitesmoke;
transform: scaleX(0);
transition: transform 0.3s ease-in-out;
min-width: 6vw;
height: 1.15vw;
}
.main-nav li a:hover:after {
height: 1.15vw;
transform: scaleX(1);
}
li.products {
display: inline-block;
position: relative;
height: 5vw;
}
.dropdown-content {
display: none;
position: absolute;
background-color: rgba(0, 0, 0, 0.35);
min-width: 8vw;
z-index: 1;
left: 0;
right: 0;
}
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
text-align: center;
height: 5vw;
}
.products:hover .dropdown-content {
display: block;
}
This is my new code. I have added the bottom border to each li as you can see when the user hovers. However, I am wanting it to align with the bottom of the navigation bar, rather than directly under the text.
I have just put an estimated height in of 1.2vw so it looks just about right, however, it isn't exact and I was just wondering if there was a more precise and not so makeshift way of doing this?
Thanks
Mary

Navbar height on scroll

I am creating a simple navigation in angular 6, am using bem methodology and flexbox for css.
Here is the navigation markup:
<div class="main-header">
<nav class="main-nav" ng-sticky [offSet]="0" [addClass]="'main-sticky'" appMainNav #ref="appMainNav">
<div class="main-nav__logo " ng-sticky [offSet]="0" [addClass]="'main-sticky__logo'">
<img class="man-nav__logo-green" src="/assets/images/logo-white.png">
</div>
<div class="main-nav__toggle">
<i class="main-nav__bars fa fa-bars" ng-sticky [offSet]="0" [addClass]="'main-bars'"></i>
</div>
<ul class="main-nav__list " ng-sticky [addClass]="'main-sticky-link'" [ngClass]="ref.click === true? 'Navbar__ToggleShow' :''">
<li class="main-nav__item">
<a class="main-nav__link" href="#">Home</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link" href="#">About us</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link" href="#">What we do</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link " href="#">Projects</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link " href="#">Contact</a>
</li>
</ul>
</nav>
<div class="main-banner">
<h2>We are a team of
<strong>experts</strong>.</h2>
<p>Founded in 2014, the BDTS Poland specializes in IT personnel outsourcing for the areas of banking, insurance, telecommunications,
high-tech, pharmacy, logistics and many others</p>
<a href="http://en.astek.pl/about-us/" class="main-banner__green-button main-banner__arrow-right">Read more
<i></i>
</a>
</div>
</div>
Here is the mobile CSS for navbar:
#media only screen and(max-width: 768px) {
.main-nav {
margin: 0;
display: block;
position: inherit;
height: auto;
overflow: auto;
background: white;
}
.main-nav__list {
margin-top: 20px;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-nav__item:after {
content: '';
width: 1px;
}
.Navbar__ToggleShow {
display: flex;
}
.main-nav__logo {
position: relative;
bottom: 49px;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.man-nav__logo-green {
visibility: hidden !important;
}
.main-nav__bars {
display: flex;
justify-content: flex-end;
cursor: pointer;
padding: 26px;
font-size: 50px;
color: #00964e;
top: 0;
margin-top: -196px;
}
.main-nav__link {
color: #444;
}
}
In desktop version everything works fine: but in mobile version navbar increase its height on scroll and hamburger menu disappears,
Here is the solution I tried: (removing height in .man-nav)
.main-nav {
margin: 0;
display: block;
position: inherit;
overflow: auto;
background: white;
}
Now navbar height does not increase on scroll but hamburger menu disappear.
UPDATE - Here is the full CSS for navbar component:
#charset "UTF-8";
#font-face {
font-family: "icomoon";
src: url("/assets/fonts/icomoon.ttf");
}
.main-header {
width: 100%;
float: left;
display: block;
min-height: 100vh;
height: 100%;
background-size: cover;
background-position: center;
padding-bottom: 100px;
background-image: url("/assets/images/banner.jpg");
}
.main-sticky {
background-color: white;
height: 100px;
}
.main-sticky__logo {
position: relative !important;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.main-sticky-link .main-nav__link {
color: #444 !important;
}
.main-nav {
position: sticky;
align-items: center;
justify-content: space-around;
left: 0;
display: flex;
z-index: 2;
width: 100%;
}
.main-nav__logo {
position: relative;
}
.main-nav__bars {
color: white;
}
.main-nav__list {
list-style: none;
display: flex;
color: white;
position: relative !important;
}
.main-nav__item {
padding: 24px 27px;
position: relative;
}
.main-nav__item:after {
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
content: "";
display: block;
float: left;
background-color: #f5f5f5;
width: 2px;
height: 60px;
-webkit-transform: rotate(20deg);
transform: skew(155deg);
position: absolute;
right: 0;
bottom: 6px;
}
.main-nav__item:last-child::after {
content: "";
width: 0px;
}
.main-nav__item:hover::after {
width: calc(100% + 1px);
}
.main-nav__item:hover .main-nav__link {
color: #444;
position: relative;
z-index: 3;
}
.main-nav__link {
list-style: none;
font-size: 1rem;
color: white;
font-family: "proxima-nova-n6", "proxima-nova";
font-style: normal;
font-weight: 600;
}
.main-nav__bars {
display: none;
}
.main-banner {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.main-banner h2 {
font-size: 3.75rem;
line-height: 5.375rem;
margin-bottom: 1.5rem;
color: #fff;
font-family: "proxima-nova-n4", "proxima-nova";
font-style: normal;
font-weight: 400;
margin-top: 70px;
font-weight: normal;
}
.main-banner p {
font-size: 1.25rem;
font-weight: normal;
color: white;
text-align: center;
max-width: 700px;
margin-bottom: 3.375rem;
margin-right: auto;
margin-left: auto;
}
.main-banner__green-button {
height: 3.4375rem;
background-color: #00964e;
text-decoration: none;
color: #fff;
padding: 11px 13px;
display: inline-block;
box-sizing: border-box;
line-height: 27px;
border-radius: 30px;
border: 3px solid #00964e;
font-size: 1.125rem;
padding-right: 50px;
font-family: "proxima-nova-n6", "proxima-nova";
font-style: normal;
font-weight: 600;
position: relative;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
}
.main-banner__arrow-right::after {
font-family: "icomoon";
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
content: "" !important;
font-size: 33px;
}
.main-banner__green-button::after {
float: right;
content: "";
display: block;
width: 34px;
height: 34px;
margin-left: 10px;
top: 10px;
position: absolute;
right: 10px;
}
.main-banner__green-button:hover {
background-color: white;
color: green;
}
.main-banner__arrow-down {
transform: rotate(90deg);
width: 34px;
height: 34px;
position: absolute;
bottom: 176px;
margin-left: -17px;
left: 50%;
z-index: 2;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
background-image: url("/assets/images/icon-arrow-right.png");
}
#main-sticky {
background-color: white;
}
#media only screen and (max-width: 768px) {
.main-nav {
margin: 0;
display: block;
position: inherit;
height: auto;
overflow: auto;
background: white;
}
.main-nav__list {
margin-top: 20px;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-nav__item:after {
content: "";
width: 1px;
}
.Navbar__ToggleShow {
display: flex;
}
.main-nav__logo {
position: relative;
bottom: 49px;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.man-nav__logo-green {
visibility: hidden !important;
}
.main-nav__bars {
display: flex;
justify-content: flex-end;
cursor: pointer;
padding: 26px;
font-size: 50px;
color: #00964e;
/* position: absolute; */
top: 0;
/* bottom: 36px; */
/* right: 28px; */
margin-top: -196px;
}
.main-nav__link {
color: #444;
}
.main-banner__arrow-down {
display: block !important;
position: initial;
margin: 0 auto;
margin-top: 50px;
}
.main-banner h2 {
text-align: center;
}
}
Here is a link to the live demo
Here is GitHub repo if interested
What is wrong with my code? please help, any suggestions will be appreciated, thanks.
There is a lot to debug, here is what I spotted:
nav bar (.main-nav):
First of all, you got a script (index.js) that sets main-nav, main-nav__bars and main-nav__list position to fixed on scroll. You don't need to do that for all three components. Just set main-nav and let the children inherit.
Next you're better off changing height: auto to min-height: 125px (enough to fit the logo)
Then you need to set the nav .main-nav) overflow-x: hidden to eliminate the scrollbar on the right when overflow bugs occur.
Or better yet, make your logo itself and it's container (.main-nav__logo) have a fixed height that matches (height: 125px) and let the logo height: inherit. (you will need to crop your image for that to look nice. See reason on next section)
You're also overriding the display: flex to block with your media query. Remove that so you will be able to use the flex properties. Afterwards you can do something like: (append into your mobile media query)
.main-nav {
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
}
.main-nav__logo {
flex: 2 1 60%;
}
.main-nav__toggle {
flex: 2 1 30%;
}
.main-nav__list {
flex: 0 1 100%;
}
This should give you a result like this:
|-----------------------|----------|
| Logo | Bars |
|-----------------------|----------|
| |
| Nav ul |
| |
|----------------------------------|
Logo (.man-nav__logo-green):
Next your logo is 200x200 with lots of transparent margin, fix your logo by cropping it down using Photoshop or something to element the fixed margin. This will let your logo to fit in without overflowing the nav bar. (and more flexible in regards to margin styling)
a dirty solution is to change the logo's container to (.main-nav__logo) height: 160px and add a margin-top: -35px.
Hopefully that should make your life a bit easier. Regards.

Making two flex items align in a row

I have two flex box elements that are each supposed to take up 50% of the browser window.
Right now, from the way I've coded it, they only stack on top of each other.
How can I get these two to be inline with each other?
I've tried setting their containers to be inline-block while the children have 50% as their width.
Live reference: https://jsfiddle.net/mqefpdkt/
/*.desktop{
display: none;
}*/
.w50 {
width: calc(50% - .1rem);
}
.w50.border-left {
border-left: 1px solid #dddddd;
}
.blog-column {
min-width: 100%;
}
.blog-column .blog-item {
padding: 60px 40px;
transition: all 0.3s;
background: #fff;
}
.blog-column .blog-item:hover {
cursor: pointer;
}
.blog-column .blog-item:hover h2.highlight {
background: rgba(35, 220, 116, 0.7);
}
.blog-column .blog-item:hover h2.highlight:after {
height: 10%;
background: #23dc74;
width: 100%;
}
.blog-column .blog-item span.read-more {
font-size: 2rem;
}
.blog-column .blog-item span.read-more:before {
content: "";
display: block;
height: 2px;
width: 0;
background-color: transparent;
}
.blog-column .blog-item h2.highlight {
padding: 10px 10px 15px 10px;
display: inline-block;
margin: 0 0 20px 0;
line-height: normal;
font-weight: 700;
position: relative;
background: rgba(35, 220, 116, 0.5);
transition: all 0.3s;
font-style: italic;
}
.blog-column .blog-item h2.highlight:before {
display: block;
position: absolute;
top: 45%;
width: 100%;
height: 40%;
margin-left: -3px;
content: "";
}
.blog-column .blog-item h2.highlight:after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 10%;
background: rgba(35, 220, 116, 0.3);
content: "";
transition: all 0.3s;
}
.blog-column .blog-item h2.highlight a {
height: 100%;
color: #141516;
}
.blog-row > .blog-column {
width: 100% !important;
}
.blog-row {
border-top: 1px solid #ddd;
}
.gutters {
padding: 0.1rem;
}
.gutters > .blog-column,
.gutters > .blog-row {
width: 100% !important;
min-width: 0;
}
.space-around {
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
}
.center {
-webkit-align-items: start;
-ms-flex-align: start;
-ms-grid-row-align: start;
align-items: start;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.panel {
text-align: center;
}
.panel.secondary {
background-color: #fff;
}
#media only screen and (min-width: 768px) {
.blog-item:hover h2.highlight {
background: rgba(35, 220, 116, 0.7);
}
.blog-item:hover h2.highlight:after {
height: 10%;
background: rgba(35, 220, 116, 0.8);
width: 100% !important;
}
.blog-item span.read-more {
font-size: 2rem;
}
.blog-item span.read-more:before {
content: "";
display: block;
height: 2px;
width: 0;
background-color: transparent;
}
.blog-item h2.highlight {
padding: 10px;
display: inline-block;
margin: 0 0 25px 0;
line-height: normal;
font-weight: 700;
position: relative;
background: rgba(35, 220, 116, 0.5);
transition: all 0.3s;
font-style: italic;
}
.blog-item h2.highlight:before {
display: block;
position: absolute;
top: 45%;
width: 100%;
height: 40%;
margin-left: -3px;
content: "";
}
.blog-item h2.highlight:after {
position: absolute;
left: 0;
bottom: 0;
width: 0 !important;
height: 10%;
background: rgba(35, 220, 116, 0.3);
content: "";
transition: all 0.3s;
}
.blog-column {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
height: auto;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
}
.blog-column .blog-item span.read-more {
padding-bottom: 5px;
text-align: center;
}
.blog-column .blog-item .right-arrow {
transition: all 0.3s;
position: relative;
}
.blog-column .blog-item:hover .right-arrow {
left: 5px;
}
.blog-column .blog-item h2 {
padding: 0;
font-size: 2.5rem;
text-align: center;
}
.gutters {
padding: 2rem;
}
.gutters > .blog-column,
.gutters > .blog-row {
margin: 1rem;
border-bottom: 5px solid red;
}
}
<div class='panel white'>
<div class='blog-row space-around'>
<div class='blog-column w50'>
<div class='blog-item center'>
<h2 class='highlight'><a
href='#'
class='w50'>Article Title</a></h2>
<span class='read-more'>Latest from the blog <span class='right-arrow'>→</span></span>
</div>
</div>
<div class='blog-column w50 desktop'>
<div class='blog-item center'>
<h2 class='highlight'><a
href='#'>Article Title</a></h2>
<span class='read-more'>Latest from the blog <span class='right-arrow'>→</span></span>
</div>
</div>
</div>
</div>
You need to make the div with class space-around a flex container.
Instead of this:
.space-around {
justify-content: space-around;
}
Try this:
.space-around {
display: flex;
justify-content: space-around;
}
This will apply default flex settings, including horizontal alignment, to both children (w50).
Revised Fiddle
If you want both items to not overflow the screen, remove this rule:
.blog-column { min-width: 100%; }