Highlight active menu item with CSS only - html

I have a topnav menu that works fine, I just want to keep the underline that appears on the hover event to stay there if that menu item is active. I have tried many solutions I found on the forum, but somehow none did not work. Any help is appreciated.
and here are the html and css snippets:
body {
margin: auto;
}
.topnavbar {
background-color: rgba(20, 180, 255, 1);
/*rgba(0,255,150,0.6); #3EDC99*/
-webkit-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
-moz-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
}
.nav {
padding: 5px 5px 5px 5px;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background-color: rgba(245, 245, 245, 1)/*#3498db; */
}
.nav {
width: 550px;
margin: 0 auto 0 auto;
text-align: center;
}
/* Navigation */
.nav {
font-family: Verdana, Georgia, Arial, sans-serif;
font-size: 14px;
}
.nav-items {
padding: 0;
list-style: none;
}
/* color of menu links
span {
color:yellow;
}
*/
.nav-item {
display: inline-block;
margin-right: 25px;
}
.nav-item:last-child {
margin-right: 0;
}
.nav-link,
.nav-link:link,
.nav-link:visited,
.nav-link:active,
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
display: block;
position: relative;
font-size: 14px;
letter-spacing: 1px;
cursor: pointer;
text-decoration: none;
outline: none;
color: blue;
}
.nav-link::before {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.2);
opacity: 0;
-webkit-transform: translate(0, 10px);
transform: translate(0, 10px);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.nav-link:hover::before,
.nav-link:hover::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
.dropdown {
position: relative;
}
.dropdown .nav-link {
padding-right: 15px;
height: 17px;
line-height: 17px;
}
.dropdown .nav-link::after {
content: "";
position: absolute;
top: 6px;
right: 0;
border: 5px solid transparent;
border-top-color: blue;
/*small triangle showing drop down menu*/
}
.submenu {
position: absolute;
top: 100%;
left: 50%;
z-index: 100;
width: 200px;
margin-left: -100px;
background: blue;
border-radius: 3px;
line-height: 1.46667;
margin-top: -5px;
box-shadow: 0 0 8px rgba(0, 0, 0, .3);
opacity: 0;
-webkit-transform: translate(0, 0) scale(.85);
transform: translate(0, 0)scale(.85);
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
pointer-events: none;
}
.submenu::after,
.submenu::before {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -10px;
border: 10px solid transparent;
height: 0;
}
.submenu::after {
border-bottom-color: blue;
}
.submenu::before {
margin-left: -13px;
border: 13px solid transparent;
border-bottom-color: rgba(0, 0, 0, .1);
-webkit-filter: blur(1px);
filter: blur(1px);
}
.submenu-items {
list-style: none;
padding: 10px 0;
}
.submenu-item {
display: block;
text-align: left;
}
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
color: #3498db;
padding: 10px 20px;
}
.submenu-link:hover {
text-decoration: underline;
}
.submenu-seperator {
height: 0;
margin: 12px 10px;
border-top: 1px solid #eee;
}
.show-submenu .submenu {
opacity: 1;
-webkit-transform: translate(0, 25px) scale(1);
transform: translate(0, 25px) scale(1);
pointer-events: auto;
}
.submenu-link {
color: red;
}
<link rel="stylesheet" type="text/css" href="{% static 'css/_topnavbar.css' %}">
<!--Top Navigation-->
<nav role="navigation" class="nav" id="topnav">
<ul class="nav-items">
<li class="nav-item">
<span>Home</span>
</li>
<li class="nav-item ">
<span>Media</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">Product #1</li>
<li class="submenu-item">Product #2</li>
<li class="submenu-item">Product #3</li>
</ul>
</nav>
</li>
<li class="nav-item">
<span>Search</span>
</li>
<li class="nav-item">
<span>Report</span>
</li>
<li class="nav-item dropdown">
<span>More</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">About</li>
<li class="submenu-item">Contact</li>
<li class="submenu-item">
<hr class="submenu-seperator" />
</li>
<li class="submenu-item">Support</li>
<li class="submenu-item">FAQs</li>
</ul>
</nav>
</li>
</ul>
</nav>
<script type='text/javascript' src="{% static 'js/_topnavbar.js' %}"></script>
I use js to open the drop down menu items, but I don't think it was necessary to make the post more extended than it is now.

You can create a new class e.g. .is-active. On the home page you can add this class to the home link in your navigation, like this:
<li class="nav-item">
<span>Home</span>
</li>
In your CSS you style the is-active class the same way as the :hover.
On each new page of your site, in the HTML, change the location of the .is-active class to the appropriate page. If your website is much bigger or more complicated, you can do this programmatically instead.
Basic example:
body {
margin: auto;
}
.topnavbar {
background-color: rgba(20, 180, 255, 1);
/*rgba(0,255,150,0.6); #3EDC99*/
-webkit-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
-moz-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
}
.nav {
padding: 5px 5px 5px 5px;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background-color: rgba(245, 245, 245, 1)/*#3498db; */
}
.nav {
width: 550px;
margin: 0 auto 0 auto;
text-align: center;
}
/* Navigation */
.nav {
font-family: Verdana, Georgia, Arial, sans-serif;
font-size: 14px;
}
.nav-items {
padding: 0;
list-style: none;
}
/* color of menu links
span {
color:yellow;
}
*/
.nav-item {
display: inline-block;
margin-right: 25px;
}
.nav-item:last-child {
margin-right: 0;
}
.nav-link,
.nav-link:link,
.nav-link:visited,
.nav-link:active,
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
display: block;
position: relative;
font-size: 14px;
letter-spacing: 1px;
cursor: pointer;
text-decoration: none;
outline: none;
color: blue;
}
.nav-link::before {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.2);
opacity: 0;
-webkit-transform: translate(0, 10px);
transform: translate(0, 10px);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.nav-link:hover::before,
.nav-link:focus::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
.dropdown {
position: relative;
}
.dropdown .nav-link {
padding-right: 15px;
height: 17px;
line-height: 17px;
}
.dropdown .nav-link::after {
content: "";
position: absolute;
top: 6px;
right: 0;
border: 5px solid transparent;
border-top-color: blue;
/*small triangle showing drop down menu*/
}
.submenu {
position: absolute;
top: 100%;
left: 50%;
z-index: 100;
width: 200px;
margin-left: -100px;
background: blue;
border-radius: 3px;
line-height: 1.46667;
margin-top: -5px;
box-shadow: 0 0 8px rgba(0, 0, 0, .3);
opacity: 0;
-webkit-transform: translate(0, 0) scale(.85);
transform: translate(0, 0)scale(.85);
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
pointer-events: none;
}
.submenu::after,
.submenu::before {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -10px;
border: 10px solid transparent;
height: 0;
}
.submenu::after {
border-bottom-color: blue;
}
.submenu::before {
margin-left: -13px;
border: 13px solid transparent;
border-bottom-color: rgba(0, 0, 0, .1);
-webkit-filter: blur(1px);
filter: blur(1px);
}
.submenu-items {
list-style: none;
padding: 10px 0;
}
.submenu-item {
display: block;
text-align: left;
}
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
color: #3498db;
padding: 10px 20px;
}
.submenu-link:hover {
text-decoration: underline;
}
.submenu-seperator {
height: 0;
margin: 12px 10px;
border-top: 1px solid #eee;
}
.show-submenu .submenu {
opacity: 1;
-webkit-transform: translate(0, 25px) scale(1);
transform: translate(0, 25px) scale(1);
pointer-events: auto;
}
.submenu-link {
color: red;
}
.nav-link.is-active::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
<link rel="stylesheet" type="text/css" href="{% static 'css/_topnavbar.css' %}">
<!--Top Navigation-->
<nav role="navigation" class="nav" id="topnav">
<ul class="nav-items">
<li class="nav-item">
<span>Home</span>
</li>
<li class="nav-item ">
<span>Media</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">Product #1</li>
<li class="submenu-item">Product #2</li>
<li class="submenu-item">Product #3</li>
</ul>
</nav>
</li>
<li class="nav-item">
<span>Search</span>
</li>
<li class="nav-item">
<span>Report</span>
</li>
<li class="nav-item dropdown">
<span>More</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">About</li>
<li class="submenu-item">Contact</li>
<li class="submenu-item">
<hr class="submenu-seperator" />
</li>
<li class="submenu-item">Support</li>
<li class="submenu-item">FAQs</li>
</ul>
</nav>
</li>
</ul>
</nav>
<script type='text/javascript' src="{% static 'js/_topnavbar.js' %}"></script>

For as far as I'm concerned, what you are trying to achieve is possible with JS or adding a class to the element. But since you want only CSS, I don't think that's possible.
For if you changed your mind, this is how to do it with adding a class: How to give a different color to the current selected list item than other items in html?
For JavaScript/jQuery, I guess you could just add this:
<script>
$('.nav-items li a').click(function(event){
event.preventDefault();
$('.nav-items li a').removeClass('active')
$(this).addClass('active');
});
</script>
EDIT: This is more like what you need:
<script>
var page = window.location.pathname;
var elements = document.getElementsByClassname("nav-link");
if (page == "/index/"){
elements[0].style.textDecoration="underline";
}
</script>

Related

How to display a boxed navigation bar when I hover over parent navigation bar?

The objective here is to display the boxed nav bars vertically when I hover over one of horizontal parent nav bars. When I stop hovering over this bar, that boxed child nav bar should disappear. The detailed HTML and CSS codes are as follows:
a {
background-color: transparent;
}
a {
background-color: transparent;
box-sizing: border-box;
color: #3197d6;
cursor: pointer;
text-decoration: none;
transition: none;
}
a:hover {
text-decoration: underline;
}
a:hover
{
color: #71bff1;
outline-width: 0;
}
a:hover {
opacity: 1;
transform: translate3d(-50%, -80%, 0);
}
.z-nav-list {
margin: 0 auto;
list-style-type: none;
padding: 0;
overflow: hidden;
max-width: 90%;
}
#media (min-width:1600px)
{
.z-nav-list
{
max-width: 1600px;
}
}
#media (min-width:768px)
{
.z-nav-list_item+.z-nav-list_item
{
margin-left: 10px;
}
}
.z-nav-list_item {
float: left;
}
.z-nav-list_link {
display: block;
color: #232320;
font-size: 1.1em;
padding: 1.5em 0.75em;
transition: color .2s linear;
position: relative;
text-decoration: none;
}
#media (min-width:1100px) {
.z-nav-list_link {
padding: 1.5em 2em;
}
}
.z-nav-list_link--project {
padding-left: 0;
}
.z-nav-list_link--project span {
position: relative;
z-index: 10;
}
.z-nav-list_link--project span:before {
z-index: 5;
content: "";
width: 100%;
position: absolute;
bottom: -10px;
height: 3px;
left: 0;
display: block;
background: #ffc4ff;
transform: translate3d(0, 5px, 0);
transition: all .2s cubic-bezier(.175, .885, .32, 1.275);
opacity: 0;
}
.z-nav-list_link--project:hover span:before {
opacity: 1;
transform: translateZ(0) scale3d(1.1, 1.1, 1.1) rotate(-2deg);
}
.z-nav.show-project .z-nav_project,
.z-nav .project-is-visible
{
opacity: 1;
pointer-events: all;
transform: translateZ(0);
}
.z-nav_project
{
pointer-events: none;
opacity: 0; /*0: transparent */
transition: all 0.2s cubic-bezier(.175, .885, .32, 1.275);
transform: translate3d(0, 15px, 0);
position: absolute;
left: 0;
top: 65px;
z-index: 10000; /*this element is always on the top */
display: none; /* remove all the elements */
/* transform: translateZ(0);*/
}
#media (min-width:992px)
{
.z-nav_project
{
display: inline-block;
}
}
.z-nav_project-list
{
list-style-type: none;
margin: 0;
padding: 1.5em 2em 2em;
background: #232320;
box-shadow: 0 4px 4px rgba(0, 0, 0, .06), 0 19px 20px rgba(0, 0, 0, .15);
border-radius: 20px;
min-width: 15em;
}
.z-nav_project-list-item+.z-nav_project-list-item {
margin-top: .5em;
}
.z-nav_project-list-item-link {
padding: .6em 0;
color: #fff;
font-size: 18px;
position: relative;
display: inline-block;
}
.z-nav_project-list-item-link span {
position: relative;
z-index: 10;
}
.z-nav_project-list-item-link:before {
z-index: 5;
content: "";
width: 100%;
position: absolute;
bottom: 3px;
height: 3px;
left: 0;
display: block;
background: #ffc4ff;
transform: rotate(-1deg);
transition: all .2s cubic-bezier(.175, .885, .32, 1.275);
}
.z-nav_project-list-item-link:after {
z-index: 1;
content: "";
height: 100%;
width: 180%;
position: absolute;
left: 0;
display: block;
top: 0;
}
.z-nav_project-list-item-link:hover {
text-decoration: none;
color: #ffc4ff;
}
.z-nav_project-list-item-link:hover:before {
transform: scale3d(1.2, 1.2, 1.2);
}
.z-nav_project-list-item-link:active:before {
transform: scale3d(1.1, 1.1, 1.1);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header class="z-nav">
<nav class="z-nav">
<ul class="z-nav-list c-nav-list--info">
<li class="z-nav-list_item z-nav-list_item--project">
<a class="z-nav-list_link z-nav-list_link--project" href="#"><span>Project</span></a>
</li>
<li class="z-nav-list_item z-nav-list_item--about">
<a class="z-nav-list_link z-nav-list_link--about" href="/about"><span>About</span></a>
</li>
</ul>
<div class="z-nav_project">
<ul class="z-nav_project-list">
<li class="z-nav_project-list-item">
<span>Project1</span>
</li>
<li class="z-nav_project-list-item">
<span>Project2</span>
</li>
<li class="z-nav_project-list-item">
<span>Project3</span>
</li>
</ul>
</div>
</nav>
</header>
</body>
</html>
If I hover over the horizontal leftmost bar "Project", it should display a vertical nav bar like the following picture. However, my code can not meet this functionality. Can someone help me out? Basically, I want to use CSS opacity property to turn on/off the vertical nav bar. but it does not work. How can I improve this code? Thanks in advance.

Hamburger menu goes under text and image

I have tried to add a hamburger menu to my web page but it keeps going under the images and texts. I changed the z-index with different numbers but it still doesn't work.the menu it self has no problem and works somoothly but when I shrink the page, the images and the texts are on the menu if anyone knows please give a suggestion. Thank you
#menu__toggle {
opacity: 0;
}
#menu__toggle:checked+.menu__btn>span {
transform: rotate(45deg);
}
#menu__toggle:checked+.menu__btn>span::before {
top: 0;
transform: rotate(0deg);
}
#menu__toggle:checked+.menu__btn>span::after {
top: 0;
transform: rotate(90deg);
}
#menu__toggle:checked~.menu__box {
left: 0 !important;
}
.menu__btn {
position: absolute;
top: 20px;
left: 20px;
width: 26px;
height: 26px;
cursor: pointer;
z-index: 1000;
}
.menu__btn>span,
.menu__btn>span::before,
.menu__btn>span::after {
display: block;
position: absolute;
width: 100%;
height: 2px;
background-color: #08ebfc;
transition-duration: .25s;
}
.menu__btn>span::before {
content: '';
top: -8px;
}
.menu__btn>span::after {
content: '';
top: 8px;
}
.menu__box {
display: block;
position: absolute;
top: 0;
left: -100%;
width: 300px;
height: 100%;
margin: 0;
padding: 80px 0;
list-style: none;
background-color: #ECEFF1;
box-shadow: 2px 2px 6px rgba(0, 0, 0, .4);
transition-duration: .25s;
}
.menu__item {
display: block;
padding: 12px 24px;
color: #333;
font-family: 'Roboto', sans-serif;
font-size: 20px;
font-weight: 600;
text-decoration: none;
transition-duration: .25s;
}
.menu__item:hover {
background-color: #CFD8DC;
}
<div class="bg">
<div class="hamburger-menu">
<!--this is the part for the menu-->
<input id="menu__toggle" type="checkbox" />
<label class="menu__btn" for="menu__toggle">
<span></span>
</label>
<ul class="menu__box">
<li><a class="menu__item" href="#">Home</a></li>
<li><a class="menu__item" href="#">About</a></li>
<li><a class="menu__item" href="#">Team</a></li>
<li><a class="menu__item" href="#">Contact</a></li>
<li><a class="menu__item" href="#">Twitter</a></li>
</ul>
</div>
<h1 class="neonText" style="text-align:center; padding:3% auto 1% auto;">TRANSFORMERS</h1>
<div class="container">
<img src="dece.jpg" alt="Decepticon logo" style="width:100%;">
<h1 class="h1-d">DECEPTICONS</h1>
<div class="content">
</div>
</div>
For me, it goes up the image and text, there might be interfernce with some other css codes.

Can you extend a list when a list or button inside the list is pressed? CSS

So I'm pretty new to programming especially CSS, HTML, Javascript, etc. I made an Info Test website for myself and I made the following list, in which I have sub Topics, each subtopic is a list as well. My Problem now is that I shortened the first list so that every subpoint fits in perfectly, but when I extend the Subtopic lists, the list in which the subtopics are don't extend, and some of the text in the sublists get cut off. My question now is if I can extend the top list so that when I extend the sublists my text won't get cut off, but I only want the list to be extended when the sublists are opened. Is that possible in CSS?
CSS and HTML
body {
background-color: #212121;
color: #fff;
font-family: arial;
font-size: 32px;
cursor: default;
}
.romanOne {
font-family: timesnewroman;
float: right;
margin-right: 15px;
width: 590px;
height: 64px;
text-align: left;
}
.romanTwo {
font-family: timesnewroman;
float: right;
margin-right: 15px;
width: 590px;
height: auto;
}
.romanThree {
font-family: timesnewroman;
float: right;
margin-right: 15px;
width: 590px;
height: auto;
}
.FontFormatHeading {
text-align: center;
font-size: 52px;
}
.FontFormat {
position: relative;
width: 700px;
margin: -20px auto 0px;
padding: 20px;
box-sizing: border-box;
list-style: none;
background: rgba(0, 0, 0, .2);
border-radius: 20px;
box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.5);
}
.FontFormat li {
display: flex;
background-color: rgba(255, 255, 255, 0.1);
padding: 10px 20px;
margin: 5px 0;
transition: .5s;
border-radius: 20px;
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}
.FontFormat li:nth-child(1) {
background-color: rgba(201, 201, 201, 0.4);
}
.FontFormat li:nth-child(2) {
background-color: rgba(201, 201, 201, 0.3);
}
.FontFormat li:hover {
transform: scale(1.05);
background: #212121;
}
.AttributeHeading {
font-size: 52px;
text-align: center;
}
.AttributeFormat {
position: relative;
width: 700px;
margin: -20px auto 0px;
padding: 20px;
box-sizing: border-box;
list-style: none;
background: rgba(0, 0, 0, .2);
border-radius: 20px;
box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.5);
}
.AttributeFormat li {
display: flex;
background-color: rgba(255, 255, 255, 0.1);
padding: 10px 20px;
margin: 5px 0;
transition: .5s;
border-radius: 20px;
box-shadow: inset 0 0 10px rgba(0, 0, 0, 1);
}
.AttributeFormat li:nth-child(1) {
background-color: rgba(201, 201, 201, 0.4);
}
.AttributeFormat li:nth-child(2) {
background-color: rgba(201, 201, 201, 0.3);
}
.AttributeFormat .AttributeList:hover {
transform: scale(1.04);
text-decoration: underline;
}
.AttributeSubList:hover {
transform: scale(1.04);
}
.StyleOne {
margin-left: 128px;
}
#StyleOneHeading {
font-family: Arial;
float: right;
list-style: none;
cursor: pointer;
}
.StyleOneJS:not([open]) {
height: 37px;
}
.StyleOneJS[open] {
height: 76px;
}
.StyleTwo {
margin-left: 110px;
padding-right: 100px;
}
#StyleTwoHeading {
font-family: Arial;
float: right;
list-style: none;
cursor: pointer;
}
.StyleTwo details:not([open]) {
height: 37px;
}
.StyleTwo details[open] {
height: 76px;
}
details {
transition: height 0.4s ease;
overflow: hidden;
}
.DropDown1>summary {
list-style: none;
margin-left: 274px;
cursor: pointer;
}
.DropDown1:not([open]) {
height: 37px;
}
.DropDown1[open] {
height: 250px;
}
<!DOCTYPE html>
<html lang="de" dir="ltr">
<head>
<meta charset="utf-8">
<title>First Web Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p class="AttributeHeading">Attribute</p>
<div>
<ul class="AttributeFormat">
<!-- Style Attribute-->
<li class="AttributeList">
<details class="DropDown1" open>
<summary>Style</summary>
<ul class="romanOne">
<li class="AttributeSubList">
<div class="StyleOne">
<details class="StyleOneJS">
<summary id="StyleOneHeading">Text größe wechseln</summary>
<br>
<div style="text-align: center;">
<span style=color:orange;>style</span>
<span>=</span>
<span style=color:limegreen;>font-size:32px</span>
</div>
</details>
</div>
</li>
<li class="AttributeSubList">
<div class="StyleTwo">
<details>
<summary id="StyleTwoHeading"> Text schriftart wechseln</summary>
<br>
<div style="text-align: center;">
<span style=color:orange;>style</span>
<span>=</span>
<span style=color:limegreen;>font-family:arial</span>
</div>
</details>
</div>
</li>
<li class="AttributeSubList">
<span style=font-family:arial;>Filler Text</span>
</li>
</ul>
</details>
</li>
<li class="AttributeList">
<details class="DropDown2">
<summary>Filler Categories</summary>
<ul class="romanTwo">
<li class="AttributeSubList">
<span style=font-family:arial>Filler Text</span>
</li>
</ul>
</details>
</li>
<li class="AttributeList">
<details class="DropDown3">
<summary>Filler Categories</summary>
<ul class="romanThree">
<li>
<span style=font-family:arial>Filler Text</span>
</li>
</ul>
</details>
</li>
</ul>
</div>
</body>
</html>

make icon appear below li name

How can I make the icon ion-edit appear below the list name .
for ex icon should appear below the names Oracl,PostgresSql,Mysql and then the border bottom line should come.
In my case its appearing at the right side of each list names.I want it below the list names with some gap.
on click of Data Source Connections the sublist will be shown there the pencil icon has to be aligned below each name.
Is there any css property to be included?
$('.src-sub-menu').click(function() {
$(this).toggleClass('submenu-open').parent('li').siblings('li').children('h4.submenu-open').removeClass('submenu-open');
$(this).parent().toggleClass('submenu-opensubmenu-open').children('ul').slideToggle(500).end().siblings('.submenu-open').removeClass('submenu-open').children('ul').slideUp(500);
$('html, body').animate({
scrollTop: (0),
}, "fast"); /*this will scroll upto the top, not sure if I want to use this yet */
});
.whole-dbsource {
height: 100%;
}
.db-pagerow {
margin-left: 12%;
justify-content: center;
height: 80%;
}
.source-container {
height: 300px; /* ED: Changed to see the dropdown */
border-radius: 10px;
background-color: white;
overflow: scroll;
position: relative;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.16), 0 1px 4px rgba(0, 0, 0, 0.26);
}
h5 {
padding: 10px;
margin: 0;
}
h5.submenu-open {
padding: 10px;
color: white;
background-color: #28be9a;
}
ul.src-main-menu {
position: relative;
list-style-type: none;
height: 12px;
}
ul.src-main-menu .src-main-sub {
margin: 20px 0;
}
ul.src-main-menu li.src-main-sub {
padding: 1px 0px;
cursor: pointer;
background-color: #e0e0e0;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
ul.src-main-menu li ul {
list-style-type: none;
color: black;
display: none;
position: relative;
max-height: 1000px;
/*fallback for FireFox */
height: 100%;
}
ul.src-main-menu li ul i {
display: inline-block;
}
.src-main-sub ul li {
border-bottom: 1px solid black;
margin: 20px 0;
}
.src-main-sub ul li:last-child {
border-bottom: none;
margin: 0;
}
ul.src-main-menu li ul.open {
display: block;
}
ul.src-main-menu .src-main-sub i {
transition: all 0.5s;
position: absolute;
right: 10px;
}
ul.src-main-menu li i.closed {
transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
}
ul.src-main-menu li i.open {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"/>
<div class="container-fluid whole-dbsource">
<div class="row db-pagerow">
<div class="col-sm-7 source-container">
<ul class="src-main-menu">
<li class="src-main-sub">
<h5 class="src-sub-menu">Data Source Connections<i class="ion-chevron-down closed"></i></h5>
<ul class="closed">
<li>Oracle 12c<i class="ion-edit"></i></li>
<li>PostgresSQL<i class="ion-edit"></i></li>
<li>MySql<i class="ion-edit"></i></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
$('.src-sub-menu').click(function() {
$(this).toggleClass('submenu-open').parent('li').siblings('li').children('h4.submenu-open').removeClass('submenu-open');
$(this).parent().toggleClass('submenu-opensubmenu-open').children('ul').slideToggle(500).end().siblings('.submenu-open').removeClass('submenu-open').children('ul').slideUp(500);
$('html, body').animate({
scrollTop: (0),
}, "fast"); /*this will scroll upto the top, not sure if I want to use this yet */
});
.whole-dbsource {
height: 100%;
}
.db-pagerow {
margin-left: 12%;
justify-content: center;
height: 80%;
}
.source-container {
height: 300px; /* ED: Changed to see the dropdown */
border-radius: 10px;
background-color: white;
overflow: scroll;
position: relative;
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.16), 0 1px 4px rgba(0, 0, 0, 0.26);
}
h5 {
padding: 10px;
margin: 0;
}
h5.submenu-open {
padding: 10px;
color: white;
background-color: #28be9a;
}
ul.src-main-menu {
position: relative;
list-style-type: none;
height: 12px;
}
ul.src-main-menu .src-main-sub {
margin: 20px 0;
}
ul.src-main-menu li.src-main-sub {
padding: 1px 0px;
cursor: pointer;
background-color: #e0e0e0;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
ul.src-main-menu li ul {
list-style-type: none;
color: black;
display: none;
position: relative;
max-height: 1000px;
/*fallback for FireFox */
height: 100%;
margin:0;
padding:0;
}
ul.src-main-menu li ul i {
display: inline-block;
}
.src-main-sub ul li {
border-bottom: 1px solid black;
margin: 20px 0;
padding:0 5px;
}
.src-main-sub ul li:last-child {
border-bottom: none;
margin: 0;
}
ul.src-main-menu li ul.open {
display: block;
}
ul.src-main-menu .src-main-sub i {
transition: all 0.5s;
}
ul.src-main-menu .src-main-sub i.ion-chevron-down {
transition: all 0.5s;
position: static;
left: 0;
}
ul.src-main-menu li i.closed {
transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
}
ul.src-main-menu li i.open {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"/>
<div class="container-fluid whole-dbsource">
<div class="row db-pagerow">
<div class="col-sm-7 source-container">
<ul class="src-main-menu">
<li class="src-main-sub">
<h5 class="src-sub-menu">Data Source Connections<i class="ion-chevron-down closed float-right"></i></h5>
<ul class="closed">
<li><span class='d-block'>Oracle 12c</span><i class="ion-edit d-block mt-2"></i></li>
<li><span class='d-block'>PostgresSQL</span><i class="ion-edit d-block mt-2"></i></li>
<li><span class='d-block'>MySql</span><i class="ion-edit d-block mt-2"></i></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
This part of your code is what is aligning your icons to the right, remove it and see the effect.
ul.src-main-menu .src-main-sub i {
transition: all 0.5s;
position: absolute;
right: 10px;
}
The code below will give your what you want
.closed li{
display: flex;
justify-content: center; // remove this if you don't want them centered
align-items: center;
flex-direction: column;
}

How to make CSS translucent two shapes look like one?

Problem
I drew 2 overlapping figures with CSS.
Because it is translucent, overlapping parts stand out.
I want to make it translucent like this when hovering, but can we do something like synthesize figures?
(I also mind that the end of transition of two figures is different..)
What I tried
I thought that the overlapping part could be deleted with overflow: hidden;, but it was not applicable to the & :: before element which diagonal cut part got lost.
Central placement problem
I would like to centrally align the letters in the tabs in this way.
Code
html { font-size: 62.5%; }
body { background-color: #c6d2dd; }
header { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; font: inherit; vertical-align: baseline; background: transparent; box-sizing: border-box; } /* reset */
header ul {
list-style: none;
display: flex;
align-items: center;
flex-wrap: wrap;
overflow: hidden;
width: 100%;
margin-bottom: -1px;
}
header li {
font-size: 1.5rem;
height: 4.5rem;
padding-left: .4rem;
}
header li:first-child {
padding-left: 1.5rem;
}
header li:last-child {
padding-right: .5rem;
}
header li > a {
text-decoration: none;
display: block;
padding: 1rem 2rem;
height: 100%;
color: #fff;
outline: none;
transition: background-color 0.2s ease-out, border-color 0.2s ease-out;
position: relative;
border-radius: 9px 5px 0 0;
}
/* from here */
header li > a:hover { /* The rectangular part on the right side */
background-color: rgba(255, 255, 255, 0.4);
border-color: rgba(255, 255, 255, 0.4);
transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.4);
}
header li > a:hover::before { /* Part of oblique cut on the left side */
background-color: rgba(255, 255, 255, 0.4);
border-color: rgba(255, 255, 255, 0.4);
transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.2);
}
header li > a::before { /* Part of oblique cut on the left side */
content: '';
position: absolute;
z-index: 1;
top: 0;
left: -.4rem;
bottom: 0;
width: 1rem;
transition: background-color 0.3s ease-in;
transform: skew(-15deg);
border-radius: 5px 0 0 0;
}
.current a { /* add from here */
border: 1px solid #fff;
border-bottom-width: 0;
z-index: 3;
background-color: #9bacbb;
pointer-events: none;
margin-bottom: -3px;
}
.current a::before {
border: 1px solid #fff;
background-color: #9bacbb;
margin: -1px 0 -3px -1px;
z-index: 3;
left: -.5rem;
}
.current a::after {
content: '';
position: absolute;
z-index: 3;
top: 0;
left: -.4rem;
bottom: 0;
width: 1rem;
transform: skew(-15deg);
border-radius: 5px 0 0 0;
margin-bottom: -3px;
background-color: #9bacbb;
}
.content {
display: flex;
margin: 0 1rem 1rem 1rem;
width: 100vw;
height: 61.9rem;
position: relative;
background: #9bacbb;
border: 1px solid #fff;
border-radius: 5px;
box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, 0.5);
}
<header>
<nav>
<ul>
<li class="111">
<a href="#">
111
</a>
</li>
<li class="222">
<a href="#">
222
</a>
</li>
<li class="333">
<a href="#">
333
</a>
</li>
<li class="444">
<a href="#">
444
</a>
</li>
<li class="current">
<a href="#">
555
</a>
</li>
</ul>
</nav>
</header>
<div class="content"> <!-- add -->
Hello world
</div>
I would do this differently with only one element. The trick is to have the skew and hide the overflowing part on the right:
check comment on the code
html { font-size: 62.5%; }
body { background-color: #c6d2dd; }
header { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; font: inherit; vertical-align: baseline; background: transparent; box-sizing: border-box; } /* reset */
header ul {
list-style: none;
display: flex;
align-items: center;
flex-wrap: wrap;
overflow: hidden;
width: 100%;
margin-bottom: -1px;
}
header li {
font-size: 1.5rem;
height: 4.5rem;
padding-left: .4rem;
}
header li:first-child {
padding-left: 1.5rem;
}
header li:last-child {
padding-right: .5rem;
}
header li > a {
text-decoration: none;
display: block;
padding: 1rem 1rem 1rem 3rem; /*changed the padding*/
margin-left:-2rem; /*create the overlap*/
height: 100%;
color: #fff;
outline: none;
transition: background-color 0.2s ease-out, border-color 0.2s ease-out;
position: relative;
border-radius: 9px 5px 0 0;
overflow:hidden; /*hide the overflow*/
/*increase the z-index*/
position:relative;
z-index:2;
}
/* from here */
header li > a:hover { /* The rectangular part on the right side */
transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.4);
/*remove border and background from here*/
}
header li > a:hover::before { /* Part of oblique cut on the left side */
background-color: rgba(255, 255, 255, 0.4);
border-color: rgba(255, 255, 255, 0.4);
transition: background-color 0.3s ease-in, border-color 0.3s ease-in;
box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.2);
}
header li > a::before { /* Part of oblique cut on the left side */
content: '';
position: absolute;
z-index: -1;
top: 0;
left: 0;
bottom: 0;
right:0; /*make right:0*/
transition: background-color 0.3s ease-in;
transform: skew(-15deg);
transform-origin:bottom right; /*change the origin*/
border-radius: 5px 0 0 0;
}
.current a {
pointer-events: none;
margin-bottom: -3px;
border-right: 1px solid #fff;
}
.current a::before {
border: 1px solid #fff;
background-color: #9bacbb;
}
.content {
display: flex;
margin: 0 1rem 1rem 1rem;
width: 100vw;
height: 61.9rem;
position: relative;
background: #9bacbb;
border: 1px solid #fff;
border-radius: 5px;
box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, 0.5);
}
<header>
<nav>
<ul>
<li class="111">
<a href="#">
111
</a>
</li>
<li class="222">
<a href="#">
222
</a>
</li>
<li class="333">
<a href="#">
333
</a>
</li>
<li class="444">
<a href="#">
444
</a>
</li>
<li class="current">
<a href="#">
555
</a>
</li>
</ul>
</nav>
</header>
<div class="content"> <!-- add -->
Hello world
</div>