Hiding a responsive navigation with button to open - html

I am trying to hide my menu when a page gets too small and has a button to open it if required. I am struggling to make it happen. I can hide the navigation when the screen shrinks and display the div button to reopen it but cannot get the menu to reappear. I have tried to use focus to bring up the original side nav div with little success thinking that it is not overwriting the code to hide it on screen size. How do I get around this?
Any guidance greatly appreciated.
.sidenav {
height: 100%;
width: 220px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
-webkit-box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #00aad4;
display: block;
}
.sidenav a:hover {
color: #000;
}
/* Style page content */
.main {
margin-left: 220px; /* Same as the width of the sidebar */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
.HideMenu { display:none; }
.ShowMenu { display:block; }
/* Desktop*/
#media screen and (min-width: 768px) {
.HideMenu { display: block; }
}
/* Mobile*/
#media screen and (max-width: 768px) {
.ShowMenu:focus ~ .sidenav { display: block; }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="HideMenu">
<div class="sidenav">
<img src="images/logo.png">
Textures
HDRI's
</div>
</div>
<!-- Content
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="grid-container halves full" style="background-color: #000;">
<div>Centre whole</div>
</div>
<div class="ShowMenu" tabindex="0">Show Me</div>
<div class="grid-container halves">
<div>
50 L
</div>
<div>
50 R
</div>
</div>
<div class="grid-container thirds">
<div>Third L</div>
<div>Thirs M</div>
<div>Third R</div>
</div>

Here's the HTML code
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="HideMenu">
<div class="sidenav">
<img src="images/logo.png">
Textures
HDRI's
</div>
</div>
<!------------------------------- Content ------------------------------->
<div class="grid-container halves full" style="background-color: #000;">
<div>Centre whole</div>
</div>
<div class="ShowMenu" tabindex="0">Show Me</div>
<div class="grid-container halves">
<div>
50 L
</div>
<div>
50 R
</div>
</div>
<div class="grid-container thirds">
<div>Third L</div>
<div>Thirs M</div>
<div>Third R</div>
</div>
<!-- You'll need to import the javascript file with the <script> tag -->
<script type="text/javascript" src="/path/to/desktop-mobile-layout-handler.js"></script>
Here's the CSS code
.sidenav {
height: 100%;
width: 220px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
-webkit-box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
box-shadow: 2px 0px 5px 0px rgba(0,0,0,0.75);
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #00aad4;
display: block;
}
.sidenav a:hover {
color: #000;
}
/* Style page content */
.main {
margin-left: 220px; /* Same as the width of the sidebar */
padding: 0px 10px;
}
/*
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
*/
.HideMenu { display:none; }
.ShowMenu { display:block; }
/* Desktop*/
/*
#media screen and (min-width: 768px) {
.HideMenu { display: block; }
}
*/
/* Mobile*/
/*
#media screen and (max-width: 768px) {
.ShowMenu:focus ~ .sidenav { display: block; }
}
*/
And finally, the JavaScript code
// desktop-mobile-layout-handler.js
var screenHeight = window.screen.availHeight;
var screenWidth = window.screen.availWidth;
var hideMenuElement = document.querySelector(".HideMenu");
var sideNavElement = document.querySelector(".sidenav");
var sideNavLinks = document.querySelectorAll(".sidenav a");
function desktopLayout () {
hideMenuElement.style.display = "block"; // hide the .HideMenu element
}
function mobileLayout () {
sideNavElement.onfocus = function () { // when the .sidenav element is being focused
sideNavElement.style.display = "block"; // display the .sidenavelement
}
sideNavElement.onblur = function () { // when the .sidenav element is not being focus
sideNavElement.style.display = "none"; // hide the .sidenav element
}
}
if (screenHeight <= 450) {
sideNavElement.style.paddingTop = "15px";
sideNavLinks.forEach(function (elem) {
elem.style.fontSize = "18px";
});
}
if (screenWidth >= 768) { // use Desktop layout
desktopLayout();
}
else { // use Mobile Layout
mobileLayout();
}
The javascript code will help you fix the CSS error you had above.
I hope this helps

Related

How to show hamburger menu only on mobile?

I'm currently trying to create a responsive navigation which is only a hamburger menu when on a mobile/tablet but am unsure how to hide it and stop it from working when it's on desktop. This is my first time playing around with CSS so it's a bit messy. The * is where the #media was when I was trying to get it to work. As I didn't know what to do I messed around with display:none but unsurprisingly it hid the entire navigation. There is quite a bit more wrong with this but i'm fixing it a step at a time. Unfortunately, I did this before I found out that mobile-first would have been better.
.button{
background-color: inherit;
border:none;
color: #4054b4;
padding: 64px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
font-family: 'Lato' , sans-serif;
transition:0.3s;
}
.dropdown {
float:center;
overflow:hidden;
display:inline-block;
}
.button:hover, .button:hover {
background-color: #4054b4;
color: #ffffff;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #4054b4;
width:100%;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown:hover .dropdown-content {
display: block;
}
.colum {
float: left;
width:25%;
padding: 10px;
background-color: #4054b4;
height: 250px;
}
.colum a {
float: none;
color: white;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
font-family: 'Lato' , sans-serif;
}
.colum a:hover {
background-color: #4054b4;
}
.col {
float: right;
width:25%;
padding: 10px;
background-color: inherit;
height: 250px;
}
.col a {
float: none;
color: inherit;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
font-family: 'Lato' , sans-serif;
}
.row:after {
content: "";
display:table;
clear: both
}
****
.open {
float:right;
color:#4054b4;
margin:1em 0 0 1em;
cursor:pointer;
display:block !important;
}
.nav{
width: 0;
height: 100vh;
z-index: 3;
position: fixed;
overflow: hidden;
background-color: #4054b4;
transition: 0.3s;
}
.nav a {
display: block;
color: #ffffff;
padding: 1em 0;
transition: 0.4s;
}
.close {
float: center;
margin: 1em 0 0 1em;
}
****
</style>
<body>
<div class="w3-container" style="box-shadow:0 0.4% 0.8% rgba(0,0,0,0.2)">
<div class="w3-bar w3-white ">
<div class="wrapper ">
<div class="nav " id="nav">
×
<div class="dropdown ">
<button class="button dropdown"> Button </button>
<div class="dropdown-content ">
<div class="header ">
<h2 style="color:white"> Header </h2>
<div class="row ">
<div class="colum ">
Page
</div>
</div>
</div>
</div>
</div>
<div class="dropdown ">
<button class="button dropdown "> Button</button>
<div class="dropdown-content ">
<div class="header ">
<h2 style="color:white"> Header </h2>
<div class="row ">
<div class="colum ">
PAge
</div>
</div>
</div>
</div>
</div><span id="open" class="open " onclick="openNav()">&#9776</span>
</div>
</div>
<script>
function openNav() {
document.getElementById("open").style.display = "none";
document.getElementById("nav").style.width = "100%";
}
function closeNav(){
document.getElementById("open").style.display = "block";
document.getElementById("nav").style.width = "0";
}
</script>
That would be better if you could dynamically add the hamburger menu by checking if device type is mobile or tablet, not just hide and show with css, so i found something you might be interested if you not yet know. Look at this
Thank you, this is my first action in stackoverflow
Start with Bootstrap
and here: https://getbootstrap.com/components/#navbar). It makes this kind of thing really simple and stops you from reinventing the wheel.
To do what you are wanting you will need to set CSS media queries for the correct display. This is exactly what bootstrap does.
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
}
If you want to do it yourself I would start with learning about media breakpoints and look at
Bootstrap hamburger menus:
Bootstrap 5
Bootstrap 4

Gap between content wrapper div and screen bottom - but only under certain conditions

First, here's my live testing page.
The issue is that the wrapper div doesn't extend all the way to the bottom of the screen; a small gap occurs between the wrapper div and the actual bottom of the screen. But the gap only occurs with certain conditions:
the gap only occurs on screens/windows vertically sized down below a certain point and that point changes depending on whether there is one line of text or two or more.
With one line of text, the gap occurs at 614 or shorter. With two or more lines of text it occurs at 633 or shorter.
the menu buttons are an SSI include. Viewed locally where the menu doesn't show, there is no gap regardless of how many lines of text are there. The gap only occurs on the uploaded version where the menu shows.
I used media queries so that the wrapper div is only obvious (black border, gradient page background color instead of white like the div) on screens larger than 1024. So the gap won't even be noticeable to anyone unless they are using a screen that is wider than 1024 AND shorter than 633. Given the common resolutions for phones, tablets, computers, TVs etc this is very unlikely (everything with a height less than 633 also has a width under 1024) unless they manually resize their window to be short while staying wide.
So this probably isn't an issue I even need to worry about but it is really bugging me that there is some "glitch" in my code causing this.
Here's the relevant code:
body {
background-color: #ffffff; /* WHITE */
font-size: 100%;
height: 100%;
margin: 0px 0px 0px 0px;
}
/* for screens 1026px and greater */
#media screen and (min-width: 1025px) {
body { background-color: #000000; /* BLACK */
background-image: linear-gradient(#ffff00, #00b300, #ffff00);} /* YELLOW GREEN YELLOW */
}
#WRAPPER {
display: block;
position: relative;
width: 1024px;
max-width: 100%;
min-height: 100%;
margin: 0 auto;
margin-top: 0px;
margin-bottom: 0px;
justify-content: center;
background-color: #ffffff; /* WHITE */
padding: 0px 10px 0px 10px;
box-sizing: border-box;
}
/* for screens 1026px and greater */
#media screen and (min-width: 1025px) {
#WRAPPER { box-sizing: border-box;
border-left: 3px solid #000000; /* BLACK */
border-right: 3px solid #000000;
}
}
#mainBack {
max-width:99%;
margin: 0px 0px 0px 0px;
}
p {
color: #000000; /* BLACK */
text-align: center;
font-family: Arial, Verdana;
font-size: 1rem;
margin: 10px 0px 5px 0px;
}
.heading {
color: #0099ff; /* BLUE */
text-align: center;
font-family: Arial, Verdana;
font-size: 1.87rem;
margin: 0px 0px 0px 0px;
}
div.text {
max-width: 1000px;
}
#myBtn {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
border: 4px solid #0099ff; /* BLUE */
border-radius: 20px;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
outline: none;
background-color: #6b6b6b; /* GRAY */
color: #ffffff; /* WHITE TEXT */
font-size: 13px;
font-weight: bold;
cursor: pointer;
padding: 10px;
}
.dropdown {
position: relative;
display: inline-block;
margin-top: 5px;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropbtn {
background-color: #6b6b6b; /* GRAY */
color: #ffffff; /* WHITE TEXT */
min-width: 175px;
padding: 10px 10px;
font-size: 16px;
border: 4px solid #0099ff; /* BLUE */
border-radius: 20px;
cursor: pointer;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
box-sizing: border-box;
}
.dropdown:hover .dropbtn {
background-color: #6b6b6b; /* GRAY */
}
.dropdown-content {
display: none;
position: absolute;
background-color: #6b6b6b; /* GRAY */
width: 95%;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
border: 4px solid #0099ff; /* BLUE */
border-radius: 4px;
box-sizing: border-box;
z-index: 1;
}
.dropdown-content a:hover {background-color: #0099ff} /* BLUE */
.dropdown-content a {
color: #ffffff; /* WHITE */
padding: 5px;
text-decoration: none;
display: block;
}
<html>
<head>
<title>Home Page Testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type ="text/css" href="NEWhome.css" />
<style type="text/css">
</style>
</head>
<div ID="WRAPPER">
<center>
<span class="heading">Home Page Testing</span>
<div class="text"><p>Issue: If screen is 633 or shorter, the wrapper div doesn't extend all the way down, there is a gap of maybe 10 pixels where the background shows. The gap only occurs on the uploaded version; the local version that doesn't display the SSI menu has no gap.</p>
</div>
<!-- this menu is actually a SSI include -->
<center>
<div class="dropdown">
<button class="dropbtn">Button 1 Label</button>
<div class="dropdown-content">
Link
Link
</div></div>
<div class="dropdown">
<button class="dropbtn">Button 2 Label</button>
<div class="dropdown-content">
Link
Link
</div></div>
<div class="dropdown">
<button class="dropbtn">Button 3 Label</button>
<div class="dropdown-content">
Link
Link
</div></div>
</center><p>
<!-- end of include -->
<img id="mainBack" src="TempHome.png" alt="main logo">
</center>
</div> <!-- CLOSES MAIN WRAPPER DIV -->
<!-- Script for Back to Top Button -->
<script>
// When the user scrolls down 200px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
</script>
<!-- END Script for Back to Top Button -->
<button onclick="topFunction()" id="myBtn" title="Go to top of page">Top of Page</button>
</body>
</html>

Grid layout not showing

I've been following a responsive web design tutorial and I just cant get my head round this problem. I've included the grid.css file in my html but some how chrome doesnt display it correctly. Instead of grid I get rows like in the attached image. Can someone please help me out with this?
Thank you
No grid
/* --------------------------- */
/* BASIC SETUP */
/* --------------------------- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
background-color: #fff;
color: #555;
font-family: 'Lato', 'Arial', sans-serif;
font-weight: 300;
font-size: 20px;
text-rendering: optimizeLegibility;
}
/* --------------------------- */
/* REUSABLE COMPONENTS */
/* --------------------------- */
.row {
max-width: 1140px;
margin: 0 auto;
}
section {
padding: 80px 0;
}
/*----- HEADINGS ----- */
h1 {
margin-top: 0;
margin-bottom: 20px;
color: #fff;
font-size: 240%;
font-weight: 300;
text-transform: uppercase;
letter-spacing: : 1px;
word-spacing: 4px;
}
/*----- BUTTONS ----- */
.btn:link,
.btn:visited {
display: inline-block;
padding: 10px 30px;
font-weight: 300;
text-decoration: none;
border-radius: 200px;
color: #fff;
transition: background-color 0.2s, border 0.2s, color 0.2s;
}
.btn-full:link,
.btn-full:visited {
background-color: #e67e22;
border: 1px solid #e67e22;
color: #fff;
margin-right: 15px;
}
.btn-ghost:link,
.btn-ghost:visited{
border: 1px solid #e67e22;
color: #e67e22;
}
.btn:hover,
.btn:active {
background-color: #cf6d17;
}
.btn-full:hover,
.btn-full:active {
border: 1px solid #cf6d17;
}
.btn-ghost:hover,
.btn-ghost:active {
border: 1px solid #cf6d17;
color: #fff;
}
/* --------------------------- */
/* HEADER */
/* --------------------------- */
header {
background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(img/hero.jpg);
background-size: cover;
background-position: center;
height: 100vh;
}
.hero-text-box {
position: absolute;
width: 1140px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.logo {
height: 100px;
width: auto;
float:left;
margin-top: 20px;
}
.main-nav {
float:right;
list-style: none;
margin-top: 55px;
}
.main-nav li {
display: inline-block;
margin-left: 40px;
}
.main-nav li a:link,
.main-nav li a:visited {
padding: 8px 0px;
color: #fff;
text-decoration:none;
text-transform: uppercase;
font-size: 90%;
border-bottom: 2px solid transparent;
transition: border-bottom 0.2s;
}
.main-nav li a:hover,
.main-nav li a:active {
border-bottom: 2px solid #cf6d17;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="vendors-stuff%2520downloaded%2520from%2520Internet/css_downloaded/normalize.css">
<link rel="stylesheet" type="text/css" href="vendors-stuff%2520downloaded%2520from%2520Internet/css_downloaded/grid.css">
<link rel="stylesheet" type="text/css" href="resources/css/style.css">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,300i,400" rel="stylesheet" type="text/css">
<title>Omnifood</title>
</head>
<body>
<header>
<nav>
<div class="row">
<img src="resources/css/img/logo-white.png" alt="Omnifood logo" class="logo">
<ul class="main-nav">
<li>Food delivery</li>
<li>How it works</li>
<li>Our cities</li>
<li>Sign up</li>
</ul>
</div>
</nav>
<div class="hero-text-box">
<h1>Goodbye junk food.<br> Hello super healthy meals</h1>
<a class="btn btn-full" href="#">I'm hungry</a>
<a class="btn btn-ghost" href="#">Show me more</a>
</div>
</header>
<section class="section-features">
<div class="row">
<h2>Get food fast — not fast food.</h2>
<p class="long-copy">
Hello, we’re Omnifood, your new premium food delivery service. We know you’re always busy. No time for cooking. So let us take care of that, we’re really good at it, we promise!
</p>
</div>
<div class="row">
<div class="col span-1-of-4">
<h3>Up to 365 days/year</h3>
<p>
Never cook again! We really mean that. Our subscription plans include up to 365 days/year coverage. You can also choose to order more flexibly if that's your style.
</p>
</div>
<div class="col span-1-of-4">
<h3>Ready in 20 minutes</h3>
<p>
You're only twenty minutes away from your delicious and super healthy meals delivered right to your home. We work with the best chefs in each town to ensure that you're 100% happy.
</p>
</div>
<div class="col span-1-of-4">
<h3>100% organic</h3>
<p>
All our vegetables are fresh, organic and local. Animals are raised without added hormones or antibiotics. Good for your health, the environment, and it also tastes better!
</p>
</div>
<div class="col span-1-of-4">
<h3>Order anything</h3>
<p>
We don't limit your creativity, which means you can order whatever you feel like. You can also choose from our menu containing over 100 delicious meals. It's up to you!
</p>
</div>
</div>
</section>
</body>
</html>
/* SECTIONS ============================================================================= */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* GROUPING ============================================================================= */
.row {
zoom: 1; /* For IE 6/7 (trigger hasLayout) */
}
.row:before,
.row:after {
content:"";
display: table;
}
.row:after {
clear:both;
}
/* GRID COLUMN SETUP ==================================================================== */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; } /* all browsers except IE6 and lower */
/* REMOVE MARGINS AS ALL GO FULL WIDTH AT 480 PIXELS */
#media only screen and (max-width: 480px) {
.col {
/*margin: 1% 0 1% 0%;*/
margin: 0;
}
}
/* GRID OF TWO ============================================================================= */
.span-2-of-2 {
width: 100%;
}
.span-1-of-2 {
width: 49.2%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.span-2-of-2 {
width: 100%;
}
.span-1-of-2 {
width: 100%;
}
}
/* GRID OF THREE ============================================================================= */
.span-3-of-3 {
width: 100%;
}
.span-2-of-3 {
width: 66.13%;
}
.span-1-of-3 {
width: 32.26%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.span-3-of-3 {
width: 100%;
}
.span-2-of-3 {
width: 100%;
}
.span-1-of-3 {
width: 100%;
}
}
/* GRID OF FOUR ============================================================================= */
.span-4-of-4 {
width: 100%;
}
.span-3-of-4 {
width: 74.6%;
}
.span-2-of-4 {
width: 49.2%;
}
.span-1-of-4 {
width: 23.8%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.span-4-of-4 {
width: 100%;
}
.span-3-of-4 {
width: 100%;
}
.span-2-of-4 {
width: 100%;
}
.span-1-of-4 {
width: 100%;
}
}

Change the place of a fixed Sidebar

This code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
left: 10px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #2196F3;
display: block;
}
.sidenav a:hover {
color: #064579;
}
.main {
margin-left: 140px; /* Same width as the sidebar + left position in px */
font-size: 28px; /* Increased text to enable scrolling */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div class="sidenav">
About
Services
Clients
Contact
</div>
<div class="main">
<h2>Auto Sidebar</h2>
<p>This sidebar is as tall as its content (the links), and is always
shown.</p>
<p>Scroll down the page to see the result.</p>
</div>
</body>
</html>
Produce a fixed slidebar in the left:
But I want change the position to the right.
Like this:
so how can I put to the right the fixed slidebar?
and which command can I move the the fixed sidebar around the page?
Thank you for the help :)
In this case you can just set .sidenav {right: 10px;} but then have to remove margin from .main and to see the content add a width on the .main div which you can adjust as you wish based on content.
Using .main {margin-right: 140px;} could also do, based on the size of the .sidediv {width: 130px;}.
body {
font-family: "Lato", sans-serif;
}
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
right: 10px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #2196F3;
display: block;
}
.sidenav a:hover {
color: #064579;
}
.main {
font-size: 28px; /* Increased text to enable scrolling */
padding: 0px 10px;
width: 75%;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="sidenav">
About
Services
Clients
Contact
</div>
<div class="main">
<h2>Auto Sidebar</h2>
<p>This sidebar is as tall as its content (the links), and is always
shown.</p>
<p>Scroll down the page to see the result.</p>
</div>
</body>
</html>
Just change the left setting to right for the sidebar and the margin-left to margin-right for main
body {
font-family: "Lato", sans-serif;
}
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
right: 10px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #2196F3;
display: block;
}
.sidenav a:hover {
color: #064579;
}
.main {
margin-right: 140px;
/* Same width as the sidebar + left position in px */
font-size: 28px;
/* Increased text to enable scrolling */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
}
<div class="sidenav">
About
Services
Clients
Contact
</div>
<div class="main">
<h2>Auto Sidebar</h2>
<p>This sidebar is as tall as its content (the links), and is always shown.
</p>
<p>Scroll down the page to see the result.</p>
</div>
try this:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: "Lato", sans-serif;
}
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
right: 10px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #2196F3;
display: block;
}
.sidenav a:hover {
color: #064579;
}
.main {
margin-right: 140px; /* Same width as the sidebar + left position in px */
font-size: 28px; /* Increased text to enable scrolling */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div class="main">
<h2>Auto Sidebar</h2>
<p>This sidebar is as tall as its content (the links), and is always
shown.</p>
<p>Scroll down the page to see the result.</p>
</div>
<div class="sidenav">
About
Services
Clients
Contact
</div>
</body>
</html>
This will work.
var width = screen.width -138 +"px";
var sidenav = document.getElementById("sidenav");
sidenav.style.left = width;
body {
font-family: "Lato", sans-serif;
}
.sidenav {
width: 130px;
position: fixed;
z-index: 1;
top: 20px;
background: #eee;
overflow-x: hidden;
padding: 8px 0;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #2196F3;
display: block;
}
.sidenav a:hover {
color: #064579;
}
.main {
margin-left: 140px; /* Same width as the sidebar + left position in px */
font-size: 28px; /* Increased text to enable scrolling */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
</style>
</head>
<body>
<div class="sidenav" id="sidenav">
About
Services
Clients
Contact
</div>
<div class="main">
<h2>Auto Sidebar</h2>
<p>This sidebar is as tall as its content (the links), and is always
shown.</p>
<p>Scroll down the page to see the result.</p>
</div>
</body>
</html>

HTML/CSS Query - cant seem to reposition ul elements for mobile devices

I have run into a slight problem when trying to reposition a list (with 2 items) when on smaller devices. i have a tried a whole host of things, but haven't quite got there yet as I cannot seem to center the list elements on smaller devices.
Basically, I have a title and a list that on large devices have the title and list on the same line (title left, list items inline on the right). Then for smaller devices I want to move the list below the title, keeping them inline (same line) until it is no longer possible, when they would go below one another, but keep it centered within the page throughout this. At the moment I can move the list to the next line fine, and when both cannot fit on the same line, it moves to one on each line. However, I am having difficulty keeping them centered.
Any advice would be greatly appreciated.
Here is a jsfiddle - https://jsfiddle.net/anyd1nuf/
HTML:
<body style="overflow: auto;" class="no-touch">
<section class="soundtrack" id="Soundtrack">
<div class="container">
<header class="group">
<h2>Soundtrack</h2>
</header>
<div class="carousel-container">
<div class="responsive-carousel">
<ul class="items group">
<a href="#"><li class="item">
<p>Menu<br />.../p>
</li></a>
<a href="#"><li class="item">
<p>...<br />... - ...</p>
</li></a>
</ul>
</div>
</div>
</div>
</section>
</body>
CSS
h2 {
font-family:arial;
color:#fff;
letter-spacing: 3px;
text-transform: uppercase;
font-size: 35px;
font-size: 3.5rem; }
#media (min-width: 480px) {
h2 {
letter-spacing: 6px; } }
#media (min-width: 1000px) {
h2 {
letter-spacing: 12px; } }
.soundtrack {
background: #000;
box-shadow: 0px -20px 20px rgba(0, 0, 0, 5.175), 0px 20px 20px rgba(0, 0, 0, 5.175);
min-height: 175px;
overflow: hidden;
position: relative;
z-index: 100; }
.soundtrack .carousel-container {
margin: 0 auto;
padding: 42px 0 0;
width: auto; }
.soundtrack .carousel-container .responsive-carousel {
margin: 0 auto;
width: auto;
}
#media (max-width: 1000px) {
.soundtrack .carousel-container .responsive-carousel {
}
.soundtrack .carousel-container .responsive-carousel .items {
margin: 0 0 0 20%;
}
}
#media (min-width: 1000px) {
.soundtrack header {
float: left;
display:inline-block;
margin: 50px 5% 0 0;
}
}
.soundtrack .carousel-container .responsive-carousel .items .item {
float: left;
border: 2px solid #fff;
box-shadow:4px 4px 25px rgba(255, 255, 255, 0.075), -4px -4px 25px rgba(255, 255, 255, 0.075);
border-radius: 5px;
display: inline-block;
height: 55px;
margin: 7px 15px;
position: relative;
text-align: center;
vertical-align: top;
width: 232px;
margin: 0 0 30px 0; }
.soundtrack .carousel-container .responsive-carousel .items .item:hover {
background: none repeat scroll 0 0 rgba(255, 255, 255, 1.0);
color:#000;
box-shadow:10px 10px 25px rgba(255, 255, 255, 0.15), -10px -10px 25px rgba(255, 255, 255, 0.15);
}
#media (min-width: 480px) {
.soundtrack .carousel-container .responsive-carousel .items .item {
margin: 0 20px 30px 0; }
}
#media (min-width: 768px) {
.soundtrack .carousel-container .responsive-carousel .items .item {
margin: 0 40px 50px 0; }
.soundtrack .carousel-container .responsive-carousel .items .item img {
display: block; }
}
I have built bit simplified model, and also #Mr Lister comments are right - you had couple of issues in markup.
So you might want to adjust your particular case, but it could go like that:
HTML:
<section class="soundtrack" id="Soundtrack">
<div class="container">
<header class="group">
<h2>Soundtrack</h2>
</header>
<div class="carousel-container">
<div class="responsive-carousel">
<ul class="items group">
<li class="item"> <p>Menu</p>
</li>
<li class="item"> <p>Menu 2</p>
</li>
</ul>
</div>
</div>
</div>
</section>
CSS:
header, .carousel-container {
display:inline-block;
}
.items {
list-style:none;
margin:0;
padding:0;
}
h2 {
text-align:center;
}
.item {
display: inline-block;
padding:10px;
border:1px solid black;
border-radius:3px;
width:100px;
text-align:center;
}
#media (max-width:380px) {
header, .carousel-container {
display:block;
}
.responsive-carousel {
text-align: center;
}
}
And Fiddle is here.
Play with it, and let me know if you have any further difficulties.