Make the sidebar collapse linear and avoid vertical misalignments - html

I have implemented a sidebar and the collapse function (for minimizing the sidebar) works quite okay, but whenever I click on 'collapse' again to maximize the sidebar, the elements inside the sidebar are misaligned during few milliseconds and the logo text appears above the body. Please see the images below
[![enter image description here][1]][1]
[![enter image description here][2]][2]
How could I make it smoother and avoid the misalignments? It should be something linear without any vertical changes.
I've tried so many things but it was impossible for me to make it work.

Edit(2): This code is from Coding Lab, the way he did it is by replacing the class with another class every time you click the hamburger icon, changing it from bx-menu-alt-right to bx-menu or vice versa.
Since you minimize your sidebar basically to width: 0 when it reaches screen width of 786px, you could just make the logo and the whole sidebar content to disappear. Refer to this this JS fiddle, I've added some css style on your media query to not display the logo when your media query is true.
/* Google Font Link */
#import url('https://fonts.googleapis.com/css2?family=Poppins:wght#200;300;400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins" , sans-serif;
}
.sidebar{
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 78px;
background: #11101D;
padding: 6px 14px;
z-index: 99;
transition: all 0.5s ease;
}
.sidebar.open{
width: 250px;
}
.sidebar .logo-details{
height: 60px;
display: flex;
align-items: center;
position: relative;
}
.sidebar .logo-details .icon{
opacity: 0;
transition: all 0.5s ease;
}
.sidebar .logo-details .logo_name{
color: #fff;
font-size: 20px;
font-weight: 600;
opacity: 0;
transition: all 0.5s ease;
}
.sidebar.open .logo-details .icon,
.sidebar.open .logo-details .logo_name{
opacity: 1;
}
.sidebar .logo-details #btn{
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
font-size: 22px;
transition: all 0.4s ease;
font-size: 23px;
text-align: center;
cursor: pointer;
transition: all 0.5s ease;
}
.sidebar.open .logo-details #btn{
text-align: right;
}
.sidebar i{
color: #fff;
height: 60px;
min-width: 50px;
font-size: 28px;
text-align: center;
line-height: 60px;
}
.sidebar .nav-list{
margin-top: 20px;
height: 100%;
}
.sidebar li{
position: relative;
margin: 8px 0;
list-style: none;
}
.sidebar li .tooltip{
position: absolute;
top: -20px;
left: calc(100% + 15px);
z-index: 3;
background: #fff;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
padding: 6px 12px;
border-radius: 4px;
font-size: 15px;
font-weight: 400;
opacity: 0;
white-space: nowrap;
pointer-events: none;
transition: 0s;
}
.sidebar li:hover .tooltip{
opacity: 1;
pointer-events: auto;
transition: all 0.4s ease;
top: 50%;
transform: translateY(-50%);
}
.sidebar.open li .tooltip{
display: none;
}
.sidebar input{
font-size: 15px;
color: #FFF;
font-weight: 400;
outline: none;
height: 50px;
width: 100%;
width: 50px;
border: none;
border-radius: 12px;
transition: all 0.5s ease;
background: #1d1b31;
}
.sidebar.open input{
padding: 0 20px 0 50px;
width: 100%;
}
.sidebar .bx-search{
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
font-size: 22px;
background: #1d1b31;
color: #FFF;
}
.sidebar.open .bx-search:hover{
background: #1d1b31;
color: #FFF;
}
.sidebar .bx-search:hover{
background: #FFF;
color: #11101d;
}
.sidebar li a{
display: flex;
height: 100%;
width: 100%;
border-radius: 12px;
align-items: center;
text-decoration: none;
transition: all 0.4s ease;
background: #11101D;
}
.sidebar li a:hover{
background: #FFF;
}
.sidebar li a .links_name{
color: #fff;
font-size: 15px;
font-weight: 400;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: 0.4s;
}
.sidebar.open li a .links_name{
opacity: 1;
pointer-events: auto;
}
.sidebar li a:hover .links_name,
.sidebar li a:hover i{
transition: all 0.5s ease;
color: #11101D;
}
.sidebar li i{
height: 50px;
line-height: 50px;
font-size: 18px;
border-radius: 12px;
}
.sidebar li.profile{
position: fixed;
height: 60px;
width: 78px;
left: 0;
bottom: -8px;
padding: 10px 14px;
background: #1d1b31;
transition: all 0.5s ease;
overflow: hidden;
}
.sidebar.open li.profile{
width: 250px;
}
.sidebar li .profile-details{
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.sidebar li img{
height: 45px;
width: 45px;
object-fit: cover;
border-radius: 6px;
margin-right: 10px;
}
.sidebar li.profile .name,
.sidebar li.profile .job{
font-size: 15px;
font-weight: 400;
color: #fff;
white-space: nowrap;
}
.sidebar li.profile .job{
font-size: 12px;
}
.sidebar .profile #log_out{
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%);
background: #1d1b31;
width: 100%;
height: 60px;
line-height: 60px;
border-radius: 0px;
transition: all 0.5s ease;
}
.sidebar.open .profile #log_out{
width: 50px;
background: none;
}
.home-section{
position: relative;
background: #E4E9F7;
min-height: 100vh;
top: 0;
left: 78px;
width: calc(100% - 78px);
transition: all 0.5s ease;
z-index: 2;
}
.sidebar.open ~ .home-section{
left: 250px;
width: calc(100% - 250px);
}
.home-section .text{
display: inline-block;
color: #11101d;
font-size: 25px;
font-weight: 500;
margin: 18px
}
#media (max-width: 420px) {
.sidebar li .tooltip{
display: none;
}
}
<!DOCTYPE html>
<!-- Created by CodingLab |www.youtube.com/CodingLabYT-->
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<!--<title> Responsive Sidebar Menu | CodingLab </title>-->
<link rel="stylesheet" href="style.css">
<!-- Boxicons CDN Link -->
<link href='https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="sidebar">
<div class="logo-details">
<i class='bx bxl-c-plus-plus icon'></i>
<div class="logo_name">CodingLab</div>
<i class='bx bx-menu' id="btn" ></i>
</div>
<ul class="nav-list">
<li>
<i class='bx bx-search' ></i>
<input type="text" placeholder="Search...">
<span class="tooltip">Search</span>
</li>
<li>
<a href="#">
<i class='bx bx-grid-alt'></i>
<span class="links_name">Dashboard</span>
</a>
<span class="tooltip">Dashboard</span>
</li>
<li>
<a href="#">
<i class='bx bx-user' ></i>
<span class="links_name">User</span>
</a>
<span class="tooltip">User</span>
</li>
<li>
<a href="#">
<i class='bx bx-chat' ></i>
<span class="links_name">Messages</span>
</a>
<span class="tooltip">Messages</span>
</li>
<li>
<a href="#">
<i class='bx bx-pie-chart-alt-2' ></i>
<span class="links_name">Analytics</span>
</a>
<span class="tooltip">Analytics</span>
</li>
<li>
<a href="#">
<i class='bx bx-folder' ></i>
<span class="links_name">File Manager</span>
</a>
<span class="tooltip">Files</span>
</li>
<li>
<a href="#">
<i class='bx bx-cart-alt' ></i>
<span class="links_name">Order</span>
</a>
<span class="tooltip">Order</span>
</li>
<li>
<a href="#">
<i class='bx bx-heart' ></i>
<span class="links_name">Saved</span>
</a>
<span class="tooltip">Saved</span>
</li>
<li>
<a href="#">
<i class='bx bx-cog' ></i>
<span class="links_name">Setting</span>
</a>
<span class="tooltip">Setting</span>
</li>
<li class="profile">
<div class="profile-details">
<!--<img src="profile.jpg" alt="profileImg">-->
<div class="name_job">
<div class="name">Prem Shahi</div>
<div class="job">Web designer</div>
</div>
</div>
<i class='bx bx-log-out' id="log_out" ></i>
</li>
</ul>
</div>
<section class="home-section">
<div class="text">Dashboard</div>
</section>
<script>
let sidebar = document.querySelector(".sidebar");
let closeBtn = document.querySelector("#btn");
let searchBtn = document.querySelector(".bx-search");
closeBtn.addEventListener("click", ()=>{
sidebar.classList.toggle("open");
menuBtnChange();//calling the function(optional)
});
searchBtn.addEventListener("click", ()=>{ // Sidebar open when you click on the search iocn
sidebar.classList.toggle("open");
menuBtnChange(); //calling the function(optional)
});
// following are the code to change sidebar button(optional)
function menuBtnChange() {
if(sidebar.classList.contains("open")){
closeBtn.classList.replace("bx-menu", "bx-menu-alt-right");//replacing the iocns class
}else {
closeBtn.classList.replace("bx-menu-alt-right","bx-menu");//replacing the iocns class
}
}
</script>
</body>
</html>
#media (max-width: 768px) {
svg, #sidebarLinks{
display: none;
}
}
Edit: If you want to minimize and expand the sidebar using a toggle-button and leave the icons then you should separate the icons from their title/description and hide ONLY the title/description on clicking the toggle-button. Change sidebar width whenever you click using .style.property. Anyway here is a video tutorial about this same feature.

Beyond a certain width your icons and texts are bound to wrap around or overlap. It's not really a misalignment but default behavior.
What you can do is reduce the font size of your text on minimize/maximize sidebar for a range of width, say from 0px to 150px width, change your text font size to be smaller. You can also use vmin, vmax instead of px or rem for font size. Also, restrict the sidebar minimum width by changing 0 to a specific value in .card class.
Or, you can only display the icons on collapse and hide the text.

Related

Asp.net Core MVC Render Body Problem after Implementing Responsive Side Bar

After implementing sidebar its fridge my other page and didn't able to scroll the page in Asp.net Core MVC. I think the problem is comes from the _layout.cshtml file. as it has a container which render my other page. Please help me to solve this problem.
Here is My _Layout.cshtm File. The header is the side bar.
<header>
<div class="sidebar">
<div class="logo_content">
<div class="logo">
<i class='bx bxl-c-plus-plus'></i>
<div class="logo_name">dgInfoSys</div>
</div>
<i class='bx bx-menu' id="btn"></i>
</div>
<ul class="nav_list">
<li>
<i class='bx bx-search-alt'></i>
<input class="text" placeholder="Search...">
<span class="tooltip">Search</span>
</li>
<li>
<a href="#">
<i class='bx bx-grid-alt'></i>
<span class="links_name">Dashboard</span>
</a>
<span class="tooltip">Dashboard</span>
</li>
<li>
<a href="#">
<i class='bx bx-user'></i>
<span class="links_name">User</span>
<i class='bx bxs-chevron-down htmlcss-arrow arrow '></i>
</a>
<span class="tooltip">User</span>
</li>
<li>
<a href="#">
<i class='bx bxs-user-badge'></i>
<span class="links_name">Super Admin</span>
</a>
<span class="tooltip">Super Admin</span>
</li>
<li>
<a href="#">
<i class='bx bx-line-chart'></i>
<span class="links_name">Analytics</span>
</a>
<span class="tooltip">Analytics</span>
</li>
<li>
<a asp-controller="BTBTable" asp-action="Index">
<i class='bx bxs-report'></i>
<span class="links_name">Files</span>
</a>
<span class="tooltip">Files</span>
</li>
<li>
<a href="#">
<i class='bx bx-cog'></i>
<span class="links_name">Setting</span>
</a>
<span class="tooltip">Setting</span>
</li>
</ul>
<div class="profile_content">
<div class="profile">
<div class="profile_details">
#*<img src="" alt="" />*#
<div class="name_job">
<div class="name">Masum Rayhan</div>
<div class="job">Developer</div>
</div>
</div>
<i class='bx bx-log-out' id="log_out"></i>
</div>
</div>
</div>
</header>
<div id="main">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰
</span>
</div>
<div class="container">
<main role="main" class="pb-3">
#RenderBody()
</main>
</div>
And side bar css is given below:
#import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
position: relative;
min-height: 100vh;
width: 100%;
overflow: hidden;
}
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 78px;
/*width: 240px;*/
background: #11101d;
padding: 6px 14px;
transition: all 0.5s ease;
}
.sidebar.active {
width: 240px;
}
.sidebar .logo_content .logo {
color: #fff;
display: flex;
height: 50px;
width: 100%;
align-items: center;
opacity: 0;
pointer-events: none;
transition: all 0.5s ease;
}
.sidebar.active .logo_content .logo {
opacity: 1;
pointer-events: none;
}
.logo_content .logo i {
font-size: 28px;
margin-right: 5px;
}
.logo_content .logo .logo_name {
font-size: 20px;
font-weight: 400;
}
.sidebar #btn {
position: absolute;
color: #fff;
left: 50%;
top: 6px;
font-size: 20px;
height: 50px;
width: 50px;
text-align: center;
line-height: 50px;
transform: translateX(-50%);
}
.sidebar.active #btn {
left: 90%;
}
.sidebar ul {
margin-top: 20px;
}
.sidebar ul li {
position: relative;
height: 50px;
width: 100%;
margin: 0 5px;
list-style: none;
line-height: 50px;
}
.sidebar ul li .tooltip {
position: absolute;
left: 122px;
height: 35px;
width: 122px;
top: 50%;
transform: translate(-50%, -50%);
border-radius: 6px;
line-height: 35px;
text-align: center;
background: #fff;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
transition: 0s;
opacity: 0;
pointer-events: none;
}
.sidebar.active ul li .tooltip {
display: none;
}
.sidebar ul li:hover .tooltip {
transition: all 0.5s ease;
opacity: 1;
top: 50%
}
.sidebar ul li input {
position: absolute;
height: 100%;
width: 100%;
left: 0;
top: 0;
border-radius: 12px;
outline: none;
border: none;
background: #1d1b31;
padding-left: 50px;
font-size: 18px;
color: #fff;
}
.sidebar ul li .bx-search {
position: absolute;
z-index: 99;
color: #fff;
font-size: 22px;
transition: all 0.5s ease;
}
.sidebar ul li .bx-search:hover {
background: #fff;
color: #1d1b31;
}
.sidebar ul li a {
color: #fff;
display: flex;
align-items: center;
text-decoration: none;
transition: all 0.4s ease;
border-radius: 12px;
white-space: nowrap;
}
.sidebar ul li a:hover {
color: #11101d;
background: #fff;
}
.sidebar ul li a i {
height: 50px;
min-width: 50px;
border-radius: 12px;
line-height: 50px;
text-align: center;
}
.sidebar .links_name {
opacity: 0;
pointer-events: none;
transition: all 0.5s ease;
}
.sidebar.active .links_name {
opacity: 1;
pointer-events: auto;
}
.sidebar .profile_content {
position: absolute;
color: #fff;
bottom: 0;
left: 0;
width: 100%;
}
.sidebar .profile_content .profile {
position: relative;
padding: 10px 6px;
height: 60px;
background: none;
transition: all 0.4s ease;
}
.sidebar.active .profile_content .profile {
background: #1d1b31;
}
.profile_content .profile .profile_details {
display: flex;
align-items: center;
opacity: 0;
pointer-events: none;
white-space: nowrap;
}
.sidebar.active .profile .profile_details {
opacity: 1;
pointer-events: auto;
}
.profile .profile_details img {
height: 45px;
width: 45px;
object-fit: cover;
border-radius: 12px;
}
.profile .profile_details .name_job {
margin-left: 10px;
}
.profile .profile_details .name {
font-size: 15px;
font-weight: 400;
}
.profile .profile_details .job {
font-size: 12px;
}
.profile #log_out {
position: absolute;
bottom: 5px;
left: 50%;
transform: translateX(-50%);
min-width: 50px;
line-height: 50px;
font-size: 20px;
border-radius: 12px;
text-align: center;
transition: all 0.4s ease;
background: #1d1b31;
}
.sidebar.active .profile #log_out {
left: 80%
}
.sidebar.active .profile #log_out {
background: none;
}
.home_content {
position: absolute;
height: 100%;
width: calc(100% -78px);
left: 78px;
transition: all 0.5s ease;
}
.home_content .text {
font-size: 25px;
font-weight: 500;
color: #1d1b31;
margin: 12px;
}
.sidebar.active ~ .home_content {
width: calc(100% -240px);
left: 240px;
}
Check your Css code:
body {
position: relative;
min-height: 100vh;
width: 100%;
overflow: hidden;
}
The overflow property specifies whether to clip the content or to add scrollbars when the content of an element is too big to fit in the specified area
The overflow property has the following values:
visible - Default. The overflow is not clipped. The content renders
outside the element's box
hidden - The overflow is clipped, and the rest of the content will
be invisible
scroll - The overflow is clipped, and a scrollbar is added to see
the rest of the content
auto - Similar to scroll, but it adds scrollbars only when
necessary
So in your code, you just need to delete overflow: hidden; or change it as the property whtich you need.

Why is my tooltip not showing up on link hover?

I have been trying for a few days to get my tooltips to show up without any progress. They can appear in the sidebar with this block selector .sidebar ul li .tooltip {} when opacity is 1, if you want to see what they should look like.
I tried adding z-index to the .sidebar ul li a:hover .tooltip {} selector, along with opacity:1, but that doesn't work.
I also tried changing the 'hover' to apply to the 'li' instead of the 'a' tag but that doesn't change anything. and also tried adding it to both (.sidebar ul li:hover a:hover .tooltip {}) but doesn't work either.
Is this a problem with opacities, or with selectors? I feel like I've tried everything.
When I select the tooltip element in the browser dev tools and force into hover state, you can see the tooltip is there in the right spot, but just behind everything or invisible.
Any help would be appreciated thank you.
.sidebar ul li a:hover {
background-color: #ae85f1;
}
.sidebar ul li a:hover .tooltip {
transition: all 0.5s ease;
top: 50%;
opacity: 1;
display: block;
z-index:500;
}
.sidebar ul li .tooltip {
position: absolute;
color: #343434;
left: 130px;
top: 0;
transform: translate(-50%, -50%);
border-radius: 6px;
height: 35px;
width: 122px;
background: #fff;
line-height: 35px;
text-align: center;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
transition: 0s;
pointer-events: none;
opacity: 1;
}
.sidebar.active ul li .tooltip {
display: none;
}
https://jsfiddle.net/ramid320/ho148uyx/11/
There are few issues in CSS, You need to update below changes in your code.
Change 1:
Remove overflow: hidden; from ul CSS on line No: 32
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}
Change 2:
Add display: none; on sidebar ul li a .tooltip CSS on line No: 123
.sidebar ul li a .tooltip {
position: absolute;
color: #343434;
display: none;
left: 130px;
top: 0;
transform: translate(-50%, -50%);
border-radius: 6px;
height: 35px;
width: 122px;
background: #fff;
line-height: 35px;
text-align: center;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
transition: 0s;
pointer-events: none;
}
Change 3:
Add !important on sidebar.active ul li .tooltip CSS on line No: 141
.sidebar.active ul li .tooltip {
display: none !important;
}
All changes also updated on below code snippet, I hope it'll help you out. Thank You
let btn = document.querySelector("#btn");
let sidebar = document.querySelector(".sidebar");
btn.onclick= function(){
sidebar.classList.toggle("active");
}
#import url('https://fonts.googleapis.com/css2?family=Cabin&family=Poppins:wght#300;400;500;600;700&display=swap');
/*font-family: 'Poppins', sans-serif;
//font-family: 'Cabin', sans-serif;*/
--root {
--dark1: #1c1c1c;
--dark2: #daddd8;
--dark3: #ecebe4;
--dark4: #eef0f2;
--dark5: #fafaff;
--og1: #eee2ff;
--og2: #faeaff;
--og3: rgba(228, 53, 145, 0.7);
--og4: #ffd5d5;
}
*{
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
position: relative;
min-height: 100vh;
width: 100%;
overflow: hidden;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: -webkit-sticky; /* Safari */
position: sticky;
top: 0;
}
li {
float: left;
width: 25%;
}
li a {
display: block;
text-align: center;
padding: 8px 0px;
text-decoration: none;
color: #e4d9ff;
}
/*--------------------------------------------------------------sidebar styles */
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 78px;
background: #1c1c1c;
color: #e4d9ff;
padding: 6px 14px;
transition: all 0.5s ease;
z-index: 10;
}
.sidebar.active {
width: 240px;
}
.sidebar .logo_details .logo {
height: 50px;
width: 60%;
display: flex;
align-items: center;
color: #fafaff;
opacity: 0;
pointer-events: none;
}
.sidebar.active .logo_details .logo {
opacity: 1;
pointer-events: none;
}
.logo_details .logo_name {
font-size: 18px;
color: #e4d9ff;
font-weight: 400;
}
.sidebar #btn {
color: #fff;
position: absolute;
left: 50%;
top: 6px;
font-size: 18px;
height: 50px;
width: 50px;
text-align: center;
line-height: 50px;
transform: translateX(-50%);
}
.sidebar.active #btn {
left: 85%;
}
.sidebar ul{
margin-top: 20px;
}
.sidebar ul li{
position: relative;
list-style: none;
height: 56px;
width: 100%;
line-height: 30px;
}
.sidebar ul li a .tooltip {
position: absolute;
color: #343434;
display: none;
left: 130px;
top: 0;
transform: translate(-50%, -50%);
border-radius: 6px;
height: 35px;
width: 122px;
background: #fff;
line-height: 35px;
text-align: center;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
transition: 0s;
pointer-events: none;
}
.sidebar.active ul li .tooltip {
display: none !important;
}
.sidebar ul li a {
color: #fff;
display: flex;
align-items: center;
text-decoration: none;
border-radius: 12px;
transition: all 0.4s ease;
white-space: nowrap;
}
.sidebar ul li i{
height: 40px;
min-width: 50px;
border-radius: 12px;
line-height: 40px;
text-align: center;
}
.sidebar ul li a:hover {
background-color: #ae85f1;
}
.sidebar ul li:hover .tooltip {
transition: all 0.5s ease;
top: 50%;
display: block;
z-index: 500;
}
.sidebar .link_name{
opacity: 0;
pointer-events: none;
}
.sidebar.active .link_name{
opacity: 1;
pointer-events: auto;
}
.sidebar .profile_content {
position: absolute;
color: #fff;
bottom: 0;
left: 0;
width: 100%;
}
.logo_details .logo i {
font-size: 28px;
margin-right: 5px;
left: 50%;
}
.sidebar .profile_content .profile{
position: relative;
padding: 10px 6px;
height: 60px;
}
.profile_content .profile .profile_details{
display: flex;
align-items: center;
}
.profile .profile_details img{
height: 45px;
width: 45px;
object-fit: cover;
border-radius: 12px;
}
.profile .profile_details .name_job {
margin-left: 10px;
}
.profile .profile_details .name{
font-size: 15px;
font-weight: 400;
}
.profile .profile_details .job{
font-size: 12px;
}
/* --------------------------------------------------page styles */
.container {
margin: 0 auto;
padding: 60px 100px;
position: absolute;
background-color: green;
}
.headerBox h1 {
display: block;
padding-left: -20px;
position: relative;
font: 60px 'Lobster', cursive;
letter-spacing: 0px;
color: #e5383b; /*red web portfolio text*/
}
.headerBox {
height: 300px;
background-color: white;
padding-left: 200px;
}
#footnote {
font-size: 10px;
text-align: center;
color: #343434;
}
/* media queries */
#media screen and (max-width: 539px) {
.container {
padding: 0px 25px;
margin: 0px;
}
}
#media screen and (min-width: 540px) and (max-width: 699px) {
.headerBox h1 {
font: 80px 'Lobster', cursive;
height: 60px;
}
h1:after {
position: absolute; left: 3px; top: 3px;
}
.container {
padding: 0px 30px;
margin: 0px;
}
.headerBox h2 {
font-size: 20px;
display: block;
line-height: 20px;
margin-bottom: 16px;
}
}
#media screen and (min-width: 700px) and (max-width: 875px) {
.headerBox h1 {
font: 100px 'Lobster', cursive;
height: 100px;
}
.container {
padding: 0px 50px;
margin: 0px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Personal Portfolio</title>
<!--fonts
font-family: 'Montserrat', sans-serif;
font-family: 'Roboto Mono', sans-serif;
font-family: 'Lobster', cursive;
font-family: 'Comfortaa', cursive;
-->.
<link href="https://fonts.googleapis.com/css?family==Lobster" rel="stylesheet">
<!--page css-->
<link rel="stylesheet" type="text/css" href="css/styles.css">
<!-- the below three lines are a fix to get HTML5 semantic elements working in old versions of Internet Explorer-->
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
<link href='https://unpkg.com/boxicons#2.1.1/css/boxicons.min.css' rel='stylesheet'>
</head>
<body>
<div class="sidebar">
<div class="logo_details">
<div class="logo">
<i class='bx bx-moon'></i>
<span class="logo_name">DRamirez</span>
</div>
<i class="bx bx-menu" id="btn"></i>
</div>
<ul class="nav_links">
<li><a href="#">
<i class='bx bx-home'></i>
<span class="link_name">Home</span>
<span class="tooltip">Home</span></a>
</li>
<li><a href="#">
<i class='bx bx-paperclip'></i>
<span class="link_name">Resume</span>
<span class="tooltip">Resume</span></a>
</li>
<li>
<div class="icon_link" >
<a href="#">
<i class='bx bxl-javascript' ></i>
<span class="link_name">JS Games</span>
<span class="tooltip">JS Games</span></a>
<!--i class='bx bxs-chevron-down' ></i-->
</div>
</li>
<li><a href="#">
<i class='bx bxl-java' ></i>
<span class="link_name">Java Swing GUIs</span>
<span class="tooltip">Java Swing</span></a>
</li>
<li><a href="#">
<i class='bx bx-transfer'></i>
<span class="link_name">API Integration</span>
<span class="tooltip">API Integration</span></a>
</li>
<li><a href="#">
<i class='bx bx-data' ></i>
<span class="link_name">Data Visualization</span>
<span class="tooltip">Data Visualization</span></a>
</li>
<li><a href="#">
<i class='bx bx-landscape'></i>
<span class="link_name">Graphic Design</span>
<span class="tooltip">Graphic Design</span></a>
</li>
<li><a href="#">
<i class='bx bx-mail-send'></i>
<span class="link_name">Contact</span>
<span class="tooltip">Contact</span></a>
</li>
</ul>
<div class="profile_content">
<div class="profile">
<div class="profile_details">
<img src="images/small-mugshot.jpg" alt="profileImage">
<div class="name_job">
<div class="name">Diana Ramirez</div>
<div class="job">Software Engineer</div>
</div>
</div>
</div>
</div>
<!--section class="home-section">
<div class="home-content">
<i class="bx bx-menu"></i>
<span class="text">Drop Down Sidebar</span>
</div>
</section-->
<!--div class="cancel_btn">
<i class="fas fa-times"></i>
</div>
<div class="media_icons">
<i class="fab fa-facebook-f"></i>
<i class="fab fa-twitter"></i>
<i class="fab fa-instagram"></i>
</div>
<div class="menu_btn">
<i class="fas fa-bars"></i>
</div-->
</div>
testingtestingtestingtestingtestingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtestingtestingtesting
testingtestingtestingtesting
testingtesting
testingtestingtestingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtestingtestingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
testingtesting
<!--div class="container">
<header>
<div class="headerBox">
<h1>Web Portfolio</h1>
<h2>web portfolio test</h2>
<h3>web portfolio test</h3>
</div>
</header>
</div>
<footer>
<div class="footer-text">
<p id="footnote">Content copyright 2022</p>
</div>
</footer-->
<script src="js/script.js"></script>
</body>
</html>

How to increase the click area of ​the element without changing the width

I'm creating a menu and I came across a problem in css that I haven't thought of how to fix.
There is a problem in the click area due to the width of the element a
code:
function OpenMenu(el) {
$(".nav li a").removeClass("active");
$(el).addClass("active");
}
.bar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 200px;
background: darkgray;
transition: all 0.5s ease;
}
.bar ul {
margin-top: 20px;
}
.bar ul li {
position: relative;
height: 45px;
width: 90%;
margin-bottom: 20px;
list-style: none;
text-transform: uppercase;
font-weight: 500;
border-radius: 3px;
background: gray;
}
.bar ul li a {
color: white;
display: flex;
align-items: center;
text-decoration: none;
background: red;
width: 3px;
height: 100%;
border-radius: 3px;
transition: all 0.4s cubic-bezier(0.98, 0.04, 0.25, 1);
}
.bar ul li a:hover {
color: white;
width: 100%;
}
.bar ul li a.active {
color: white;
background: red;
width: 230px;
}
.bar ul li i {
font-size: 18px;
height: 50px;
min-width: 50px;
line-height: 50px;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" />
<div class="bar">
<ul class="nav">
<li>
<a href="#" class="active" onclick="OpenMenu(this)">
<i class="fas fa-adjust"></i>
<span>Test1</span>
</a>
</li>
<li>
<a href="#" onclick="OpenMenu(this)">
<i class="fas fa-adjust"></i>
<span>Test2</span>
</a>
</li>
</ul>
</div>
problem picture:
The problem is because of the .bar ul li a, having a width of 3px.
I did a test using 100% width and it works correctly.
What should I do to allow the click in the circle area and keep the width at 3px?
You are selecting a tag which is not full width, that's why you are getting this strange artefact. Instead, you can check for hover on parent element li and still select a, like so:
function OpenMenu(el) {
$(".nav li").removeClass("active");
$(el).addClass("active");
}
.bar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 200px;
background: darkgray;
transition: all 0.5s ease;
}
.bar ul {
margin-top: 20px;
}
.bar ul li {
position: relative;
height: 45px;
width: 90%;
margin-bottom: 20px;
list-style: none;
text-transform: uppercase;
font-weight: 500;
border-radius: 3px;
background: gray;
cursor: pointer;
}
.bar ul li a {
color: white;
display: flex;
align-items: center;
text-decoration: none;
background: red;
width: 3px;
height: 100%;
border-radius: 3px;
transition: all 0.4s cubic-bezier(0.98, 0.04, 0.25, 1);
}
/* Move `:hover` from `a` to `li` */
.bar ul li:hover a {
color: white;
width: 100%;
}
.bar ul li.active a {
color: white;
background: red;
width: 230px;
}
.bar ul li i {
font-size: 18px;
height: 50px;
min-width: 50px;
line-height: 50px;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" />
<div class="bar">
<ul class="nav">
<li onclick="OpenMenu(this)">
<a href="#" class="active">
<i class="fas fa-adjust"></i>
<span>Test1</span>
</a>
</li>
<li onclick="OpenMenu(this)">
<a href="#">
<i class="fas fa-adjust"></i>
<span>Test2</span>
</a>
</li>
</ul>
</div>

The :checked selector doesn't work beside working on the tutorial

I'm using this tutorial, and beside some id/class name, I did exactly the same as the tutorial, but i still can't make the checked work.
I didn't get through the entire tutorial.
I tested both codes (code I tested with : here), but it looks like the problem isn't coming from the checkbox.
Here's the HTML :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
<title>Test Sidebar</title>
</head>
<body>
<input type="checkbox" id="check">
<header>
<label for="check">
<i class="fas fa-bars" id="sidebarBtn"></i>
</label>
<div class="leftArea">
<h3>Side <span>Bar</span></h3>
</div>
<div class="rightArea">
Logout
</div>
<div class="sidebar">
<center>
<img src="pic.jpg" class="profileImage" alt="">
<h4>Amanda</h4>
</center>
<i class="fas fa-desktop"></i><span>Dashboard</span>
<i class="fas fa-cogs"></i><span>Components</span>
<i class="fas fa-table"></i><span>Tables</span>
<i class="fas fa-th"></i><span>Forms</span>
<i class="fas fa-info-circle"></i><span>About</span>
<i class="fas fa-sliders-h"></i><span>Settings</span>
</div>
</header>
</body>
</html>
Here's the CSS :
body {
margin: 0;
padding: 0;
font-family: "Roboto", sans-serif;
}
header {
position: fixed;
background: #22242A;
padding: 20px;
width: 100%;
height: 30px;
}
.leftArea h3 {
color: #fff;
margin: 0;
text-transform: uppercase;
font-size: 22px;
font-weight: 900;
}
.leftArea span {
color: #1DC4E7;
}
.logoutBtn {
padding: 5px;
background: #19B3D3;
text-decoration: none;
float: right;
margin-top: -30px;
margin-right: 40px;
border-radius: 2px;
font-size: 15px;
font-weight: 600;
color: #fff;
transition: 0.5s;
transition-property: background;
}
.logoutBtn:hover {
background: #0D9DBB;
}
.sidebar {
background: #2F323A;
margin-top: 22px;
/* margin-top: 70px - n'as pas l'air de fonctionner */
padding-top: 30px;
position: fixed;
left: 0;
width: 250px;
height: 100%
}
.sidebar .profileImage {
width: 100px;
height: 100px;
border-radius: 100px;
margin-bottom: 10px;
}
.sidebar h4 {
color: #ccc;
margin-top: 0;
margin-bottom: 20px;
}
.sidebar a {
color: #fff;
display: block;
width: 100%;
line-height: 60px;
text-decoration: none;
padding-left: 40px;
box-sizing: border-box;
transition: 0.5s;
transition-property: background;
}
.sidebar a:hover {
background: #19B3D3;
}
.sidebar i {
padding-right: 10px;
}
label #sidebarBtn {
z-index: 1;
color: #fff;
position: fixed;
cursor: pointer;
left: 300px;
font-size: 20px;
margin: 5px 0;
transition: 0.5s;
transition-property: color;
}
label #sidebarBtn:hover {
color: #19B3D3;
}
#check:checked ~ .sidebar {
left: -190px;
}
Place an <input type="checkbox" id="check"> inside your head tag, but above the line <label for="check">.
body {
margin: 0;
padding: 0;
font-family: "Roboto", sans-serif;
}
header {
position: fixed;
background: #22242A;
padding: 20px;
width: 100%;
height: 30px;
}
.leftArea h3 {
color: #fff;
margin: 0;
text-transform: uppercase;
font-size: 22px;
font-weight: 900;
}
.leftArea span {
color: #1DC4E7;
}
.logoutBtn {
padding: 5px;
background: #19B3D3;
text-decoration: none;
float: right;
margin-top: -30px;
margin-right: 40px;
border-radius: 2px;
font-size: 15px;
font-weight: 600;
color: #fff;
transition: 0.5s;
transition-property: background;
}
.logoutBtn:hover {
background: #0D9DBB;
}
.sidebar {
background: #2F323A;
margin-top: 22px;
/* margin-top: 70px - n'as pas l'air de fonctionner */
padding-top: 30px;
position: fixed;
left: 0;
width: 250px;
height: 100%
}
.sidebar .profileImage {
width: 100px;
height: 100px;
border-radius: 100px;
margin-bottom: 10px;
}
.sidebar h4 {
color: #ccc;
margin-top: 0;
margin-bottom: 20px;
}
.sidebar a {
color: #fff;
display: block;
width: 100%;
line-height: 60px;
text-decoration: none;
padding-left: 40px;
box-sizing: border-box;
transition: 0.5s;
transition-property: background;
}
.sidebar a:hover {
background: #19B3D3;
}
.sidebar i {
padding-right: 10px;
}
label #sidebarBtn {
z-index: 1;
color: #fff;
position: fixed;
cursor: pointer;
left: 300px;
font-size: 20px;
margin: 5px 0;
transition: 0.5s;
transition-property: color;
}
label #sidebarBtn:hover {
color: #19B3D3;
}
#check:checked ~ .sidebar {
left: -190px;
}
<body>
<header>
<input type="checkbox" id="check">
<label for="check">
<i class="fas fa-bars" id="sidebarBtn"></i>
</label>
<div class="leftArea">
<h3>Side <span>Bar</span></h3>
</div>
<div class="rightArea">
Logout
</div>
<div class="sidebar">
<center>
<img src="pic.jpg" class="profileImage" alt="">
<h4>Amanda</h4>
</center>
<i class="fas fa-desktop"></i><span>Dashboard</span>
<i class="fas fa-cogs"></i><span>Components</span>
<i class="fas fa-table"></i><span>Tables</span>
<i class="fas fa-th"></i><span>Forms</span>
<i class="fas fa-info-circle"></i><span>About</span>
<i class="fas fa-sliders-h"></i><span>Settings</span>
</div>
</header>
</body>
Ok, i just understood where i messed up. The tag should close after the rightArea class.
<header>
<label for="check">
<i class="fas fa-bars" id="sidebarBtn"></i>
</label>
<div class="leftArea">
<h3>Side <span>Bar</span></h3>
</div>
<div class="rightArea">
Logout
</div>
</header>
This way, i can have my input BEFORE my header, and it would works. I think it's because now, the sidebar isn't in the header anymore. That was pretty dumb on my part, sorry, and thank you for helping me out there.

How to make icon and `a` in one line

So, I used sidebar menu in my web. At the first, this sidebar just has 100px, and when I hover the mouse to it, it will shows up all the sidebar. this is the image, before and after hover:
My HTML code:
.sidenav {
height: 100%;
width: 100px;
position: fixed;
z-index: 2;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.8s;
}
.sidenav:hover{
width: 250px;
transition: 0.8s;
}
.sidenav a {
float:left;
width:100%;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
opacity: 0;
transition: opacity 1300ms
}
.sidenav:hover a {
opacity: 1
}
.icon{
display: block;
position: relative;
left: 50%;
top: 50%;
width: 15px;
height: 15px;
float: left;
border-radius: 50%;
border: 1px solid red;
border-top-color: transparent;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
<body>
<div id="mySidenav" class="sidenav"> <!-- CSSnya di 2691 -->
<br><br>
Home
Menu 1
Menu 2
Menu 3
Menu 4
Menu 5
</div>
</body>
all my link menu is hidden when sidebar is not hover, and will appear when hovered. My question is how to just display icons when sidebar is not hover, and display all when its hover, where I use this class:
so its still shows when sidebar not hover and still in one line with the link menu? thanks
You can use FontAwesome for the icons. Hope it helped.
.sidenav a {
float: left;
width: 250px;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 16px;
display: block;
line-height: 37px;
color: transparent;
transition: 1300ms;
height: 30px;
font-family: arial;
letter-spacing: 1px;
text-transform: uppercase;
}
i {
display: block;
position: relative;
width: 15px;
height: 15px;
float: left;
border-radius: 50px;
border: 1px solid red;
padding: 10px;
text-align: center;
line-height: 15px !important;
color: #fff;
opacity: 1;
margin-right: 10px;
font-size: 15px !important;
}
.sidenav {
width: 100px;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 60px;
transition: 0.8s;
}
.sidenav:hover {
width: 250px;
overflow: hidden;
transition: 0.8s;
}
.sidenav:hover a {
color: #fff;
}
<script src="https://use.fontawesome.com/7a90a673fc.js"></script>
<div id="mySidenav" class="sidenav">
<br><br>
<i class="fa fa-bars"></i> Home
<i class="fa fa-comment"></i> Menu 1
<i class="fa fa-users"></i> Menu 2
<i class="fa fa-thumbs-up"></i> Menu 3
<i class="fa fa-facebook"></i> Menu 4
<i class="fa fa-close"></i> Menu 5
</div>
.sidenav {
height: 100%;
width: 250px;
position: fixed;
z-index: 2;
top: 0;
left: 0;
background-color: #111;
overflow: hidden;
padding-top: 60px;
transition: 0.8s;
transform: translatex(-150px);
}
.sidenav:hover {
transition: 0.8s;
transform: translatex(0);
}
.sidenav a {
display: block;
width: 150px;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 20px;
color: #818181;
transition: opacity 1300ms;
position: relative;
}
.sidenav a::after {
content: '';
display: block;
position: absolute;
right: -16px;
top: calc(50% - 8px);
width: 15px;
height: 15px;
border-radius: 50%;
border: 1px solid red;
border-top-color: transparent;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
<div id="mySidenav" class="sidenav">
<!-- CSSnya di 2691 -->
<br>
<br>
Home
Menu 1
Menu 2
Menu 3
Menu 4
Menu 5
</div>