Bulma CSS Tabs Component Implement Angled Borders With Vue - html

I'm using Bulma CSS Tabs component with the is-boxed modifier. Fantastic out of the box styling but I would like to change how the active tabs' borders look. What I wanted to achieve is:
I've tried skewing the elements, but it's really not working as expected as I have to take into consideration the next list item especially in the middle when active. Here's what I've tried so far:
<div class="tabs is-boxed">
<ul>
<li class="is-active">
<a>
<span>Pictures</span>
</a>
</li>
<li>
<a>
<span>Music</span>
</a>
</li>
<li>
<a>
<span>Videos</span>
</a>
</li>
</ul>
</div>
This is the CSS:
li.is-active a {
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-ms-transform: skew(20deg);
-o-transform: skew(20deg);
transform: skew(20deg);
border-top: 0;
border-left: 0;
}
li.is-active a span {
-webkit-transform: skew(-20deg) !important;
-moz-transform: skew(-20deg) !important;
-ms-transform: skew(-20deg) !important;
-o-transform: skew(-20deg) !important;
transform: skew(-20deg) !important;
}

Maybe like following snippet (plain css):
const app = Vue.createApp({
data() {
return {
tabs: ['Pictures', 'Music', 'Videos'],
active: 0,
};
},
methods: {
activate(id) {
this.active = id
}
}
})
app.mount('#demo')
.tabs ul {
display: flex;
flex-wrap: wrap;
align-items: center;
list-style-type: none;
margin: .5em 1em;
}
.is-active:before, .is-active:after {
border: none;
}
li {
position: relative;
padding: 0.3em 0.8em;
cursor: pointer;
z-index: 0;
}
li:before,
li:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
width: 70%;
}
li:before {
left: -1px;
border-left: 2px solid #000;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
}
li:after {
right: -1px;
border-right: 2px solid #000;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
}
li:after,
li:nth-child(odd):before {
transform: skewX(-15deg)
}
li:before,
li:nth-child(odd):after {
transform: skewX(15deg)
}
li:first-of-type:before {
transform: skewX(0deg)
}
li:last-of-type:after {
transform: skewX(0deg)
}
li:hover {
color: #fff;
}
li:hover:before,
li:hover:after {
background: #000;
}
<script src="https://unpkg.com/vue#3/dist/vue.global.prod.js"></script>
<div id="demo">
<div class="tabs is-boxed">
<ul>
<li v-for="(tab, idx) in tabs" :key="idx" :class="active === idx && 'is-active'" #click="activate(idx)">
<a>
<span>{{ tab }}</span>
</a>
</li>
</ul>
</div>
</div>

Related

text-underline decoration not apply on all child element

I have a label "Show more", that display hidden content. I want all child element of this label to be underline including the arrow. The problem is that only the text has text-decoration and not the arrow. How can I solve this issue in order that also arrow will be in the same underline text.
Thanks
#arrow_create {
border: solid black;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 2px;
}
.icos-angle-up {
margin-left: 3px !important;
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
}
.icos-angle-down {
margin: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.icos-angle-up {
visibility: hidden;
}
#read_more_checkbox:checked+label[for="read_more_checkbox"]>.icos-angle-up {
visibility: visible;
}
#read_more_checkbox:checked+label[for="read_more_checkbox"]>.icos-angle-down {
display: none;
}
.read_more_txt {
display: none;
}
#read_more_checkbox {
display: none;
}
#read_more_checkbox:checked~.read_more_txt {
display: block;
margin-top: 10px;
}
.read_more_label {
margin-left: 5px !important;
font-weight: bold;
text-transform: uppercase;
}
#read_more_checkbox~.read_more_label:before {
content: attr(read_more);
text-decoration: underline;
text-underline-offset: 4px;
text-decoration-thickness: 1px;
cursor: pointer;
width: 110px;
}
#read_more_checkbox:checked~.read_more_label::before {
text-decoration: underline;
text-underline-offset: 4px;
text-decoration-thickness: 1px;
content: attr(read_less);
cursor: pointer;
}
<label for="read_more_checkbox" class="read_more_label" read_more="Show more" read_less="Show less">
<span id="arrow_create" class="icos-angle-down"></span>
<span id="arrow_create" class="icos-angle-up"></span>
</label>
So instead of using text-decoration (which only applies to text) you can either use border-bottom or to keep it more complicated there is also the possibility of using a css pseudo class.
Using border bottom
.read_more_label {
border-bottom: 1px solid black;
}
#arrow_create {
border: solid black;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 2px;
}
.icos-angle-down {
margin: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<label class="read_more_label">
Show more
<span id="arrow_create" class="icos-angle-down"></span>
</label>
Using css pseudo classes
The benefit of using pseudo classes would be that you also have the chance to design it more and you can even add some litte animations (as I did in the example)
.read_more_label {
position: relative;
}
.read_more_label::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
width: 100%;
height: 1px;
background-color: black;
opacity: 0;
transition: all 0.2s;
}
.read_more_label:hover::after {
opacity: 1;
}
#arrow_create {
border: solid black;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 2px;
}
.icos-angle-down {
margin: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<p>HOVER IT: </p>
<label class="read_more_label">
Show more
<span id="arrow_create" class="icos-angle-down"></span>
</label>
If shape arrow doesn't matter.
span {
text-decoration: underline;
}
<html>
<body>
<span>SHOW MORE ∨</span>
</body>
</html>
You can use also other HTML Special Characters
Another way
span {
border-bottom: 1px solid black;
}
span::after {
content: "";
border: solid black;
border-width: 0 2px 2px 0;
display: inline-block;
padding: 2px;
margin: 3px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<html>
<body>
<span>SHOW MORE</span>
</body>
</html>
You can use hr tag to draw a line under any thing and then you can add css on hr according to your need.for example if you want to change color of that line you can simply add css on hr tag and change color.

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;
}

CSS only accordian with input - hidden hyperlinks appearing

I've built a CSS only accordian... (And I specifically have been asked to build this without JavaScript).
So far my code is working fine. And I'm using the <input type="checkbox" checked="checked" /> to achieve this.
The problem I am having, is that the content I am hiding/toggling, includes hyperlinks. And when my accordian is closed, the hyperlinks are still clickable, even with the accordian is closed.
IE - if you were to hover 40px-50px under the copy "Choose another cool destination", you can't see the content. But you can still hover over the (invisible) hyperlinks. And even click them.
How can I stop this from happening?
I don't want my hyperlinks to be clickable. Only when the accordian is open!
Here is a codepen where you can see this:
https://codepen.io/ReenaVerma1981/pen/qBdbbWJ
ul {
list-style: none;
padding: 0px;
}
.readme {
background-color: transparent;
color: #ff6600;
font-family: "easyjet_rounded_demi",Arial,Helvetica,sans-serif;
font-size: 17px;
font-weight: 700;
line-height: 22px;
padding: 0;
border: 0;
}
.accordion {
margin: 0 auto;
width: 100%;
}
.accordion__item {
float: left;
position: relative;
width: 100%;
background-color: transparent;
border-radius: 4px;
margin-bottom: 40px;
}
.accordion__item span {
color: #ff6600;
margin-top: 1rem;
position: absolute;
left: 280px;
top: 0;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.accordion__item input[type=checkbox] {
position: absolute;
cursor: pointer;
width: 100%;
height: 50px;
z-index: 1;
opacity: 0;
}
.accordion__item input[type=checkbox]:checked ~ div.panel {
float: left;
margin: 5px 0;
max-height: 0;
opacity: 0;
-webkit-transform: translate(0, 50%);
transform: translate(0, 50%);
}
.accordion__item input[type=checkbox]:not(:checked) ~ span {
padding-top: 5px;
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
.accordion__item input[type=checkbox]:checked ~ span {
padding-top: 5px;
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
.panel {
background-color: transparent;
border: 1px solid grey;
}
<body>
<div class="accordion">
<ul class="">
<li class="accordion__item">
<input type="checkbox" checked="checked" />
<p class="readme">Choose another cool destination</p>
<span class="">
<svg viewBox="1 1 22 22" width="1em" height="1em" aria-hidden="true" focusable="false" class="icon-svg"><path d="M21.7 6.79a1 1 0 00-1.41 0L12 15.08 3.71 6.79a1 1 0 00-1.41 0 1 1 0 000 1.42l9 9a1 1 0 001.42 0l9-9a1 1 0 00-.02-1.42z"></path></svg>
</span>
<div class="panel">
<strong>
London,
NYC,
LA,
LAX,
Dublin,
Liverpool,
Manchester,
Dubai,
Hong Kong,
Singapre.
</strong>
</div>
</li>
</ul>
</div>
</body>
</html>
.accordion__item input[type=checkbox]:checked ~ div.panel {
float: left;
margin: 5px 0;
max-height: 0;
//opacity: 0; instead use display: none
-webkit-transform: translate(0, 50%);
transform: translate(0, 50%);
}
Mark accepted answer, if you feel answer is coreect
Try using pointer-events
.accordion__item input[type="checkbox"]:checked ~ div.panel {
float: left;
margin: 5px 0;
max-height: 0;
opacity: 0;
-webkit-transform: translate(0, 50%);
transform: translate(0, 50%);
pointer-events: none;
}
.panel {
background-color: transparent;
border: 1px solid grey;
pointer-events: all;
}

How to keep text in anchor tag in the same position when border property is used

I am planning to use Bootstrap's Scrollspy component to work on a <ul> element.
The issue for me is that when I use the border-left property on a <li> element, the text in the anchor tag gets shifted a little to the right.
What could I do to fix this?
Please see Pen:
https://codepen.io/AshNaz87/pen/QmVJVY
.wrapper {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
li {
list-style: none;
margin-bottom: 0.5rem;
padding-left: 1rem;
}
li:last-child {
margin: 0;
}
.with-border {
border-left: 3px solid grey;
}
a {
text-decoration: none;
color: #000;
}
<div class="wrapper">
<ul class="nav">
<li class="with-border">Fortune</li>
<li>Favours</li>
<li>The</li>
<li class="with-border">Brave</li>
</ul>
</div>
The reason why you're seeing this inconsistent offset of the text is because the border of an element actually take up physical space in the layout. To circumvent this, you will need to account for the space the border will take (see solution 1), or use alternative strategies that do not alter the flow of the document (see solution 2 and 3).
You can either use a:
transparent left-border on all your elements <li>,
background-image to visually mimic a border, or
abolustely positioned pseudo-element
Solution 1: Transparent left border
This solution means introducing a transparent border on all <li> elements, and simply changing the border-color property when needed:
li {
border-left: 3px solid transparent;
}
li.with-border {
border-color: grey;
}
.wrapper {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
li {
border-left: 3px solid transparent;
list-style: none;
margin-bottom: 0.5rem;
padding-left: 1rem;
}
li:last-child {
margin: 0;
}
li.with-border {
border-color: grey;
}
a {
text-decoration: none;
color: #000;
}
<div class="wrapper">
<ul class="nav">
<li class="with-border">Fortune</li>
<li>Favours</li>
<li>The</li>
<li class="with-border">Brave</li>
</ul>
</div>
Solution 2: background-image to mimic border
Alternatively, you can use a linear gradient as a background image with a clearly demarcated border/breakpoint, to visually mimic a border:
li.with-border {
background-image: linear-gradient(90deg, grey 3%, transparent 3%);
}
.wrapper {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
li {
list-style: none;
margin-bottom: 0.5rem;
padding-left: 1rem;
}
li:last-child {
margin: 0;
}
li.with-border {
background-image: linear-gradient(90deg, grey 3%, transparent 3%);
}
a {
text-decoration: none;
color: #000;
}
<div class="wrapper">
<ul class="nav">
<li class="with-border">Fortune</li>
<li>Favours</li>
<li>The</li>
<li class="with-border">Brave</li>
</ul>
</div>
Solution 3: Absolutely-positioned pseudo-element
This solution is the most verbose one: it uses a generated pseudo-element that is absolutely positioned within the <li> element to visually mimic a border:
li {
position: relative;
}
li::before {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 3px;
display: none;
content: '';
background-color: grey;
}
li.with-border::before {
display: block;
}
.wrapper {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
li {
position: relative;
list-style: none;
margin-bottom: 0.5rem;
padding-left: 1rem;
}
li:last-child {
margin: 0;
}
li::before {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 3px;
display: none;
content: '';
background-color: grey;
}
li.with-border::before {
display: block;
}
a {
text-decoration: none;
color: #000;
}
<div class="wrapper">
<ul class="nav">
<li class="with-border">Fortune</li>
<li>Favours</li>
<li>The</li>
<li class="with-border">Brave</li>
</ul>
</div>

Highlight active menu item with CSS only

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>