I'm making a navbar for my site following a tutorial. While working on my mobile menu responsiveness I made a ".burger" class with three "bars" to represent the menu. For some reason the menu icon doesn't show at all.
Code: https://gist.github.com/VlatkoStojkoski/290234f49a6f4e51019ca4b014c03f37
You have wrong css selector in media query.
add this to #media screen and (max-width: 775px).
nav .burger {
display: block;
}
It's because you set display: none to the menu. Even though you added a media query with display: block on the bottom, the first one will always rule.
You should add a media query to the first rule and you can remove the display: block on the bottom.
.burger {
#media screen and (min-width: 775px) {
display: none;
}
}
So this is your complete code:
#import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap");
$text-color: whitesmoke;
$font-stack: "Source Sans Pro", sans-serif;
$nav-color: rgba(79, 91, 102, 0.8);
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 12vh;
font-family: $font-stack;
background-color: $nav-color;
h1 {
letter-spacing: 5px;
font-size: 30px;
color: $text-color;
}
img {
width: 64px;
}
ul {
display: flex;
width: 35%;
justify-content: space-around;
a {
font-size: 21px;
color: $text-color;
text-decoration: none;
}
li {
list-style: none;
}
}
.burger {
#media screen and (min-width: 775px) {
display: none;
}
div {
width: 30px;
height: 4px;
background-color: $text-color;
margin: 5px;
}
}
}
#media screen and (max-width: 1024px) {
nav ul {
width: 50%;
}
}
#media screen and (max-width: 775px) {
body {
overflow-x: hidden;
}
nav ul {
position: absolute;
right: 0px;
height: 88vh;
top: 12vh;
background-color: $nav-color;
display: flex;
flex-direction: column;
align-items: center;
width: 50%;
transform: translateX(100%);
li {
opacity: 0;
}
}
}
Related
I have a flex layout, and its code like following
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item ">
Home
</li>
<li class="nav-item ">
Profile
</li>
<li class="nav-item">
Logout
</li>
</ul>
</div>
And its css like this
.navbar-collapse {
display: flex !important;
-ms-flex-preferred-size: auto;
flex-basis: auto;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-align: center;
align-items: center;
}
.navbar-nav {
margin-left: auto !important;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: row;
padding-left: 0;
list-style: none;
}
.navbar-nav .nav-item {
display: inline-flex;
text-align: -webkit-match-parent;
position: relative;
flex-shrink: 0;
padding-bottom: 0;
height: 100%;
}
.navbar-nav .nav-item a {
color: #fff;
font-weight: 400;
text-transform: capitalize;
cursor: pointer;
display: inline-flex;
align-items: center;
padding: 0 0.1rem;
white-space: nowrap;
position: relative;
}
It looks like this
The a element currently appears to have no height, and I want it to be as heigh as the parent element, how? Thank you.
Append:
The image shows what it looks like when I'm in chrome developer mode. Above is all my code.
The issue is with the default style of ul element.
ul has a default margin value of 1em as below.
ul {
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-inline-start: 40px;
}
You have to override this and bring this to you anchor tag as padding, because you are handling the hover effect of anchor tag. So this value should be set as the padding so that this will not break the layout while hovering.
I have fixed that in the below snippet.
Working Fiddle
.navbar-collapse {
display: flex !important;
-ms-flex-preferred-size: auto;
flex-basis: auto;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-align: center;
align-items: center;
}
.navbar-nav {
margin-left: auto !important;
margin: 0; /* Added */
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: row;
padding-left: 0;
list-style: none;
}
.navbar-nav .nav-item {
display: inline-flex;
text-align: -webkit-match-parent;
position: relative;
flex-shrink: 0;
padding-bottom: 0;
height: 100%;
}
.navbar-nav .nav-item a {
color: black;
font-weight: 400;
text-transform: capitalize;
cursor: pointer;
display: inline-flex;
align-items: center;
padding: 0 0.1rem;
white-space: nowrap;
position: relative;
}
/* New styles added */
.navbar-nav .nav-item a {
padding: 1em 0;
}
.navbar-nav .nav-item a:hover {
color: #fff;
background-color: #6c757d;
}
.navbar-collapse {
background-color: #00a82d;
}
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item ">
Home
</li>
<li class="nav-item ">
Profile
</li>
<li class="nav-item">
Logout
</li>
</ul>
</div>
I implemented now the rest of your code from the fiddle within the comments. You need to give the ul a height of 100% of the parent: .navbar-nav { height: 100%; }. In my snippet you have in CSS-line 301 declared: a { display: block; } -> swap the value to flex to keep the text from the anchor centered.
.navbar-nav {
height: 100%;
}
.navbar-nav a {
display: flex; /* swap this with line 301 */
}
/* original css */
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%
}
body {
margin: 0
}
main {
display: block
}
h1 {
font-size: 2em;
margin: .67em 0
}
hr {
box-sizing: content-box;
height: 0;
overflow: visible
}
pre {
font-family: monospace, monospace;
font-size: 1em
}
a {
background-color: transparent
}
abbr[title] {
border-bottom: 0;
text-decoration: underline;
text-decoration: underline dotted
}
b,
strong {
font-weight: bolder
}
code,
kbd,
samp {
font-family: monospace, monospace;
font-size: 1em
}
small {
font-size: 80%
}
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline
}
sub {
bottom: -0.25em
}
sup {
top: -0.5em
}
img {
border-style: none;
vertical-align: middle;
}
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
font-size: 100%;
line-height: 1.15;
margin: 0
}
button,
input {
overflow: visible
}
button,
select {
text-transform: none
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button
}
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0
}
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText
}
fieldset {
padding: .35em .75em .625em
}
legend {
box-sizing: border-box;
color: inherit;
display: table;
max-width: 100%;
padding: 0;
white-space: normal
}
progress {
vertical-align: baseline
}
textarea {
overflow: auto
}
[type="checkbox"],
[type="radio"] {
box-sizing: border-box;
padding: 0
}
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto
}
[type="search"] {
-webkit-appearance: textfield;
outline-offset: -2px
}
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none
}
::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit
}
details {
display: block
}
summary {
display: list-item
}
template {
display: none
}
[hidden] {
display: none
}
html {
font-size: 625%;
font-family: "Roboto", Arial, Helvetica, sans-serif;
height: 100%;
width: 100%;
}
body {
font-size: 0.16rem;
height: 100%;
width: 100%;
color: #6c757d;
line-height: 1.75;
}
a {
text-decoration: none;
}
.wrapper {
width: 100%;
height: 100%;
display: -webkit-flex;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
}
.container {
width: 100%;
flex-shrink: 0;
}
.row {
padding: 0 .12rem;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
flex: 1;
}
.navbar-brand {
font-size: 0.32rem;
color: #00a82d;
font-weight: 700;
text-transform: uppercase;
display: inline-block;
padding-top: 0.125rem;
padding-bottom: 0.125rem;
line-height: inherit;
white-space: nowrap;
}
.navbar-collapse {
display: flex!important;
-ms-flex-preferred-size: auto;
flex-basis: auto;
-ms-flex-positive: 1;
flex-grow: 1;
-ms-flex-align: center;
align-items: center;
}
.navbar-nav {
margin-left: auto!important;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: row;
padding-left: 0;
list-style: none;
}
.navbar-nav .nav-item {
display: inline-flex;
text-align: -webkit-match-parent;
position: relative;
flex-shrink: 0;
padding-bottom: 0;
height: 100%;
}
.device-width {
width: 9.6rem;
margin: 0 auto;
}
.usercenter-navbar {
background-color: #00a82d;
line-height: 1;
}
.usercenter .device-width {
width: 98%;
}
.usercenter-navbar .navbar-brand {
color: #fff;
font-size: .28rem;
font-weight: 700;
}
.usercenter-navbar .navbar-nav .nav-item a {
color: #fff;
font-weight: 400;
text-transform: capitalize;
cursor: pointer;
/* display: block; */
align-items: center;
padding: 0 0.1rem;
white-space: nowrap;
position: relative;
}
.usercenter-navbar .navbar-nav .nav-item a:hover {
color: #fff;
background-color: #6c757d;
}
#media screen and (max-width: 768px) {
body {
font-size: 0.13rem;
}
.auth-form {
width: 80%;
}
}
#media (min-width: 1200px) {
.device-width {
width: 11.4rem;
}
.auth-form {
width: 22%;
}
}
#media (min-width: 1920px) {
.device-width {
width: 11.4rem;
}
.auth-form {
width: 20%;
}
}
#media (min-width: 1200px) and (max-width: 1919px) {
.device-width {
width: 11.4rem;
}
.auth-form {
width: 26%;
}
}
#media (min-width: 992px) and (max-width: 1199px) {
.device-width {
width: 10.8rem;
}
.auth-form {
width: 30%;
}
}
#media (min-width: 768px) and (max-width: 991px) {
.device-width {
width: 9.6rem;
}
.auth-form {
width: 30%;
}
}
<div class="wrapper usercenter">
<div class="container usercenter-navbar">
<div class="device-width">
<div class="row">
<a class="navbar-brand" href="/">Workspace</a>
<div class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item current">
Home
</li>
<li class="nav-item ">
Profile
</li>
<li class="nav-item">
Logout
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
First, I want to state that I am not a web designer, but I am trying to search for solutions.
At the moment I am at loss, as I cannot figure out why a logo I am trying to add on a footer does not scale with resolution.
In fact, it is displaying it in full resulation only.
There is another logo in the footer that is scaling when resolution changes.
When I paste the code in TryIt, it is working, but once I put it on server, the image is in full resolution always.
Here is the TryIt link - https://www.w3schools.com/code/tryit.asp?filename=GRDOYEDNJX5K
As tyou can see, here the code would work.
What I have done is defined the image in footer.php
<div class="logo5">
<img src='https://i.ibb.co/42Lgdw7/8a2403c4b0d344d5ae7c3762c74fddb4-0001.jpg' class="logo5">
</div>
And added to CSS these lines
.logo5 {
width: 100%;
height: auto;
}
This is the rest of _footer.scss file
.footer-wrapp {
background-image: url("../../images/footer_back.jpg");
background-position: top;
background-size: cover;
background-repeat: no-repeat;
.container {
width: 100% !important;
max-width: unset !important;
}
.additional-info {
padding: 30px 0;
#media screen and (max-width: 992px) {
padding: 30px 0 15px;
}
h4 {
color: #fff;
}
p {
color: #7d7d7d;
}
}
#myFootNavWrapp {
margin: 60px 15% 0;
#media screen and (max-width: 1600px){
margin: 60px 5% 0;
}
#media screen and (max-width: 992px) {
margin: 0;
padding-left: 0;
padding-right: 0;
justify-content: space-between;
}
#media screen and (max-width: 520px) {
align-items: flex-start;
padding-top: 25px;
}
a {
color: #6377a4;
margin-right: 20px;
&:hover {
text-decoration: none;
border-bottom: 2px solid $main__red;
}
}
.mobile-logo-wrapp {
display: none;
margin-left: 20px;
#media screen and (max-width: 992px) {
display: inline-block;
}
a {
display: inline-block;
width: 45px;
height: 45px;
background-image: url("../../images/logo.jpg");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
}
#navFoot {
border-radius: 10px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
#media screen and (max-width: 992px) {
display: flex;
justify-content: center;
align-items: center;
}
.customFootNav {
flex-grow: 1;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
list-style-type: none;
flex-wrap: wrap;
width: 100%;
#media screen and (max-width: 520px) {
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
li {
flex-grow: 1;
min-width: 5%;
a {
color: $main__dark_blue;
border-bottom: 2px solid transparent;
transition: all 0.2s linear;
font-weight: 600;
}
&:hover {
a {
text-decoration: none;
border-bottom: 2px solid $main__red;
}
}
}
}
.privacyFootNav {
flex-grow: 1;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
list-style-type: none;
flex-wrap: wrap;
width: 100%;
#media screen and (max-width: 520px) {
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
}
#media screen and (min-width: 520px) and (max-width: 788px) {
margin-left: 92px;
}
li {
flex-grow: 1;
min-width: 5%;
a {
color: #6377a4;
border-bottom: 2px solid transparent;
transition: all 0.2s linear;
font-weight: 400;
}
&:hover {
a {
text-decoration: none;
border-bottom: 2px solid $main__red;
}
}
&.current-menu-item {
a {
text-decoration: none;
border-bottom: 2px solid $main__red;
}
}
}
}
.additional-wrapp {
flex-grow: 1;
}
.custom-menu-logo {
position: relative;
height: 95px;
min-width: 200px;
#media screen and (max-width: 1500px) {
min-width: 175px;
}
#media screen and (max-width: 1200px) {
min-width: 150px;
}
#media screen and (max-width: 992px) {
min-width: unset;
width:90px;
margin-right: 20px;
}
#media screen and (max-width: 520px){
display: none;
}
&:before {
content: '';
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
margin: 0 auto;
background-image: url("../../images/Logo_Red.jpeg");
background-position: center;
background-size: contain;
background-repeat: no-repeat;
transition: all 0.2s linear;
}
a{
outline: none;
display: block;
z-index: 9999;
position: absolute;
width: 100%;
height: 100%;
}
&:hover {
border: none;
a {
border: none;
}
}
}
}
}
}
Is there anything that would interfere with the logo I am trying to add to not scale?
Thank you.
I noticed that you're using wordpress, I already had problems while customizing themes and files this way, because wordpress theme sometimes overwrite your style and that's is bad.
To avoid it, I needed to put the css !important property, this way you force your style over any other that not have this property.
Maybe it's not the best appraoch, but worked for me, you should give a try.
.logo5 {
width: 100% !important;
height: auto !important;
}
I created a _mobile.scss to add responsive design to my website but some of my media queries are not overriding the default styles. I checked other posts on this topic which talked about 'specificity' but I made sure that the _mobile.scss is imported in the style.scss after the _home.scss (where I'm currently styling)
this is the content of styles.scss:
#import 'utilities/config';
#import 'layout/sidebar';
#import 'pages/home';
#import 'layout/mobile';
this is the _mobile.scss :
/
* Large screens */
#media screen and (min-width: 600px) {
.navbar {
top: 0;
left:0;
width: 8rem;
height: 100vh;
}
.navbar:hover {
width: 20rem;
}
.navbar:hover .link-text {
display: inline;
}
}
/* Small screens */
#media screen and (max-width: 800px) {
.banner-wrapper{
img{
width:50%;
}
}
.intro-text{
h1{
font-size: 2rem;
}
.typing::after{
height:50%;
}
}
.about-content{
flex-direction: column;
img{
width:100%;
}
p{
font-size: 1.5rem;
}
}
}
#media screen and (max-width: 600px) {
.navbar {
bottom: 0;
left:0;
width: 100%;
height: 5rem;
z-index:1;
}
.logo {
display: none;
}
.navbar-nav {
flex-direction: row;
width: 100%;
}
.nav-link {
justify-content: center;
height: 5rem;
i{
font-size: 2rem;
}
}
main {
margin: 0;
}
}
And this is a portion of the _home.scss(the part that isn't working):
#banner{
position: relative;
top: -5rem;
width: 100%;
height: 100vh;
}
.banner-wrapper{
display:flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 1rem;
img{
margin-left: auto;
margin-right: auto;
display: block;
width: 30%;
margin-bottom: 3rem;
}
.intro-text{
text-align: center;
h1{
font-size: 5rem;
text-transform: uppercase;
margin-bottom: 0;
margin-top: 0;
}
.typing{
position: relative;
margin-left:10px;
}
.typing::after{
content: "";
position: absolute;
right: -2px;
width:1px;
height: 100%;
border-right: 2px solid black;
animation: blink 0.5s infinite ease;
}
}
}
Where I'm confused is that I am able to change the img width of the .banner-wrapper on small screens (less than 800px) but changing the font-size of the h1 and height of .typing::after in .intro-text has no effect. So how can I fix this? Thank you in advance
After checking your code i found that in your _home.scss the .intro-text is wrapped inside .banner-wrapper whereas in your media query you're defining the .intro-text outside the .banner-wrapper double check it by defining the .intro-text inside the brackets of .banner-wrapper in the _mobile.scss and it might be the problem.
I was attempting to build a responsive nav using flexbox. When the screen is smaller than 744px, I wanted a toggle button to appear, the main nav to have a max-height of 0, and then on click, have the nav display in block. Fairly typical stuff.
However, I'm used to doing this just with floats and I'm running into several problems:
I don't understand how to drop the UL below the nav without pushing the nav logo and toggle up;
The UL with the LI doesn't seem to be responding to the max-height trick.
If anyone can provide some assistance or point me in the direction of tutorial that would be great.
* {
margin: 0;
padding: 0;
}
body {
font-family: 'open-sans', 'sans-serif';
font-size: 17px;
color: #444;
}
.navText {
font-size: 14px;
}
nav {
height: 100%;
width: 100%;
background-color: white;
}
.nav-fixedWidth {
//border: 1px solid;
min-height: 120px;
width: 960px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.mainNav {
list-style: none;
display: flex;
}
.mainNav li {
margin-right: 60px;
padding: 10px;
//border: 1px solid;
}
.mainNav li:nth-child(5){
margin-right: 10px;
}
.mainNav li a {
text-decoration: none;
color: #444;
display: block;
}
.mainNav li a:hover {
color: #9d9d9d;
}
.logo {
height: 60px;
width: 60px;
background-color: #ccc;
}
.toggle {
height: 60px;
width: 60px;
background-color: #ccc;
display: none;
}
#media screen and (max-width: 960px) {
.nav-fixedWidth
{
width: 95vw;
}
}
#media screen and (max-width: 744px) {
.nav-fixedWidth
{
flex-wrap:wrap;
}
.toggle
{
display: block;
}
}
<nav>
<div class="nav-fixedWidth">
<div class="logo"></div>
<div class="toggle"></div>
<ul class="mainNav">
<li class="navText">Webinars</li>
<li class="navText">e-Books</li>
<li class="navText">Blog</li>
<li class="navText">e-Course</li>
<li class="navText">Search</li>
</ul>
</div>
</nav>
I know this might be a bit late for your particular need, but you might want to take a look at this solution by Chris Coiyer
https://codepen.io/chriscoyier/pen/GJRXYE
html {
background: #666;
}
body {
width: 60%;
margin: 0 auto;
background: white;
}
.nav {
position: relative;
ul {
display: flex;
height: 3rem;
overflow: hidden;
flex-wrap: wrap;
list-style: none;
padding: 0;
width: 80%;
}
li {
a {
display: block;
padding: 1rem 0.5rem;
text-decoration: none;
white-space: nowrap;
}
}
&.open {
ul {
height: auto;
display: block;
}
}
}
.x {
position: absolute;
top: 0.75rem;
right: 0.75rem;
cursor: pointer;
}
This solution does require a small amount of JavaScript to toggle the menu.
Hope it helps :-)
I want my .logo to be in the middle for the small screens, and on the left for all of the other screens. The .logo stays on the left until the screen gets big and then moves a little to the right, but I would like it to stay into the middle until the screen gets to the breakpoint for bigger screens. I don't know a whole lot about flexbox, but I was hoping that y'all would be able to tell me how to do this!
Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Mad Men Software | Sometimes Crazy is Just What We Need</title>
<link rel="stylesheet" href="/main.css">
<link rel="stylesheet" href="css/normalize.min.css">
</head>
<body>
<header class="header">
<h1 class="logo">Logo</h1>
<ul class="nav">
<li>Projects</li>
<li>About</li>
<li>Contact</li>
</ul>
</header>
</body>
</html>
and here is my css:
/******************************
Flexbox Layout
*******************************/
.header, .nav {
display: flex;
flex-direction: column;
}
.header {
justify-content: space-between;
}
.nav {
flex: 1;
justify-content: space-around;
}
#media all and (min-width: 670px) {
.header, .nav {
flex-direction: row;
}
}
#media all and (min-width: 1030px) {
.nav {
flex: none;
}
}
/******************************
Additional Styling
*******************************/
body {
margin: 0;
font-family: Helvetica;
background: #5fcf80;
}
.header {
padding: 10px 0;
margin: 0 auto;
}
.logo {
background: url('/HTML/MadMenTransparent/MadMenOfficialLogo.png') center center no-repeat;
width: 150px;
min-height: 70px;
background-size: contain;
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
.nav {
list-style: none;
}
.nav li {
margin: 12px 0 12px 28px;
}
.nav li a {
text-decoration: none;
color: #fff;
font-size: 12px;
text-transform: uppercase;
}
.nav li a:hover {
color: rgba(255,255,255,0.7);
}
.nav li:last-child a {
background: rgba(255,255,255,0.3);
border-radius: 2px;
transition: 200ms ease-in-out;
padding: 8px 16px 7px;
}
.nav li:last-child a:hover {
background: rgba(255,255,255,0.5);
color: #fff;
}
#media all and (min-width: 1030px) {
.header {
width: 1030px;
min-width: 768px;
}
}
/*************************
Clearfix
*************************/
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
You can add a breakpoint at ur css like this:
#media only screen and (min-device-width: 700px) and (max-device-width: 1024px) {
header {
position: relative;
}
header ul.nav {
margin-top: 150px;
}
.logo {
position: absolute;
left: 50%;
margin-left: -75px;
}
}