Trying to center hamburger menu in content box - html

Hamburger Menu
As shown above, my hamburger menu is stuck in the top left of its container. I'm trying to get it centered with the rest of the header content. Right now this is the code I have...
HTML
<header>
<ul class="main-menu-ls">
<li class="main-menu-ls main-logo">
<a class="logo-link" href="artsol.HTML"></a>
</li>
<li class="main-menu-ls search-wrapper">
<form class="main-search" action="/search">
<input class="main-search-bar-input" type="search" name="q" placeholder="Search:" value=""
autocapitalize="off" autocomplete="off">
</form>
</li>
<li class="main-menu-ls cart-link-container">
<a class="cart-link" href="cart.html"></a>
</li>
<li class="main-menu-ls wallet-btn-container">
<button onclick="togglePopupWallet()" class="wallet-btn">Wallet</button>
</li>
<li class="main-menu-ls login-btn-container">
<button onclick="togglePopupLogin()" class="login-btn">Login</button>
</li>
<li class="h-menu-container" id="h-menu-container">
<input class="main-menu-ls menu-checkbox" type="checkbox" id="menu_checkbox">
<label class="h-menu-btn" for="menu_checkbox">
<div></div>
<div></div>
<div></div>
</label>
</li>
</ul>
CSS
.main-menu-ls {
height: 48px;
margin: 0;
padding: 0;
width: 100%;
border: 0;
border-bottom: 1px solid #443E7A;
display: inline-flex;
text-align: center;
align-items: center;
justify-content: center;
list-style: none;
}
.h-menu-container {
margin: 0 auto;
position: relative;
text-align: center;
display: inline-flex;
width: var(--main-menu-height);
height: var(--main-menu-height);
align-items: center;
}
.h-menu-btn {
justify-content: center;
align-items: center;
text-align: center;
}
#menu_checkbox {
display: none;
}
label {
display: inline-block;
position: relative;
align-items: center;
justify-content: center;
/* top: 75%; */
/* right: 0;
left: 0; */
margin: 0 auto;
width: var(--main-menu-height);
height: var(--main-menu-height);
/* transform: translateY(-50%); */
transition: 0.3s ease transform, 0.3s
ease background-color;
cursor: pointer;
}
What I want to happen is to have the hamburger menu toggle centered in the container and when I toggle it'll do a little animation where it turns into a horizontal ellipse in the same position while changing the parent containers background color to match the menu that will be added. Although I can't continue until I find out how to center the divs that create the menu.

There are three ways to center a child in a div(parent).
/* Using FlexBox */
.parent {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 100px;
background-color: aqua;
}
/* Using Grid Layout */
.parent2 {
display: grid;
place-content: center;
width: 100px;
height: 100px;
background-color: rgb(112, 172, 132);
}
/* Giving the parent position relative and making the child postion absoulute */
.parent3 {
position: relative;
width: 100px;
height: 100px;
background-color: rgb(88, 20, 165);
}
.parent3 h1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -100%);
}
<div class="parent">
<h1>ABC</h1>
</div>
<div class="parent2">
<h1>ABC</h1>
</div>
<div class="parent3">
<h1>ABC</h1>
</div>

Related

expanding text background color to fit portion of div box

I'm trying to get the attached results.
The entire page is on a grid layout.
Every time I try to adjust the height to 100% to try to fill the tabs div box it overflows like this
.tabs{
display: inline-block;
font-size: 20px;
}
.prints {
display: inline-block;
background: black;
width: 100%;
height: 100%;
color: #ffffe6;
transform: rotate(90deg);
text-align: center;
top: 7%;
}
.shop{
display: inline-block;
background: #e95514;
color: black;
transform: rotate(90deg);
top: 85%;
text-align: center;
}
<div class="tabs">
<div class="prints">
PRINTS
</div>
<div class="shop">
SHOP
</div>
</div>
I have a solution here where you only rotate the content of the divs (prints and shop). I added p tag inside prints and shop so I can rotate the content of the div.
body {
margin: 0;
padding: 0;
}
.tabs {
position: fixed;
right: 0;
top: 0;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
font-size: 20px;
}
.prints {
display: inline-block;
background: black;
color: #ffffe6;
width: 100%;
text-align: center
}
.shop {
display: inline-block;
background: #e95514;
color: black;
width: 100%;
text-align: center;
}
.prints, .shop {
padding: 1rem 0;
}
.prints > p, .shop > p {
transform: rotate(90deg)
}
<body>
<div class="tabs">
<div class="prints">
<p>PRINTS</p>
</div>
<div class="shop">
<p>SHOP</p>
</div>
</div>
</body>

Have :focus Toggle Items Including If You Click The Parent Item Again

I have a simple submenu that is toggled into visibility using the :focus CSS selector.
It shows the submenu by turning the submenu from display: none to display: block with the following CSS:
.menu-item:focus > .submenu {
display: block;
}
This all works, and if I click on a different menu item (or anywhere else on the page) the submenu then disappears.
Is it possible however with CSS (and I'm guessing :focus) to have it so when I click on the initial menu-item again (i.e. for a 2nd time) it also toggles away? At the moment this isn't happening - it is only happening when I click anywhere else (which is clearly when the element loses focus).
Many thanks
Codepen: https://codepen.io/emilychews/pen/RwVVmjm
body {
display: flex;
justify-content: center;
margin: 0;
height: 100vh;
width: 100%;
}
header {
margin-top: 2rem;
display: flex;
width: 50%;
justify-content: space-evenly;
align-items: center;
padding: 1rem;
background: red;
height: 2rem;
}
.menu-item {
position: relative;
padding: 1rem;
background: yellow;
cursor: pointer;
}
/* select the focused menu-item's child elements (the submenu) */
.menu-item:focus > .submenu {
display: block;
}
.submenu {
display: none; /* changes to 'block' with focus */
padding: 1rem;
background: lightblue;
position: absolute;
top: 4rem;
left: 0;
width: 6rem;
}
<header>
<div id="item-1" class="menu-item menu-item-1" tabindex="0">ITEM 1
<div id="sub-item-1" class="submenu submenu-1">SUB-ITEM-1</div>
</div>
<div id="item-2" class="menu-item menu-item-2" tabindex="0">ITEM 2
<div id="sub-item-2" class="submenu submenu-2">SUB-ITEM-2</div>
</div>
</header>
The best way for my opinion is to use JavaScript.
However you can use checkbox and changing the wrapper div to label for only CSS solution :
body {
display: flex;
justify-content: center;
margin: 0;
height: 100vh;
width: 100%;
}
header {
margin-top: 2rem;
display: flex;
width: 50%;
justify-content: space-evenly;
align-items: center;
padding: 1rem;
background: red;
height: 2rem;
}
.menu-item {
position: relative;
padding: 1rem;
background: yellow;
cursor: pointer;
}
/* select the element after the checked checkbox (the submenu) */
.dis:checked ~ .submenu {
display: block;
}
.dis{ /*reset default checkbox style*/
display: none
}
.submenu {
display: none; /* changes to 'block' with focus */
padding: 1rem;
background: lightblue;
position: absolute;
top: 4rem;
left: 0;
width: 6rem;
}
<header>
<label id="item-1" class="menu-item menu-item-1" tabindex="0">ITEM 1
<input type="checkbox" class="dis">
<div id="sub-item-1" class="submenu submenu-1">SUB-ITEM-1</div>
</label>
<label id="item-2" class="menu-item menu-item-2" tabindex="0">ITEM 2
<input type="checkbox" class="dis">
<div id="sub-item-2" class="submenu submenu-2">SUB-ITEM-2</div>
</label>
</header>

Navbar elements on top of each other instead of spaced out. Display: flex, and space-inbetween

I'm trying to space my logo and hamburger menu to either side of the page, with the logo on the left and hamburger on the right. The two elements are either reversed, or on top of each other. I can't even remember all of the things I've tried in order to fix it... it's been hours of reworking.
html
<nav>
<div id="topNav" class="navigation">
<span id="closebtn" onclick="navToggle()">
<span class="line1"></span>
<span class="line2"></span>
<span class="line3"></span>
</span>
<ul class="menulist">
<li><a class="menuitems" href="project3.html">PUPSPOT</a></li>
<li><a class="menuitems" href="project.html">POTTED</a></li>
<li><a class="menuitems" href="about.html">ABOUT</a></li>
<li><a class="menuitems" href="contact.html">CONTACT</a></li>
</ul>
</div>
<div id="main">
</div>
<div class="logo">
<img src="images/madlogo.png"/>
</div>
</nav>
CSS
* {
box-sizing: border-box;
}
html {
font-size: 10px;
}
html,body
{
background-color: #f7f7f8;
width: 100%;
height: auto;
margin: 0px;
padding: 0px;
position: relative;
}
body {
transition: background-color .5s;
}
.container {
background-color: #f7f7f8;
display: grid;
grid-template-columns: 1fr;
grid-auto-rows: minmax(1px, auto);
grid-template-areas:
"nav"
"hero"
"proj"
"process";
padding-bottom: 5rem;
position: relative;
text-align: center;
width: 100%;
margin: 0 auto;
min-height: 100vh;
}
nav {
display: flex;
flex-direction: row;
align-items: center;
position: sticky;
top: 0;
width: 100%;
z-index: 99;
display: flex;
grid-area: nav;
}
.navigation {
width: 100%;
position: sticky;
z-index: 1;
top: 0;
overflow: hidden;
transition: all 0.4s ease-in-out;
padding-top: 0px;
}
.logo {
margin:0 auto;
position: absolute;
width: 4%;
}
navbar
Alright, so first I would recommend looking at my article for some nice CSS references...
https://medium.com/#hunter.campbell843/css-references-for-new-developers-and-old-6e3dbead437f
Also you just need a justifyContent: space-between attribute on your nav element and to put your "main" element outside your element. Here's what I did to your code below....
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
html {
font-size: 10px;
}
html,
body {
background-color: #f7f7f8;
width: 100%;
height: auto;
margin: 0px;
padding: 0px;
position: relative;
}
body {
transition: background-color 0.5s;
}
.container {
background-color: #f7f7f8;
display: grid;
grid-template-columns: 1fr;
grid-auto-rows: minmax(1px, auto);
grid-template-areas:
"nav"
"hero"
"proj"
"process";
padding-bottom: 5rem;
position: relative;
text-align: center;
width: 100%;
margin: 0 auto;
min-height: 100vh;
}
nav {
display: flex;
flex-direction: row;
justify-content: space-between; /*This pushes your child elements to each extreme, what you were missing*/
align-items: center;
position: sticky;
top: 0;
/* width: 100%; */ /*You're using grid so you shouldn't need this*/
z-index: 99;
grid-area: nav;
}
.navigation {
/* width: 100%; Don't need either*/
position: sticky;
z-index: 1;
top: 0;
overflow: hidden;
transition: all 0.4s ease-in-out;
padding-top: 0px;
}
.logo {
width: 50px;
height: 50px;
/* margin: 0 auto; Don't need either*/
/* position: absolute; Don't need either*/
width: 4%;
}
</style>
</head>
<body>
<nav>
<div class="logo">
<img src="" />
</div>
<div id="topNav" class="navigation">
<span id="closebtn" onclick="navToggle()">
<span class="line1"></span>
<span class="line2"></span>
<span class="line3"></span>
</span>
<ul class="menulist">
<li><a class="menuitems" href="">PUPSPOT</a></li>
<li><a class="menuitems" href="">POTTED</a></li>
<li><a class="menuitems" href="">ABOUT</a></li>
<li><a class="menuitems" href="">CONTACT</a></li>
</ul>
</div>
</nav>
<div id="main"></div> <!--Your main element was inside your nav element throwing everything off-->
</body>
</html>

Absolute div inside flexbox div behaving like fixed

I'm designing a responsive chat page view on react and i'm struggling with the following problem.
I have a div menu with absolute position which is displayed on top of all the elements when click the menu button as you can see here:
Everything seems ok, even when i resize the screen to phone dimentions it displays as i expect because i have a media query which modifies the left property to fit the div where i want. But on the phone view, when i scroll the page the div moves in its offset position along the screen and i couldn't fixing it:
As far i know this behavior corresponds to fixed position, i've got understood that if i apply an absolute position the div should stays on his place. But i don't know what is happening here. Maybe it may be messing up it because i'm working with flex (everything is positioned with flex using its direction property to arrange my elements).
This is my JSX code:
return (
<div id="chat-page-main-container" onClick={onMainContainerClick}>
<div id="chat-main-menu-select" style={{ display: displayMenu }}>
<ul className="list-group">
<li className="list-group-item">Profile</li>
<li className="list-group-item">Create new group</li>
<li className="list-group-item">Log out</li>
</ul>
</div>
<div id="chat-left-side-content">
<div id="chat-main-menu">
<img
src="https://upload.wikimedia.org/wikipedia/commons/e/e8/The_Joker_at_Wax_Museum_Plus.jpg"
alt="unavailable"
/>
<div id="chat-main-menu-options">
<div className="main-menu-options-icons">
<i id="chat-comment-icon" className="fa fa-comments"></i>
</div>
<div
className="main-menu-options-icons"
style={{ backgroundColor: selectedItem }}
>
<i
id="chat-menu-icon"
className="fa fa-bars"
onClick={onMenuIconClick}
></i>
</div>
</div>
</div>
<div id="search-conversation-bar">
<i className="fa fa-search"></i>
<input type="text" placeholder="Search for a conversation" />
</div>
<div id="chats-component-container">
{data.map((object, index) => (
<ChatCard key={index} data={object} />
))}
</div>
</div>
<div id="chat-right-side-content">
<div id="conversation-splash-screen">
<img src={conversationImage} alt="unavailable" />
<h3>Welcome to tellit chat page!</h3>
<p>
You can search for a contact or a conversation on the left menu.
</p>
</div>
</div>
</div>
);
And this is my SASS code:
::-webkit-scrollbar {
width: 8px
}
::-webkit-scrollbar-track {
background: whitesmoke;
}
::-webkit-scrollbar-thumb {
background: #bababa;
}
#chat-page-main-container {
display: flex;
flex-direction: row;
height: 100%;
overflow-x: auto;
white-space: nowrap;
#chat-main-menu-select {
position: absolute;
top: 4em;
left: 12em;
ul {
border-radius: 5px;
cursor: pointer;
}
li:hover {
background-color: #ededed;
}
}
#chat-left-side-content {
display: flex;
flex-direction: column;
min-width: 400px;
height: 100%;
border-right: solid 1px #bababa;
#chat-main-menu {
width: 100%;
height: 71px;
padding: 10px 25px;
border-bottom: solid 1px #bababa;
background-color: #EDEDED;
img {
width: 50px;
height: 50px;
border-radius: 50%;
float: left;
}
#chat-main-menu-options {
display: flex;
flex-direction: row;
float: right;
height: 100%;
padding-top: 5px;
.main-menu-options-icons {
font-size: 25px;
opacity: 0.5;
text-align: center;
width: 40px;
border-radius: 50%;
margin: 0 10px;
i {
cursor: pointer;
}
}
}
}
#search-conversation-bar {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
background-color: #EDEDED;
padding: 10px 0;
border-bottom: solid 1px #bababa;
input {
border-radius: 30px;
border: none;
width: 85%;
height: 40px;
font-family: "Segoe UI";
font-size: 13px;
padding: 0 43px;
&:focus {
outline: none;
}
}
i {
font-size: 20px;
position: relative;
left: 30px;
top: 10px;
}
}
#chats-component-container {
overflow-y: auto;
overflow-x: hidden;
}
}
#chat-right-side-content {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
height: 100%;
background-color: white;
#conversation-splash-screen {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 5em;
img {
width: 30em;
height: 30em;
}
}
}
}
#media (max-width: 500px) {
#chat-left-side-content {
min-width: 300px !important;
}
#chat-right-side-content {
min-width: 600px !important;
#conversation-splash-screen {
padding-top: 3em !important;
}
}
#chat-main-menu-select {
left: 6em !important;
}
}
Another fact i want to add is that i also tried to change the absolute position to relative, but this last mess up the container div displaying a space blank or rearranging the elements inside.
Any suggestion or code correction is welcome. Thank you.
set position: relative for parent (#chat-page-main-container)

Transparent fixed header with flexbox

I've been trying to make a page with a fixed transparent header, using flexbox. At first, I found that somehow this causes a confliction (the fixed positioning and the flex) and the justify-content or align-items properties won't work on the child elements of the wrapper flex-fixed parent. The child elements of the fixed parent won't space appropriately.
But then I saw this https://templated.co/industrious, and somehow it works!
So I cannot understand why it doesn't work with my code. It seems to me I'm not doing it differently.
The header-fixed-flex div wraps the LOGO, NAV and search (svg) elements, but I cannot make the justify-content or align-items option to work on header-nav and navigation div's.
body {
height: 2500px;
}
.header-fixed-flex {
max-width: 150rem;
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 100;
display: flex;
justify-content: space-between;
transform: translate(19.2rem, 0);
}
.header_nav {
max-width: 155rem;
display: flex;
justify-content: space-around;
align-items: center;
}
.header_logo {
max-height: 9.7rem;
background: rgba(3, 12, 77, 0.4);
}
.header_link {
padding: 0.5rem;
}
.navigation {
background: rgba(191, 218, 218, 0.4);
display: flex;
}
.navigation_list {
list-style: none;
letter-spacing: 0.4rem;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
align-items: center;
height: 100%;
}
.navigation_item:not(:last-child) {
margin-right: 3rem;
}
.navigation_link:link, .navigation_link:visited {
color: #fff;
text-decoration: none;
padding: 0.8rem;
}
.navigation_button {
border: none;
background: none;
display: flex;
align-items: center;
}
.navigation_search-input {
border: none;
background: rgba(255, 255, 255, 0.1);
outline: none;
width: 5rem;
}
.navigation_icon {
padding: 0.5rem;
width: 3rem;
fill: #fff;
}
.hero_img {
background: url(https://twimg0-a.akamaihd.net/a/1350072692/t1/img/front_page/jp-mountain#2x.jpg) top/cover;
height: 100vh;
}
<div class="header-fixed-flex">
<div class="header_nav">
<header class="header_logo">
LOGO
</header>
<nav class="navigation">
<ul class="navigation_list">
<li class="navigation_item">
Profile
</li>
<li class="navigation_item">
Services
</li>
<li class="navigation_item">
Articles
</li>
<li class="navigation_item">
Contact
</li>
</ul>
<button class="navigation_button">
<input type="text" class="navigation_search-input" id="search-query"/>
<label for="search-query" class="navigation_search_label"></label>
<svg class="navigation_icon"></svg>
</button>
</nav>
</div>
</div>
<section class="hero">
<div class="hero_img"></div>
</section>
Or a codepen link with scss
https://codepen.io/tantoniou/pen/QoGmba
Remove the header-fixed-flex element and apply this style on header_nav
width: 100%;
top: 0;
left: 0;
position: fixed;
z-index: 100;
display: flex;
justify-content: space-between;
It's really tough to determine what you want from your writeup with no design comp or wireframe provided, but my initial guess is things aren't happening as you expect because .header-fixed-flex only has one child. So maybe setting flex: 1 or just width: 100% on .header_nav will get things working as you like.