Collapsable sidebar with fixed navbar - css

I am trying to create a collapsable sidebar and found an example here.
I would like to change it in order to have:
the "collapsed" sidebar to remain partially visible (in order to have
menu links reduced to buttons);
the "Collapse" button on the sidebar itself;
a fixed navbar on the main page on the right.
I can't find an example on the net, but I am trying to copy the interface in the "Windows 10 Preview" applications (take a look at the Mail or Calendar applications).
Thanks in advance for any help.

i've found this for you
Sidebar icon
You can mix with navbar top fixed

This HTML Part
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">
<a href="#">
Start Bootstrap
</a>
</li>
<li>
Dashboard
</li>
<li>
Shortcuts
</li>
<li>
Overview
</li>
<li>
Events
</li>
<li>
About
</li>
<li>
Services
</li>
<li>
Contact
</li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1>Simple Sidebar</h1>
<p>This template has a responsive menu toggling system. The menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will appear/disappear. On small screens, the page content will be pushed off canvas.</p>
<p>Make sure to keep all page content within the <code>#page-content-wrapper</code>.</p>
Toggle Menu
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
Jquery part
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
Please see this DEMO

This may help others. It has a fixed top nav, swappable mini/full side nav.
https://codepen.io/RobertoCannella/pen/poyBJGr
HTML
<div id="grid-container">
<div id="header">Header</div>
<div id="nav-button" onclick="menu()">
Navigation Button
</div>
<div id="empty-containerOne">Empty Container
</div>
<div id="navigation-menu" id="navigation-menu">Navigation Menu
</div>
<div id="mini-menu">
Mini
</div>
<div id="content">Content Window
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vitae accusamus voluptates earum delectus. Cum, illum accusantium! Laudantium enim ullam id veniam nemo, modi alias non eos, debitis beatae maxime nisi.Lorem Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus laborum tenetur similique eligendi! Porro sunt molestias unde fugiat, delectus, tenetur aperiam itaque dolores aspernatur veritatis recusandae, ut officiis aut consequatur.<p/>
</div>
<div id="footer">Footer
</div>
</div>
CSS:
#grid-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: minmax(75px, auto);
border: solid 1px red;
position: relative;
}
#grid-container > div {
position: relative;
background: #ddd;
border: dotted 1px blue;
}
#header {
grid-column: 1/5;
grid-row: 1;
}
#nav-button {
grid-column: 1;
grid-row: 2;
cursor: pointer;
}
#empty-containerOne {
grid-column: 2/5;
grid-row: 2;
}
#navigation-menu {
position: absolute;
grid-column: 1;
grid-row: 3;
left: 0px;
width: 150px;
min-height: 150px;
z-index: 1;
opacity: 90%;
transition: 300ms;
display: block;
}
#mini-menu {
position: absolute;
grid-column: 1;
grid-row: 3;
left: -30px;
width: 30px;
min-height: 150px;
z-index: 1;
opacity: 90%;
transition: 450ms;
}
#content {
grid-column: 1/5;
grid-row: 3;
padding-left: 2Rem;
}
#footer {
grid-column: 1/5;
grid-row: 4;
}
JavaScript (please ignore the poor state management.)
var i=1;
function menu() {
if(i==0){
document.getElementById("navigation-menu").style.left = '0px';
document.getElementById("mini-menu").style.left = '-30px';
i=1;
document.getElementById("toggle").src = "../images/menu.svg";
// document.getElementById("icons").style.display = 'Block';
// console.log("Colapsing menu.");
}
else {
document.getElementById("navigation-menu").style.left = '-150px';
document.getElementById("mini-menu").style.left = '0px'
i=0;
document.getElementById("toggle").src = "../images/menu_open.svg";
// document.getElementById("icons").style.display = 'none';
// console.log("Expanding menu.");
}
}

Related

Running into grid item text overflow vertically on my sidebar

Running into an issue: I have a total of five grid items, but the problem lies within two items: leftbar & rightbar - the text overflows vertically when I scale the page down. Instead, I would like for the text to remain wthin the two grid items and mold around the brand shown in the middle. I understand that I can use overflow:scroll and it would solve my issue, but that's not a solution I'm looking for. Ideally, I want the the left/rightbars to adjust around the other grid items.
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<header>
<div class = "header">
Hello, World.
</div>
</header>
<div class = "container flex">
<nav class="nav">
<ul>
<li>Home</li>
<li>Gallery</li>
<li>Options</li>
<li>Contact</li>
</ul>
</nav>
<main class="logo-center">
<div class= "logo-center-grid-items">
<h1></h1>
<h1></h1>
<h1></h1>
<h1></h1>
</div>
</main>
<div class="leftbar">
<h3>the art.</h3><br>
<p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Minima nostrum facere eum laborum blanditiis exercitationem doloremque. Veritatis suscipit sunt a earum error illum quam, adipisci, fuga corporis in distinctio molestias!
</p> <br>
<div class = "creations-btn">
creations
</div><br>
</div>
<div class="rightbar">
<h3>the craft.</h3><br>
<p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Minima nostrum facere eum laborum blanditiis exercitationem doloremque. Veritatis suscipit sunt a earum error illum quam, adipisci, fuga corporis in distinctio molestias!
</p><br>
<div class = "order-btn">
order
</div><br>
</div>
<footer>
<div class="social-media">
<i class="fab fa-facebook"></i>
<i class="fab fa-instagram"></i>
<i class="fab fa-discord"></i>
<i class="fab fa-youtube"></i>
</div>
</footer>
</div>
</body>
</html>
My CSS:
:root{
--main-radius: 25px;
--main-padding: 40px;
box-sizing: border-box;
}
.container{
display: grid;
height: 100vh;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: auto 35% 35% auto;
grid-template-areas:
"nav nav nav nav"
"leftbar main main rightbar"
"leftbar main main rightbar"
"footer footer footer footer";
grid-gap: 1.5rem;
text-align: center;
margin: 15px;
margin-bottom: 45px;
}
/* grid items (5) */
/* nav (deleted for the sake of unimportance) */
/* logo center */
.logo-center {
grid-area: main;
display: grid;
}
.logo-center > div {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
}
.logo-center h1 {
background-attachment: fixed;
}
/* left sidebar */
.leftbar{
grid-area: leftbar;
}
/* right sidebar*/
.rightbar{
grid-area: rightbar;
}
.rightbar > p{
margin: 20px;
}
/* footer (deleted for the sake of unimportance) */
I did find one solution that allowed the items to form around the grid like I want, adding inline-table to the parents...
display:inline-table;
width: 100%;
but ultimately this solution comes with the price of the sidebars digging into the footer.

Improved (with flexbox) old (mailny with float) grid layout that doesn't work in some browsers: gutter not respected

I have just created a grid layout with old techniques (float and inline elements). It works enough nicely. Briefly I have a top-level wrapper class to center and limit size content. There are 2 main sections, each one with a header (20%) ,and the remainder (80%) is subdivided in different ways. There is even an elastic gutter (in em) setted with padding. I have designed the layout with in mind a good separation between content and presentation for high code maintainability and for this rason there is some redundant tag (especially divs).
Here is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Float layout plus wrapping rows using inline-block</title>
<!-- the base styles and "housekeeping" styles are in here: -->
<link rel="stylesheet" href="css/grid-base.css">
<!-- the HTML5 shiv, to help older browsers understand styling
on newer HTML5 elements: -->
<script src="js/html5shiv.min.js"></script>
<style>
/* grid styling */
.row {
margin: 0 -.6875em;
padding: 0;
list-style: none;
}
.row:after {
content: '';
display: block;
clear: both;
}
.row-quartet > * {
width: 25%;
}
.row-trio > * {
width: 33.3333%;
}
.col {
float: left;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0 .6875em 1.375em;
}
.col:last-child {
float: right;
}
.row-wrapping {
font-size: 0;
margin: 0 -11px;
margin: 0 -.6875rem;
}
.row-wrapping > * {
float: none;
vertical-align: top;
display: inline-block;
font-size: 16px;
font-size: 1rem;
}
/* content styling */
.subcategory {
margin-top: 1.5em;
border-bottom: 1px solid #8e3339;
}
.subcategory-featured {
width: 50%;
}
.subcategory-content {
width: 80%;
}
.subcategory-header {
width: 20%;
}
.story {
padding: .6875em;
background-color: #eee;
}
.story + .story {
margin-top: 1.375em;
}
.story img {
width: 100%;
}
</style>
</head>
<body>
<header class="masthead">
<div class="wrapper">
<h1>Important News</h1>
</div>
</header>
<nav role="navigation" class="navbar">
<div class="wrapper">
<ul class="navlist">
<li>Home</li>
<li>World</li>
<li>Local</li>
<li>Sports</li>
</ul>
</div>
</nav>
<main class="wrapper">
<section class="subcategory">
<div class="row">
<header class="col subcategory-header">
<h2>Lorem ipsum</h2>
</header>
<div class="col subcategory-content">
<div class="row row-quartet">
<div class="col subcategory-featured">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3>Cras suscipit nec leo id.</h3>
<p>Autem repudiandae aliquid tempora quos reprehenderit architecto, sequi repellat.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3>Perferendis, ipsam!</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3>Curabitur mattis purus nec velit.</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
</div>
<ul class="row row-quartet row-wrapping">
<li class="col">
<div class="story">
<h3>Perferendis, ipsam! Dolor sit amet consectetur</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Aliquam mattis eros id posuere.</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Proin leo felis, semper nec</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Aliquam vitae risus tortor. Sed!</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Perferendis, ipsam!</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Aliquam mattis eros id posuere.</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Proin leo felis, semper nec</h3>
</div>
</li>
<li class="col">
<div class="story">
<h3>Aliquam vitae risus tortor. Sed!</h3>
</div>
</li>
</div>
</div>
</div>
</section>
<section class="subcategory">
<div class="row">
<header class="col subcategory-header">
<h2>Dolor sit amet</h2>
</header>
<div class="col subcategory-content">
<div class="row row-trio">
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3>Ut sit amet mi massa</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<h3>Nunc mollis sit amet nunc</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
<article class="story">
<h3>Duis sed ante enim. Cras</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
<div class="col">
<article class="story">
<img src="http://placehold.it/600x300" alt="Dummy image">
<h3>Animi, explicabo, ipsum</h3>
<p>Neque magnam vero obcaecati facere nobis sint dolore accusamus vitae consequuntur ad necessitatibus, laborum molestiae.</p>
</article>
</div>
</div>
</div>
</div>
</section>
</main>
</body>
</html>
And the extern .css:
body {
margin: 0;
line-height: 1.375;
font-family: Georgia, Times New Roman, Times, serif;
}
h1,h2,h3,h4,h5,h6 {
font-family: Avenir Next, Avenir, Franklin Gothic, Trebuchet MS, Arial, sans-serif;
margin-top: 0;
}
a {
color: #8E3339;
text-decoration: none;
}
a:hover,
a:focus {
text-decoration: underline;
}
/* here's our wrapper */
.wrapper {
width: 95%;
max-width: 76em;
margin: 0 auto;
}
/* masthead styling */
.masthead {
background-color: #8E3339;
}
.masthead h1 {
margin: 0;
padding: 0.5em 0;
color: #fff;
text-shadow: -.1em .1em 0 rgba(0,0,0,0.3);
}
/* navbar styling */
.navbar {
background-color: #5E2126;
margin-bottom: 1.375em;
}
nav {
display: block;
}
.navbar ul {
font-family: 'Avenir Next', Avenir, Corbel, 'Franklin Gothic', 'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
list-style: none;
padding: 0;
margin: 0;
background-color: #752A2F;
display: flex;
overflow: hidden;
}
.navbar li {
float: left;
text-transform: uppercase;
text-align: center;
box-sizing: border-box;
flex: 1 1 auto;
border-left: 1px solid #8E3339;
}
.navbar li:first-child {
border-left: 0;
}
.navbar li a {
display: block;
text-decoration: none;
line-height: 1.75em;
padding: 1em 2em;
color: #fff;
}
https://jsfiddle.net/36q59rav/
To improve the code I introduced in a second moment (A sort of progressive enhancement) the power of flexbox, to add several embellishments as box of equal height that is a tricky feature to have with float (in actual fact there was already flexbox for the navbar with float like fallback).
I'm using Modernizr to test specific flexbox support (class flexbox and flexwrap). I have reached an awesome result in Firefox (for my limited experience) but with my big surprise when I test the code in Google Chrome there is a visual mistake: the second nested row of first section is overlapped to first row and I'm not able to understand why.
Here is the code:
https://jsfiddle.net/rs7n8hLm/
You can see the same problem in the jsfiddle browser.
Advice is also appreciated because I'm in a blind alley, and I'm very available if some line of code is obscure.
Thanks in advance.
Here a screenshot of the problem.
https://ibb.co/jkNKRnY

Problem with positioning elements using Grid

I am trying to place a section with 4x4 fields. Each field will hold a picture with header and paragraph centered horizontally and vertically on a picture. I would like to do that by not implementing pictures as a backgrounds for each field. I am having problem centering header and paragraph in a field.
.container-2 {
width: 100%;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(2, 1fr);
margin-bottom: 100px;
}
#pic-1 {
grid-column: 1/3;
grid-row: 1/2;
width: 100%;
height: 100%;
}
#pic-1 img {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#pic-1 h3 {
z-index: 1;
text-align: center;
}
#pic-2 {
grid-column: 3/5;
grid-row: 1/2;
}
#pic-3 {
grid-column: 1/3;
grid-row: 2/3;
}
#pic-4 {
grid-column: 3/5;
grid-row: 2/3;
}
<div class="container-2">
<div id="pic-1">
<img src="./img/practise-areas.jpg" alt="">
<h3>USLUGE KOJE PRUZAMO</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi velit, consequatur veniam dolorem eligendi tenetur ex?</p>
</div>
<div id="pic-2">
<img src="./img/who-we-are.jpg" alt="">
<h3>KO SMO MI?</h3>
</div>
<div id="pic-3">
<img src="./img/getting-started2.jpg" alt="">
<h3>KONTAKTIRAJTE NAS</h3>
</div>
<div id="pic-4">
<img src="./img/how-we-work.jpg" alt="">
<h3>NAS NACIN RADA</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi velit, consequatur veniam dolorem eligendi tenetur ex?</p>
</div>
</div>
[...] not implementing pictures as a backgrounds
One approach which creates the effect you are looking to achieve (ie. employing marked up images as element backgrounds) is to give each image which precedes the heading and the paragraph a position: absolute (to take it out of document flow) and then apply the styles: top: 0, left: 0 and width: 100%, height: 100%.
I am having problem centering header and paragraph in a field.
To horizontally center the heading and the paragraph in each field, you simply need to apply the style: text-align: center.
Working Example:
.container-2 {
display: grid;
grid-template-columns: repeat(2, 50%);
grid-template-rows: repeat(2, 50%);
}
.container-2 div {
position: relative;
text-align: center;
}
.container-2 img {
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div class="container-2">
<div id="pic-1">
<img src="./img/practise-areas.jpg" alt="">
<h3>USLUGE KOJE PRUZAMO</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi velit, consequatur veniam dolorem eligendi tenetur ex?</p>
</div>
<div id="pic-2">
<img src="./img/who-we-are.jpg" alt="">
<h3>KO SMO MI?</h3>
</div>
<div id="pic-3">
<img src="./img/getting-started2.jpg" alt="">
<h3>KONTAKTIRAJTE NAS</h3>
</div>
<div id="pic-4">
<img src="./img/how-we-work.jpg" alt="">
<h3>NAS NACIN RADA</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi velit, consequatur veniam dolorem eligendi tenetur ex?</p>
</div>
</div>

Text not adjusting to browser window

I've bee experimenting lately with a responsive container for image, text and two columns of lists and can't seem to be able to make the text adjust to the browser window when I re-size it. Let me know if you have any ideas of why this might be happening. Thank you!
Here's the HTML:
<div id="wrapper">
<div class="content">
<img src="http://www.labyrinth.net.au/~toonist/flash_goodies/graphics/image_sizes/rotate_circle_100.gif">
</div>
<div class="maintext">
<h3>Heading</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident deserunt architecto quasi quaerat cupiditate quis harum ipsum ipsa veritatis suscipit iure velit asperiores ipsam vitae reiciendis quos aliquam doloribus repellendus.</p>
<div class="linkleft">
<ul>
<li>Left Item 1</li>
<li>Left Item 2</li>
<li>Left Item 3</li>
</ul>
</div>
<div class="linkright">
<ul>
<li>Right Item 1</li>
<li>Right Item 2</li>
<li>Right Item 3</li>
</ul>
</div>
</div>
And the CSS:
p {
overflow: hidden;
}
#wrapper {
width:650px
}
.content {
float:left;
margin:0 25px;
}
.maintext {
float:left;
padding-bottom: 25px;
width:500px;
}
.linkleft, .linkright {
display: block;
width: 100%;
}
#media only screen and (min-width: 800px) {
.linkleft, .linkright {
display: inline-block;
width: 50%;
float: left;
background-color: green;
}
}
#media only screen and (min-width: 480px) {
.maintext{
background-color: tomato;
}
}
Here's also the link to the pen: http://codepen.io/carlos_serrano/pen/jrcFu
Fixing a "width" will force the div to remain that width unless otherwise stated.
Using
max-width: xyz
will allow it to expand to whatever value you like and then collapse to your min-width.
http://codepen.io/anon/pen/rhFcs

Keeping lists from wrapping around image

I'm trying to keep a couple of lists aligned to the left with some text and un-wrapping around an image on desktop/tablet and mobile but don't seem to be making a lot of progress.
Here's the Codepen: http://codepen.io/carlos_serrano/pen/ikjeg
and here the code for what I have so far:
HTML:
<div class="content">
<img src="any 100x 100 image.gif">
<h3>Heading</h3>
<p>Just random text here.</p>
</div>
<div class="linkcontainer">
<div class="linkleft">
<ul>
<li>Left Item 1</li>
<li>Left Item 2</li>
<li>Left Item 3</li>
</ul>
</div>
<div class="linkright">
<ul>
<li>Right Item 1</li>
<li>Right Item 2</li>
<li>Right Item 3</ul>
</div>
Here's the CSS:
p{
overflow: hidden;
}
img{
float:left;
margin: 0 25px;
}
.linkcontainer {
width: 50%;
padding-bottom: 25px;
clear: both;
}
.linkleft, .linkright {
width: 100%;
float: right;
}
#media only screen and (min-width: 481px) {
.linkleft, .linkright {
display: inline-block;
width: 30%;
float: left;
}
}
Ok, if I understood your question (and clarification in your comment) correctly, this is what you need to do:
First, move the heading and the text into the linkcontainer:
<div class="content">
<img src="http://www.labyrinth.net.au/~toonist/flash_goodies/graphics/image_sizes/rotate_circle_100.gif" />
</div>
<div class="linkcontainer">
<h3>Heading</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident deserunt architecto quasi quaerat cupiditate quis harum ipsum ipsa veritatis suscipit iure velit asperiores ipsam vitae reiciendis quos aliquam doloribus repellendus.</p>
<div class="linkleft">
<!-- ... -->
</div>
</div>
Then ensure content and linkcontainer are both floated left:
.content {
float:left;
margin:0 25px
}
.linkcontainer {
float:left;
padding-bottom: 25px;
}
I updated your pen: http://codepen.io/anon/pen/aAiqj
EDIT: Upon further clarification, there is a better solution that will help prevent wrapping the heading, text and menus on smaller screens: make sure you wrap the 2 main divs into a wrapper div and set the width of this one to the total of the inner divs (plus margins).
#wrapper {
width: 750px
}
.content {
float: left;
margin: 0 25px;
width: 200px;
}
.linkcontainer {
float: left;
padding-bottom: 25px;
width: 500px;
}
<div id="wrapper">
<div class="content">
<img src="http://www.labyrinth.net.au/~toonist/flash_goodies/graphics/image_sizes/rotate_circle_100.gif">
</div>
<div class="linkcontainer">
<!-- ... -->
</div>
</div>
Here is your newest pen: http://codepen.io/anon/pen/hJbmr

Resources