So I am still learning about css / html for Mobile devices. I have a site that when on desktop looks good. When you pull it up on mobile device the menu is gone. If you go into landscaping mode the menu will appear. Any help on why?
menu code.
<div class="menu_block ">
<div class="container_12">
<div class="grid_12">
<nav class="horizontal-nav full-width horizontalNav-notprocessed">
<ul class="sf-menu">
<li <img src="images/logo.png" alt="wake up rentals"></li>
<li class="current">Home</li>
<li>Rentals</li>
<li>Lakes</li>
<li>Rent Now</li>
<li>FAQ's</li>
<li>Login</li>
<li>Contact Us</li>
</ul>
</nav>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
Menu Block CSS
.menu_block {
z-index: 999;
position: relative;
background: url(../images/menu_bg.png) 0 0 repeat-x #d8d8db;
padding: 12px 0 11px;
}
.menu_block nav {
position: relative;
font-family: 'Marvel', sans-serif;
}
nav>.sf-menu {
z-index: 990;
text-align: center;
position: relative;
}
nav{ position:relative;padding: 0px 0 0 0;}
.sf-menu ul {position:absolute;top:-999px; display:none;/* left offset of submenus need to match (see below) */}
.sf-menu>li {
display: block;
position: relative;
display: inline-block;
font-size: 24px;
line-height: 20px;
}
.sf-menu>li>ul>li {
float: none;
position: static;
}
.sf-menu>li+li {
margin-left: 27px;
}
.sf-menu>li>a{
font-weight: bold;
text-align: center;
color: #313030;
display: block;
padding: 9px 25px;
}
.sf-menu>li.sfHover>a, .sf-menu>li.current>a, .sf-menu>li>a:hover {
color: #000;
background-color: blue;}
.sf-menu>li>a.sf-with-ul:after {
position: absolute;
content: '';
left: 50%;
margin-left: -3px;
width: 5px;
background: url(../images/arrows.png) 0 0 no-repeat;
height: 4px;
bottom: 10px;
pointer-events: none;
z-index: 999;
display: block;
}
.sf-menu>li>ul>li>a.sf-with-ul:after {
content: '';
font-family: 'FontAwesome';
position: absolute;
width: 5px;
font-size: 15px;
line-height: 13px;
font-weight: normal;
right: -15px;
color: #fff;
bottom: 3px;
pointer-events: none;
z-index: 999;
}
Mobile Menu Block
#media only screen and (max-width: 767px) {
.menu_block {
float: none !important;
padding: 20px 10px 25px !important;
clear: both;
min-height: 0px;
border: none;
}
.menu_block nav {
border: none !important;
float:none !important;
font:12px/15px Arial, Helvetica, sans-serif;
text-transform:uppercase;
color:#927c67;
margin: 0 auto;
padding-left: 0 !important;
}
header nav ul {
border: none;
}
.sf-menu {
display:none !important;
float: none;
}
#mm0 {
font:12px/15px Arial, Helvetica, sans-serif;
color:#202020;
width:100%;
margin: 0 auto;
float: none;
outline: none;
border:2px solid #fff;
}
}
I am not sure if you need more like the container_12 and grid_12 code. There was a lot of lines of code in them. And did not want to add a lot of not needed info . If you think they are needed I can post them.
Container_12 / some grid_12 CSS
https://pastebin.com/tup8Psis
Grid_12 CSS
https://pastebin.com/qxAswhVc
posted links to the css figured it was easier to read there...
You have your UL set to "Display None" at max-width 767px.
#media only screen and (max-width: 767px)
.sf-menu {
display: none !important;
/* float: none; */
That is why you do not have a menu, remove the "Display None" from your UL.
Related
I am trying to create a navbar in pure html/css that at less than 600px width is horizontal with a horizontal set of links inline (no bullet points). At more than 600px width, I want a vertical navbar with a vertical list.
However, my horizontal version keeps giving me a vertically stacked set with bullet points and my vertical version has the word 'links' inline with 'paragraph' when I want it underneath.
I'm at a fault to see what I'm doing wrong. I tried scrubbing it out and starting again which worked until I put in my media query and it all went wrong again. Any help appreciated.
<header>
<nav id="navbar">
<h1>HTML Basics</h1>
<ul>
<li>Documents</li>
<li>Headings</li>
<li>Paragraph</li>
<li>Links</li>
<li>Images</li>
</ul>
</nav>
</header>
#navbar{
background: red;
width: 100%;
height: 20%;
margin: auto;
position: fixed;
display: inline;
float: top;
top: 0;
left: 0;
}
#media screen and (min-width:600px){
#navbar{
background: red;
width: 22%;
height: 100%;
margin: auto;
position: fixed;
display: block;
top: 0;
left: 0;
}
li{
list-style: none;
padding-right: 20px;
padding-bottom: 20px;
display: inline-block;
margin-left: 10%;
float: left;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 12px;
}
#media only screen and (min-width:600px){
li{
list-style-type: none;
display: block;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 20px;
}
}
li:hover{
color:#911f32;
font-size: 18px;
}
You're missing a closing curly brace in your first Media Query. Try this:
#navbar {
background: red;
width: 100%;
height: 20%;
margin: auto;
position: fixed;
display: inline;
float: top;
top: 0;
left: 0;
}
#media screen and (min-width:600px) {
#navbar {
background: red;
width: 22%;
height: 100%;
margin: auto;
position: fixed;
display: block;
top: 0;
left: 0;
} // <-- NOTE! This curly brace was missing...
}
li {
list-style: none;
padding-right: 20px;
padding-bottom: 20px;
display: inline-block;
margin-left: 10%;
float: left;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 12px;
}
#media only screen and (min-width:600px){
li {
list-style-type: none;
display: block;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 20px;
}
}
li:hover{
color: #911f32;
font-size: 18px;
}
You had some errors in there:
You used min-width both times instead of min/max
For the horizontal version you need to allow full width (100%)
You forgot a closing curly brace
There is no float: top; (but that has no effect anyway)
#navbar {
background: red;
width: 100%;
height: 20%;
margin: auto;
position: fixed;
display: inline;
top: 0;
left: 0;
}
#media screen and (max-width:600px) {
#navbar {
background: red;
margin: auto;
position: fixed;
display: block;
top: 0;
left: 0;
}
li {
list-style-type: none;
padding-right: 20px;
padding-bottom: 20px;
display: inline-block;
margin-left: 10%;
float: left;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 12px;
}
}
#media only screen and (min-width:600px) {
#navbar {
width: 20%;
height: 100%;
}
li {
list-style-type: none;
display: block;
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 20px;
}
}
li:hover {
color: #911f32;
font-size: 18px;
}
<header>
<nav id="navbar">
<h1>HTML Basics</h1>
<ul>
<li>Documents</li>
<li>Headings</li>
<li>Paragraph</li>
<li>Links</li>
<li>Images</li>
</ul>
</nav>
</header>
Add style for your list-item element (600px and down).
Comment unnecessary style (600px and up).
Look at CSS code below.
#navbar{
/* ... */
}
/* === Add this code */
li {
list-style-type: none;
display: inline-block;
}
#media screen and (min-width:600px){
#navbar {
/* ... */
}
/* ===
You don't need
"display: inline-block" and
"float: left"
*/
li {
list-style: none;
padding-right: 20px;
padding-bottom: 20px;
/* display: inline-block; */
margin-left: 10%;
/* float: left; */
font-family: 'Nunito Sans', sans-serif;
text-decoration: none;
font-size: 12px;
}
/*...*/
Basically, I want to position the button inside the image, and make it stay in its position when I switch to mobile mode or change the size of the window.
This is what I want it to look like:
https://prnt.sc/mij0s6
.img-wrapper {
position: relative;
}
.img-responsive {
max-width: 100%;
height: auto;
margin-top: 180px;
margin-left: 360px;
}
a.btn {
display: inline-block;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
position: relative;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
#media all and (max-width:30em) {
a.btn {
display: block;
margin: 0.2em auto;
}
}
<h1>De zakelijke VR/AR hardware leverancier van Benelux</h1>
<div class="img-wrapper">
<img class="img-responsive" src="vrgt.png">
</div>
Meer Info
(I posted prematurely.. pressed the post button by accident)... You had no css for img or H1.. I added some, I also added a max-width for image in both the main css and the reponsive (media) css.
The code could do with a bit of tweaking but I'd advise you have a look and adapt it to your needs. It's closer to what you want I think!
EDIT: I'd advise you add a few more media queries to accommodate different screen resolutions as absolute positioning can be a bit of a nightmare on differently-sized devices. Screenfly is a good tool for testing how your code looks on multiple sizes. Using large margin-bottoms measured in pixels (such as 360px) may result in your button not even displaying on a screen, so try to use vertical height (vh) or percentages when measuring height especially. The [calc function] is also very useful 2. Useful css for centering are margin : 0 auto or text-align:center;
Best of luck, and hope this helps
h1 {
text-align: center;
font-weight: bold;
font-size: 1.8em;
}
img {
max-width: 70%;
max-height: 80%;
margin: 10px 12%;
}
img-wrapper {
display: inline-block;
position: relative;
}
nav {
margin: 0 auto;
}
nav ul {
list-style-type: none;
background-color: lightgrey;
width:100%;
}
nav ul li {
min-width:18%;
display: inline-block;
text-align: center;
padding: 10px;
margin:0 auto;
}
ul li a {
padding: 10px 15px;
text-decoration: none;
}
/*.img-responsive {
/* margin-top: 100px;
margin-left: 360px;
}*/
a.btn {
display: inline-block;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
position: relative;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
#media all and (max-width:30em) {
img {
max-width: 400px;
}
a.btn {
display: block;
margin: 0.2em auto;
}
}
<h1>De zakelijke VR/AR hardware leverancier van Benelux</h1>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</nav>
<div class="img-wrapper">
<img class="img-responsive" src="https://gilsig.ca/wp-content/uploads/2015/10/12391435_192385974441516_971157875868647436_n.jpg-North-Shore-Mountains-Dec-2015.jpg">
</div>
Meer Info
Button's position should be absolute relative to it's first parent element.
a.btn
{
position: absolute;
top: 50%;
left: 50%;
}
.img-wrapper {
position: relative;
}
a.btn {
position: absolute;
top: 50%;
left: 50%;
padding: 0.2em 1.45em;
margin: 0.1em;
border: 0.15em solid #CCCCCC;
box-sizing: border-box;
text-decoration: none;
font-family: 'Segoe UI', 'Roboto', sans-serif;
font-weight: 400;
color: #000000;
background-color: #ffc966;
text-align: center;
}
a.btn:hover {
border-color: #7a7a7a;
}
a.btn:active {
background-color: #999999;
}
<div class="img-wrapper">
<img src="https://www.w3schools.com/css/img_5terre_wide.jpg" alt="Cinque Terre" width="1000" height="300">
</div>
Meer Info
I am trying to create a dynamic nav bar. By default, I want the nav bar to display vertically in a div which spans the entire height of the page, but when resized, I want the bar to become horizontal. Here's a picture of what I am trying to achieve:
I have tried to mould my approach based off W3Schools suggestions, by adding display:block; to my ul but it doesn't change anything. My understanding of media queries isn't the best, but I have also tried to alter the width and height of the left div (dark grey):
#media screen and (max-width: 200px) {
.nav-container{
width: 100%;
height: 200px;
background-color: #333;
border-bottom: 0.5px solid #333;
}
}
What is the best approach to achieve this?
Edit:
html,
body {
height: 100%;
background-color: #fff;
}
body {
background-color: #fff;
text-align: center;
margin: 0;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
display: block;
}
.site-wrapper {
display: table;
width: 100%;
height: 100%;
min-height: 100%;
-webkit-box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5);
box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5);
}
* {
margin: 0;
padding: 0;
}
.site-wrapper {
display: flex;
flex-wrap: wrap;
}
.nav-container {
height: 100%;
width: 200px;
background-color: #333;
display: flex;
justify-content: center;
align-items: center;
}
.logo-holder {
position: absolute;
top: 0;
text-align: center;
}
.logo-holder img {
height: auto;
}
#navigation-div {
margin-top: -300px;
width: 100%;
}
.nav-ul li a {
display: block;
}
.nav-link {
width: 100%;
display: block;
text-align: left;
color: #fff;
text-decoration: none;
margin-left: 0px;
padding-left: 15px;
}
.nav-link:hover {
background-color: #fff;
color: #333;
}
.nav ul {
width: 100%;
padding-left: 0px;
}
.nav ul li {
list-style-type: none;
width: 100%;
}
.nav ul li a {
text-align: left;
padding: 5px;
color: #fff;
text-decoration: none;
margin-left: 15px;
}
.nav li:hover {
background-color: #fff;
}
.nav li:hover a {
color: #333;
}
#media screen and (max-width: 540px) {
.nav-container {
width: 100%;
height: 160px;
background-color: #333;
border-bottom: 0.5px solid #333;
}
.nav-container nav,
.nav-container nav ul,
.nav-container nav ul li,
.logo-holder {
display: inline;
}
.logo-holder {
position: absolute;
left: 0;
}
#navigation-div {
float: left;
}
}
<div class="site-wrapper">
<div class="nav-container">
<div class="logo-holder">
<img src="#" alt="Logo" />
</div>
<div id="navigation-div">
<nav class="nav left-nav-bar">
<ul class="nav-ul">
<a class="nav-link active" href="">
<li>Home</li>
</a>
<a class="nav-link" href="">
<li>Blog</li>
</a>
<a class="nav-link" href="">
<li>Store</li>
</a>
<a class="nav-link" href="">
<li>Contact</li>
</a>
</ul>
</nav>
</div>
</div>
</div>
Firstly, your media query might not be called at all because the max width is pretty small at 200px.
Inside your media query you'll need to set the display property of the navigation elements and the logo to inline, so that they display side-by-side. (You could also consider using flexbox for this) You'll also need to reset some of the properties that are defined higher up, like the line-height of the h3 logo element.
#media screen and (max-width: 480px) {
.nav-container{
width: 100%;
height: auto;
background-color: #333;
border-bottom: 0.5px solid #333;
}
.nav-container nav,
.nav-container nav ul,
.nav-container nav ul li,
.logo-holder,
.logo-holder h3 {
display: inline;
}
.logo-holder h3 {
line-height: 1;
}
}
I'm trying to reduce the height of my navigation bar. when I use min-height property, it adds a scrollbar to the navigation bar which makes it not so appealing. I would like to align the logo to the extreme left and the rest of the contents to the extreme right.I have attached the code below. Please help me to fix it.
.navigation {
background-color: rgba(15,58,114,0.9);
overflow-y: auto;
position: fixed;
left: 0;
top: 0;
text-align: left;
width: 100%;
z-index: 10000;
box-sizing: border-box;
}
.log {
text-align: right;
top: 0;
margin: 0 auto;
right: 0;
}
ul {
padding: 0;
}
li {
color: White;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-weight: 300;
margin: 16px 20px;
text-transform: uppercase;
}
li a {
display: inline-block;
color: White;
text-align: Center;
padding: 14px 16px;
text-decoraton: none;
}
li a:hover {
background-color: rgba(0,0,0,0);
}
#logo {
color: #FFFFFF;
font-family: 'Vollkorn';
font-size: 34px;
padding: 0px 50px;
text-align: center;
}
<div class="navigation">
<ul>
<li id="logo">LOGO</li>
<div class="log">
<li>LOGIN</li>
<li>JOIN WITH US</li>
</div>
</ul>
</div>
your logo and below that your menu list - that's the problem
make its side by side
.navigation ul {
display: flex;
}
.navigation {
background-color: rgba(15,58,114,0.9);
overflow-y: auto;
position: fixed;
left: 0;
top: 0;
/*text-align: left;*/
width: 100%;
z-index: 10000;
box-sizing: border-box;
}
.navigation ul {
display: flex; /* new line added */
}
#logo {
flex: 2; /* new line added */
}
.log {
/*text-align: right;*/
top: 0;
margin: 0 auto;
right: 0;
display: flex; /* new line added */
flex: 8; /* new line added */
justify-content: flex-end; /* new line added */
}
ul {
padding: 0;
}
li {
color: White;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-weight: 300;
margin: 16px 20px;
text-transform: uppercase;
}
li a {
display: inline-block;
color: White;
text-align: Center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: rgba(0,0,0,0);
}
#logo {
color: #FFFFFF;
font-family: 'Vollkorn';
font-size: 34px;
padding: 0px 50px;
text-align: center;
}
<div class="navigation">
<ul>
<li id="logo">LOGO</li>
<div class="log">
<li>LOGIN</li>
<li>JOIN WITH US</li>
</div>
</ul>
</div>
You had the scroll bar because the contents were too big and you had overflow-y: auto; Overflow controls the behavior when the contents are too big for the parent div size.
The float property can be used to move elements to different sides of the viewer in a consistent manner.
Your code is still not responsive and will not display correctly on screens smaller that 365px wide. The support range will get smaller if you add more menu items.
There are a lot of resources you can check out for making a responsive menu
Is this what you wanted?
body {
margin: 0 auto;
padding: 0
}
.navigation {
background-color: rgba(15, 58, 114, 0.9);
position: fixed;
height: 60px;
line-height: 60px; /* needs to be the same height as your navigation div */
top: 0;
width: 100%;
z-index: 10000;
}
.log {
float: right; /* pulls the div to the right side */
}
ul {
padding: 0;
margin: 0 auto;
}
li {
color: White;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-weight: 300;
margin: 0 auto;
text-transform: uppercase;
}
li a {
color: White;
text-align: Center;
padding: 0 10px;
text-decoration: none;
}
li a:hover {
color:wheat;
}
#logo {
color: #FFFFFF;
font-family: 'Vollkorn';
font-size: 34px;
padding: 0px 10px;
float: left; /* pulls the div to the left side */
}
<div class="navigation">
<ul>
<li id="logo">LOGO</li>
<div class="log">
<li>LOGIN</li>
<li>JOIN WITH US</li>
</div>
</ul>
made Changes to your HTML and CSS
div with class log is a block level element, means it occupies 100% width of the page, make them display:inline-block and float it to right, make the logo wrap in a div and float it to left. since we are having two float elements navigation bar height gets collapsed to avoid it we need to add clearfix
HTML
<div class="navigation clearfix">
<div class="logo">LOGO</div>
<div class="menu">
<ul>
<li>LOGIN</li>
<li>JOIN WITH US</li>
</ul>
</div>
</div>
CSS
.navigation {
background-color: rgba(15,58,114,0.9);
overflow-y: auto;
position: fixed;
left: 0;
top: 0;
text-align: left;
width: 100%;
z-index: 10000;
box-sizing: border-box;
}
.logo{
float:left;
display:inline-block;
}
.logo a{
padding:8px 2px;
color:#fff;
display:block;
}
.menu{
float:right;
}
.clearfix::after{
content:"";
display:table;
width:100%;
}
.menu ul{
padding:0px;
list-style-type:none;
margin:0;
}
.menu ul li{
display:inline-block;
}
.menu ul li a{
color:#fff;
padding:8px 2px;
display:block;
}
Link For reference
style accordingly
hope this helps..
I've done a little change in the style:
.navigation {
background-color: rgba(15, 58, 114, 0.9);
overflow-y: auto;
position: fixed;
left: 0;
top: 0;
right: 0;
text-align: left;
width: 100%;
z-index: 10000;
box-sizing: border-box;
}
.log {
margin: 0 auto;
float: right;
}
ul {
padding: 0;
}
li {
color: White;
list-style: none;
font-family: 'Raleway', sans-serif;
font-size: 18px;
font-weight: 300;
text-transform: uppercase;
float: right;
}
li a {
display: inline-block;
color: White;
text-align: Center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: rgba(0, 0, 0, 0);
}
#logo {
color: #FFFFFF;
font-family: 'Vollkorn';
font-size: 34px;
padding: 0px 50px;
text-align: center;
float: left !important;
margin-top: -10px;
}
<div class="navigation">
<ul>
<li id="logo">LOGO</li>
<div class="log">
<li>LOGIN</li>
<li>JOIN WITH US</li>
</div>
</ul>
</div>
I am trying to display logo at top end in HTML and CSS.
However, the logo image size is not reduced to the specified width and height and I do not see it being overridden anywhere else.
Code is as follows:
/*********************************************************************************/
/* Banner */
/*********************************************************************************/
#banner
{
overflow: hidden;
height: 300px;
position: relative;
background: url(images/pic01.jpg) no-repeat center;
background-size: cover;
}
#banner .image
{
}
#banner p{
position: absolute;
top:30%;
left: 40%;
width: 100px;
padding: 5px;
margin: 5px;
font-family: 'Lobster', cursive;
font-weight: bold;
font-size: 55px;
color: #fff;
}
/** MENU */
#menu-wrapper
{
background: #16a085;
overflow:auto;
}
#menu {
overflow: hidden;
height: 100px;
float:left;
}
#menu ul {
margin: 0;
padding: 0px 0px 0px 0px;
list-style: none;
line-height: normal;
text-align: center;
}
#menu li {
display: inline-block;
}
#menu a {
display: block;
letter-spacing: 1px;
padding: 0px 40px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-size: 0.80em;
line-height: 100px;
border: none;
color: #FFF;
}
#menu a:hover, #menu .current_page_item a {
text-decoration: none;
}
#menu .current_page_item a {
background: #1abc9c;
}
#Logo{
width:10px;
height:30px;
float: left;
margin-top: 5px;
}
<div id="wrapper">
<div id="menu-wrapper">
<div id = "Logo" >
<img src="images/Logo.jpg" ></img>
</div>
<div id="menu" class="container">
<ul>
<li class="current_page_item">Homepage</li>
<li>About</li>
<li>Blog</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div>
/*and so on */
</div>
It looks like this:
White part in the banner is image that is taking up the width despite of having set width attribute to 10 px.
In your CSS. change the style for #Logo to #Logo img{}. you have to set the width to img tag. Not its parent container.
#Logo img{
width:100px;
height:30px;
float: left;
margin-top: 5px;
}
JS Fiddle