How to tilt hover in CSS - html

I try to stylize hover for the header.
It shows like this.
And I want to make it look like this:
Even when I tried skew, the text was also tilting with it.
Help will be appreciated.
Here is my code:
.hvr-link {
display: inline-block;
vertical-align: middle;
-webkit-transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
position: relative;
-webkit-transition-property: color;
transition-property: color;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
}
.hvr-link:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: #424141;
-webkit-transform: scaleY(0);
transform: scaleY(0);
-webkit-transform-origin: 50%;
transform-origin: 50%;
-webkit-transition-property: transform;
transition-property: transform;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-link:hover,
.hvr-link:focus,
.hvr-link:active {
color: white;
}
.hvr-link:hover:before,
.hvr-link:focus:before,
.hvr-link:active:before {
-webkit-transform: scaleY(1);
transform: scaleY(1);
}
<div class="col-md-7 col-sm-12">
<div class="nav-outer clearfix menu-bg">
<!--main-menu start-->
<nav class="main-menu">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
</div>
<div class="navbar-collapse collapse clearfix">
<ul class="navigation clearfix">
<li class="hvr_link"><a class="hvr-link" href="#top">Home</a>
</li>
<li><a class="hvr-link" href="#service">Services</a>
</li>
<li class="dropdown"><a class="hvr-link" href="#">About</a>
<ul>
<li><a class="hvr-link" href="#aboutmy">About</a></li>
<li><a class="hvr-link" href="#teammy">Team</a></li>
</ul>
</li>
<li><a class="hvr-link" href="#portfoliomy">Portfolio</a>
</li>
<li><a class="hvr-link2" href="#propertymy">Properties</a>
</li>
<li><a class="hvr-link2" href="#contactmy">Contact</a></li>
</ul>
</div>
<div class="clearfix"></div>
</nav>
<!--main-menu end-->
</div>
</div>

In this context, it can be a little bit tricky because you have to put the link text in a span element in order to be able to achieve this.
Check the snippet below, a quick explanation:
What transform: skewX(20deg); does to .menu li a is basically tilt the link as you require. The problem there is that that tilts the entire element, text included. That's why you use a span inside your link and apply a counter tilt to that span using transform: skewX(-20deg);. It's basically resulting in a final 0 degree tilt. The rest of the styles I added just to simulate your requirements.
Also, it's important that the a elements use inline-block if you're not using float or block if you're using float, otherwise they are not affected by the tilt. Same applies to the inner span element.
It would look something like this:
.menu {
display: flex;
flex-direction: row;
flex-wrap: wrap;
list-style: none;
background: #3d424a;
}
.menu li a {
color: #c3c5c7;
text-decoration: none;
display: inline-block;
transform: skewX(20deg);
font-family: Arial;
font-weight: bold;
text-transform: uppercase;
padding: 2rem;
transition: background 0.15s ease-in-out, color 0.15s ease-in-out;
}
.menu li a span {
transform: skewX(-20deg);
display: block;
}
.menu li a:hover {
background: #fda539;
color: #3d424a;
}
<ul class="menu">
<li>
<span>Home</span>
</li>
<li>
<span>About</span>
</li>
<li>
<span>Contact</span>
</li>
</ul>

you can hover and create images. I added in the text to show you how to unskew the text as well so it doesn't get messed up on hovering.
.navigation {
transform: skew(20deg);
width: 100px;
height: 20px;
}
ul {
list-style-type: none;
}
ul li a {
display: block;
transform: skew(-20deg);
text-align: center;
}
li:hover {
background: orange;
}
<div class="col-md-7 col-sm-12">
<div class="nav-outer clearfix menu-bg">
<!--main-menu start-->
<nav class="main-menu">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
</div>
<div class="navbar-collapse collapse clearfix">
<ul class="navigation clearfix">
<li class="hvr_link"><a class="hvr-link" href="#top">Home</a>
</li>
<li><a class="hvr-link" href="#service">Services</a>
</li>
<li class="dropdown"><a class="hvr-link" href="#">About</a>
<ul>
<li><a class="hvr-link" href="#aboutmy">About</a></li>
<li><a class="hvr-link" href="#teammy">Team</a></li>
</ul>
</li>
<li><a class="hvr-link" href="#portfoliomy">Portfolio</a>
</li>
<li><a class="hvr-link2" href="#propertymy">Properties</a>
</li>
<li><a class="hvr-link2" href="#contactmy">Contact</a></li>
</ul>
</div>
<div class="clearfix"></div>
</nav>
<!--main-menu end-->
</div>
</div>

#parallelogram {
width: 150px;
height: 100px;
transform: skew(20deg);
background: red;
}
https://css-tricks.com/the-shapes-of-css/#parallelogram-shape

Related

ScrollSpy feature of Bootstrap 5 not working

I am trying to use scroll-spy feature of bootstrap 5 to ensure that the corresponding navbar item is shown active when I scroll through those sections of the html page. however I see its not working for me. The navigation-link item becomes inactive the moment I remove the cursor over it. Below are the snippets of my code:
I am trying to use data-bs-spy on the body tag. Below is the structure of my code
<body data-bs-spy="scroll data-bs-target="#nav-example" data-bs-offset="0" tabindex="0">
<header id="nav-items">
<nav class="navbar navbar-expand-lg navbar-light bg-light" id="nav-example">
<div id="navItem">
<ul class="navbar-nav mr-auto nav-items">
<li class="nav-item active">
<a class="nav-link" href="#home">Home <span class="sr-only"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section1">Section1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section2">
Section2
<span class="sr-only"></span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#section3">Section3</a>
</li>
</ul>
</div>
</nav>
</header>
<section id="home">...</section>
<section id="Section1">....</section>
<section id="Section2">....</section>
<section id="Section3">....</section
</body>
and here is the relevant CSS for this.
body{
position:relative;
scroll-behavior: smooth;
}
#navItem>ul>li> a{
display: inline-block;
position: relative;
}
#navItem>ul>li> a:hover{
color: red;
}
#navItem>ul>li> a:before{
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background-color: red;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.25s ease-in-out 0s;
transition: all 0.25s ease-in-out 0s;
}
#navItem>ul>li a:hover:before , #navItem>ul>li a:active:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
Complete Working code
If you want your active menu item underlined, you can add #navItem>ul>li a.active:before, to the following rule :
#navItem>ul>li a:hover:before , #navItem>ul>li a:active:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

Don't want recursive :after for my ul li dropdown menu

I'm stuck with this annoying problem. I have a nav in which there is a dropdown menu, composed by many <ul> in each <li>of the first <ul>
I have an :after effect for the main <ul>. It set a separator, but I don't want this separator in the <ul><li> of the <ul><li>.
Here is my code
nav ul li {
-webkit-transition: background-color .3s;
transition: background-color .3s;
float: left;
padding: 0;
transition:0.5s all;
position: relative;
display: block;
letter-spacing: -1px;
}
nav ul li:after {
height:60%;
content:'';
border-left: solid 1px rgba(255, 255, 255,0.3);
position: absolute;
transform: translateX(-50%) translateY(-50%);
left: 0px;
top: 50%;
transition:0.5s all;
-webkit-transition: 0.5s all;
}
nav ul li ul li:after {
content:none!important;
height:0%!important;
content:unset;
border-left: unset;
position: unset;
transform: unset;
left: unset;
top: unset;
}
<header id="header">
<nav>
<div class="bar">
<div class="brand-logo">
Paris Avenir</div>
<ul id="nav-normal" class="right">
<li>Aide/Tutos/Astuces<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>J'arrive à Paris</li>
<li>Impositions</li>
<li>Fonctionnement de la mairie</li>
<li>PLU</li>
<li>Emploi/Formation</li>
</ul>
</li>
<li>Nos actions<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>Décryptage des conseils municipaux</li>
<li>Étude des budgets</li>
<li>Actualités</li>
</ul></li>
<li><a id="search"><i class="fas fa-search"></i></a></li>
</ul>
</div>
</nav>
</header>
This seems so easy but it doens't work.
Thanks you,
Matthieu
You want to select only the ul with the id of nav-normal and use the child combinator CSS selector:
ul#nav-normal > li::after
You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
Note that I've altered the styling of the ::after elements to make then more easily visible
nav ul li {
-webkit-transition: background-color .3s;
transition: background-color .3s;
float: left;
padding: 0;
transition: 0.5s all;
position: relative;
display: block;
letter-spacing: -1px;
}
ul#nav-normal>li::after {
content: '[:after content]';
color: red;
}
<header id="header">
<nav>
<div class="bar">
<div class="brand-logo">Paris Avenir</div>
<ul id="nav-normal" class="right">
<li>
Aide/Tutos/Astuces<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>J'arrive à Paris</li>
<li>Impositions</li>
<li>Fonctionnement de la mairie</li>
<li>PLU</li>
<li>Emploi/Formation</li>
</ul>
</li>
<li>
Nos actions<i class="fas fa-angle-down"></i>
<ul class="dropdown">
<li>Décryptage des conseils municipaux</li>
<li>Étude des budgets</li>
<li>Actualités</li>
</ul>
</li>
<li><a id="search"><i class="fas fa-search"></i></a></li>
</ul>
</div>
</nav>
</header>

How to adjust animation linked to a hover event?

I have a header composed of navigation links to other websites, some of these links are shown through drop-down menus. With the event hover I have added an animation and style to see what you are on at every moment and that, in case of a drop-down, shows you all the options. The thing is that once the dropdown has been shown I have added the same style and animation to the internal links as to the main ones, but in the case of the animation I always have the underline in the same place instead of just below each link. Thanks in advance for your time and help. I leave you a link with an example as I have it now working with the described behavior
https://codepen.io/carlosurra/pen/YzqXjdP
my template
<div id="row">
<div class="col-xs-12">
<header>
<nav class="navbar navbar-expand-lg navbar-light header">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu">
<li class="nav-item">
<a class="nav-link">PERSONAL INFO</a>
</li>
<li class="nav-item" #mouseover="animalList = true" #mouseleave="animalList = false" >
<a class="nav-link menu-link-toggle" >PERSONAL FORM</a>
<ul class='dropdown-menu' v-if="animalList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>FORM DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >AUTOCOMPLETE</a>
</li>
</ul>
</li>
<li class="nav-item" #mouseover="serviceList = true" #mouseleave="serviceList = false">
<a class='nav-link menu-link menu-link-toggle' >SERVICES</a>
<ul class='dropdown-menu' v-if="serviceList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >LA CRÉMATION PRIVÉE</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PERSONAL S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>COMPANY S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >FULL S INFO</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link ">SHOP</a>
</li>
<li class="nav-item active">
<router-link class="nav-link" to="/devis">PRICES</router-link>
</li>
<li class="nav-item" #mouseover="contactList = true" #mouseleave="contactList = false">
<a class='menu-link nav-link menu-link-toggle' >CONTACT</a>
<ul class='dropdown-menu' v-if="contactList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>MAIL</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PHONE</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>
my css
html, body {
background: #009050;
}
.header {
display: flex;
justify-content: center;
align-items: baseline;
}
.menu {
list-style: none;
display: flex;
align-items: center;
}
.nav-item {
padding: 25px;
position: relative;
}
.nav-link:hover {
color: white;
}
.menu-link-toggle {
cursor: pointer;
}
.dropdown-menu {
margin-top: 10px;
list-style: none;
position: absolute;
padding: 1em 1.25em 0.5em 0.75em;
background-color: white;
width: max-content;
box-shadow: 0px 14px 24px 0px rgba(0,0,0,0.21);
}
.dropdown-menu-item {
margin: 20px 0 20px 0;
}
.dropdown-menu-link {
font-size: 14px;
font-weight: bold;
color: red;
text-decoration: none;
}
.head {
font-size: 14px;
color: red;
font-weight: bold;
text-decoration: none;
}
.nav-item:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 35%;
background: white;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.nav-item:hover:before,
.nav-item:focus:before {
visibility: visible;
transform: scaleX(1);
}
.dropdown-menu-link:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 0%;
background: #D53865;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.dropdown-menu-link:hover:before,
.dropdown-menu-link:focus:before {
visibility: visible;
transform: scaleX(1);
}
.added {
display: none;
}
Please add this to your code
.dropdown-menu-link {
padding-bottom:3px;
position:relative;
}
.dropdown-menu-item {
position:relative;
}
Change the code bottom:30%; to bottom: 0px;
.dropdown-menu-link:before {
bottom: 0px;
}
Please check this codepen :
https://codepen.io/Rayeesac/pen/LYNpyEx
Add position: relative to .dropdown-menu-item and set a correct position to bottom of .dropdown-menu-item:before, let's say to 0px;
Or if you want to be relative to the link set position: relative to .dropdown-menu-link.

Bootstrap Sub menu to stretch full screen and overlay the whole page

I've made a JSFiddle to illustrate what I have at the moment. Please view my code here:
Some of my CSS snippet code:
.subnav {
display: none;
position: absolute;
//top: 58px;
background: #dfe6e8;
padding: 24px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
transition: all .5s ease;
}
.subnav li {
margin-right: 0px !important;
min-width: 142px;
}
.subnav li a {
padding-bottom: 0px !important;
margin-bottom: 16px;
}
.subnav li:last-child a {
margin-bottom: 0px;
}
.has-dropdown:hover .subnav {
display: block;
}
I'm having problem to make my UL to stretch fullscreen. Here's what I'm trying to achieve as below:
Any help would be appreciated
To achieve this you have to make few structural and css changes. I edited your fiddle and made some changes to the navigation.
Html:
<div class="nav-container">
<nav class="top-bar">
<div class="container-fluid">
<div class="row nav-menu">
<div class="col-xs-12 columns">
<a class="navbar-brand" href="index.html"><img alt="Logo" class="logo logo-light" src="img/logo-light.png"> <img alt="Logo" class="logo logo-dark" src="http://www.subcablenews.com/links/images2/telenor.gif"></a>
<ul class="menu navbar-right">
<li>
ABOUT
</li>
<li class="has-dropdown">
PROGRAMMES
<ul class="subnav">
<li>
Programme 1
</li>
<li>
Programme 2
</li>
<li>
Programme 3
</li>
<li>
Programme 4
</li>
</ul>
</li>
<li class="has-dropdown">
PROJECTS
<div class="subnav subnav-halfwidth fullwidth">
<div class="col-sm-4">
<h6 class="alt-font">Project Lists</h6>
<ul class="subnav subnav-halfwidth">
<li>
Project 1
</li>
<li>
Project 2
</li>
<li>
Project 3
</li>
<li>
Project 4
</li>
</ul>
</div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
<div class="col-sm-4">
<h6 class="alt-font">Project Lists 2</h6><img alt="Logo" class="logo" src="http://www.subcablenews.com/links/images2/telenor.gif"></div>
</div>
</li>
<li class="has-dropdown">
MEDIA
<ul class="subnav">
<li>
Media 1
</li>
<li>
Media 2
</li>
<li>
Media 3
</li>
<li>
Media 4
</li>
</ul>
</li>
<li>
CONTACT
</li>
</ul>
<ul class="social-icons text-right">
<li>
<i class="icon social_twitter"></i>
</li>
<li>
<i class="icon social_facebook"></i>
</li>
<li>
<i class="icon social_instagram"></i>
</li>
</ul>
</div>
</div><!--end of row-->
<div class="mobile-toggle">
<i class="icon icon_menu"></i>
</div>
</div><!--end of container-->
</nav>
</div>
Extra Css:
.subnav.fullwidth{
position: absolute;
right: -15px;
top: 58px;
width: 100vw;
background: #F6F4F4;
padding: 48px 64px 48px;
box-shadow: inset 0 1px 0 #e2e3df, 0 3px 6px rgba(113,111,111,.7);
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-ms-transform: translateX(0);
-o-transform: translateX(0);
transform: translateX(0);
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
-moz-transition: opacity .3s 0s, visibility 0s 0s;
transition: opacity .3s 0s, visibility 0s 0s;
/* box-shadow: 1px 2px 5px #7D7D7D; */
}
.row{margin:0}
.top-bar .logo {
width: 150px;
}
.subnav li{float:none; display: block;}
Here is Updated Fiddle. Make sure you check the html as well. Because I made some changes in that too.
Read this to get better understand about bootstrap navigation. Hope this helps you.
It's because the parent elements aren't at 100% width. You can override this by using width:100vw; on any element that you want to take up the full width. Also, try and remember next time to only include css on your fiddle that's relevant to the html at question. It's a lot to sort through for someone trying to help when you include your entire stylesheet.

links jump out of navigation when resized (responsive)

I have two problems with my navigation in twitter bootstrap.
the links jump out of the navigation when I re-size the browser window
and 2. the collapsed navigation is hidden behind the carousel.
I want all my links in the navigation to have the same width, because they get a border in mouse-over but because of that they jump out of the navigation and are hidden behind the carousel/slider when re-sized.
They collapse just fine when re-sized to 768px but everything above that jumps out of navigation. And the other thing is that when the navigation is collapsed it is half hidden behind the carousel/slider when opened.
<nav class="navbar navbar-inverse" role="navigation">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-header">
<a class="navbar-brand" href="index.html">Test</a>
</div>
<div class="nav-collapse collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="span4">Home</li>
<li class="span4">Forschung</li>
<li class="span4">Fahrzeug</li>
<li class="span4">Team</li>
<li class="span4">Presse</li>
<li class="span4">Ziele</li>
<li class="span4">Karte</li>
<li class="span4">Jobs</li>
</ul>
</div>
</nav>
<div class="container">
<div id="this-carousel-id" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#this-carousel-id" data-slide-to="0" class="active"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="http://placehold.it/1200x480" alt="" />
<div class="carousel-caption"><h1>Mercedes Benz</h1></div>
</div>
</div>
<a class="carousel-control left" href="#this-carousel-id" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="carousel-control right" href="#this-carousel-id" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
</div>
and this is the css
.navbar {
height: 100px;
font-family: 'Oswald', sans-serif;
text-transform: uppercase;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
padding-right: 5%;
background-color: #000000 !important;
box-sizing: border-box;
}
.navbar-inverse .navbar-nav > li > a { color: #a2a2a2 !important }
.nav a:link,
a:visited {
line-height: 4em;
display: block;
height: 100px;
width: 120px;
text-align: center;
text-decoration: none;
}
.nav a:after {
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 1px;
background: #062d67;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
.nav a:hover,
a:focus,
a:active {
height: 81px;
color: #ffffff !important;
background-color: #0d0d0d !important;
}
.nav a:hover:after,
.nav a:focus:after,
.nav a:active:after {
height: 18px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}
Can anyone please point out what I did wrong?
You can't have 8 span4 elements in one row. the total sum of N in spanN must be 12 or below.
you can use span1in your case or no class on for <li> (list item) elements at all.