I'm trying to achieve this
social icons hover effect
The dark background should moves down and fill the box on mouse over. This works perfectly when I use no background for the parent container but the hover effect goes behind the parent container when a background image is used.
Screenshot: not showing when bg image set for parent container
and I can see the effect when an opacity value is set for the parent container.
I've tried using negative z-index for the parent but not working for some reason.
My code
.hero {
background: url('http://lorempixel.com/output/abstract-q-g-640-480-3.jpg') no-repeat;
background-size: cover;
height: 550px;
padding: 40px 10px;
/*opacity :0.5; Works in Background*/
}
.social-icons {
}
.social-icons li {
display: inline-block;
font-weight: bold;
text-transform: uppercase;
color: #fff;
padding: 60px 5px 5px 60px;
text-decoration: none;
position: relative;
border: 3px solid #000;
overflow: hidden;
transition: all .5s linear;
}
.social-icons li:hover {
color: #000;
}
.social-icons li:hover:before {
left: -55px;
}
.social-icons li:before {
content: "";
position: absolute;
top: 0;
left: -280px;
background: #000;
height: 100%;
width: 250px;
transform: skew(-50deg);
z-index: -1;
transition: all .5s linear;
}
.social-icons li a {
color: #000000;
display:block;
}
.social-icons li:hover a {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<section class="hero">
<div class="container">
<div class="row">
<div class="social-icons">
<ul>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>
</section>
Do like this, give the anchor a a position, i.e. position: relative and remove the z-index.
I also adjusted your li:before/li:hover:before rules a little, so the transition work both ways.
.hero {
background: url('http://lorempixel.com/output/abstract-q-g-640-480-3.jpg') no-repeat;
background-size: cover;
height: 550px;
padding: 40px 10px;
/*opacity :0.5; Works in Background*/
}
.social-icons {
}
.social-icons li {
display: inline-block;
font-weight: bold;
text-transform: uppercase;
color: #fff;
padding: 60px 5px 5px 60px;
position: relative;
border: 3px solid #000;
overflow: hidden;
}
.social-icons li:hover {
color: #000;
}
.social-icons li:before {
content: "";
position: absolute;
top: 0;
left: 280px;
background: #000;
height: 100%;
transform: skew(-50deg);
width: 250px;
transition: left .2s linear;
}
.social-icons li:hover:before {
left: -20px;
transition: left .2s linear;
}
.social-icons li a {
position: relative;
color: #000000;
display:block;
}
.social-icons li:hover a {
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<section class="hero">
<div class="container">
<div class="row">
<div class="social-icons">
<ul>
<li><i class="fa fa-facebook"></i></li>
<li><i class="fa fa-twitter"></i></li>
<li><i class="fa fa-google-plus"></i></li>
<li><i class="fa fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>
</section>
Related
i am trying to create a CSS Animation for a vertical line going upwards - the line should be within a specific div
I have used gsap - i have used as well ypercent field, however the line starts from below the FirstScene div while i need it to be contained within the FirstScene div
gsap.fromTo(".vertical-line",{ yPercent:10 }, {yPercent:0,duration: 5});
* {
margin: 0;
padding: 0
}
.topnav {
position: sticky;
top: 0;
font-size: x-large;
background-color: black;
position: -webkit-sticky;
overflow: hidden;
z-index: 1;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: black;
}
li {
float: right;
padding: 8px;
color: white;
display: inline;
}
linkStyle {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li i {
color: white;
text-decoration: none;
}
li a {
color: white;
text-decoration: none;
}
#li-left {
float: left;
}
body {
margin: 0px;
height: 100%;
}
.FirstScene {
background-color: black;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
.line {
left: 50%;
top: 50%;
width=10px;
height: 50%;
position: absolute;
}
.vertical-line {
border-left: 6px solid blue;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.3/gsap.min.js"></script>
<div class="topnav">
<ul>
<li id="li-left">
<Link to="/" class="linkStyle"> MINA IBRAHIM
</Link>
</li>
<li>
<a href="https://github.com/ibrahimmina">
<i class="fa-brands fa-github"></i>
</a>
</li>
<li>
<a href="https://www.linkedin.com/in/minasamyibrahim/">
<i class="fa-brands fa-linkedin"></i>
</a>
</li>
<li>
.email()
</li>
<li>
<Link to="/about" class="linkStyle"> .about()
</Link>
</li>
</ul>
</div>
<body>
<section class="FirstScene">
<div class="line">
<div class="vertical-line">
</div>
</div>
</section>
</body>
Please use the bellow css for the Vertical Line Going Upwards animations
.FirstScene{
background-color: black;
position:absolute;
top:0px;
right:0px;
bottom:0px;
left:0px;
}
.vertical-line{
border-left: 6px solid blue;
animation-name: line;
animation-duration: 5s;
animation-iteration-count: 1;
left: 0;
height: 50%;
width: 10px;
position: absolute;
bottom: 0;
right: 0;
margin: 0 auto;
}
#keyframes line{
0%{
height: 0px;
}
100%{
height: 50%;
}
}
To make sure the media query was actually working and the problem not being me setting the wrong max-width, I set the nav bar to change color and height when the max width was reached. My main goal was for the search bar to move further to the left but this doesn't work (the change in background color was for visual purposes). Why is this so? I'm trying to reposition the search bar as it glitches once the screen gets smaller.
nav ul {
display: inline-flex;
list-style: none;
transform: translate(16%);
}
nav ul li {
margin-right: 50px;
}
.search {
border-radius: 40px;
background-color: rgb(255, 255, 255);
display: inline-flex;
height: 35px;
transform: translate(180px, -1px);
}
.search input {
position: relative;
left: 10px;
top: 0px;
outline: none;
width: 0px;
border: none;
background: transparent;
transition: 0.5s;
}
search:hover input {
width: 150px;
}
.btn {
height: 35px;
width: 35px;
border-radius: 35px;
background-color: lightseagreen;
}
.btn i {
position: Relative;
top: 9px;
left: 9px;
}
#media screen and (max-width: 1380px) {
nav {
background-color: greenyellow;
height: 40px;
}
.search {
background-color: indigo;
}
}
<nav>
<ul>
<li><a href=#>word1</a></li>
<li><a href=#>word2</a></li>
<li><a href=#>word3</a></li>
</ul>
<div class="search">
<input type="text" placeholder="search">
<div class=btn>
<i class="fas fa-search"></i>
</div>
</div>
</nav>
Your media query is working as expected: The background-colors are applied and the height is set. The background-color for .search wasn't so good visible because the search input has a width: 0px - therefor i tested with 50px. The change of the height wasn't visible because everything was white - therefor i tested with:
nav {
background-color: #ccc;
}
Now you can see that on big screens the nav has no height (= auto) and on small screens 40px (use the browsers dev tools).
Working example:
nav {
background-color: #ccc;
}
nav ul {
display: inline-flex;
list-style: none;
transform: translate(16%);
}
nav ul li {
margin-right: 50px;
}
.search {
border-radius: 40px;
background-color: lightcoral;
display: inline-flex;
height: 35px;
transform: translate(180px, -1px);
}
.search input {
position: relative;
left: 10px;
top: 0px;
outline: none;
width: 0px;
border: none;
background: transparent;
transition: 0.5s;
}
.search:hover input {
width: 150px;
}
.btn {
height: 35px;
width: 35px;
border-radius: 35px;
background-color: lightseagreen;
}
.btn i {
position: Relative;
top: 9px;
left: 9px;
}
#media screen and (max-width: 1380px) {
nav {
background-color: greenyellow;
height: 40px;
}
.search {
background-color: indigo;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<nav>
<ul>
<li><a href=#>word1</a></li>
<li><a href=#>word2</a></li>
<li><a href=#>word3</a></li>
</ul>
<div class="search">
<input type="text" placeholder="search">
<div class=btn>
<i class="fas fa-search"></i>
</div>
</div>
</nav>
Alternative example:
with display: flex for the whole nav container and deactivated transform for the ul in the media query
nav {
display: flex;
justify-content: space-between;
background-color: #ccc;
}
nav ul {
display: inline-flex;
list-style: none;
transform: translate(16%);
}
nav ul li {
margin-right: 50px;
}
.search {
border-radius: 40px;
background-color: lightcoral;
display: inline-flex;
height: 35px;
}
.search input {
position: relative;
left: 10px;
top: 0px;
outline: none;
width: 0px;
border: none;
background: transparent;
transition: 0.5s;
}
.search:hover input {
width: 150px;
}
.btn {
height: 35px;
width: 35px;
border-radius: 35px;
background-color: lightseagreen;
}
.btn i {
position: Relative;
top: 9px;
left: 9px;
}
#media screen and (max-width: 1380px) {
nav {
background-color: greenyellow;
height: 40px;
}
nav ul {
transform: none;
}
.search {
background-color: indigo;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<nav>
<ul>
<li><a href=#>word1</a></li>
<li><a href=#>word2</a></li>
<li><a href=#>word3</a></li>
</ul>
<div class="search">
<input type="text" placeholder="search">
<div class=btn>
<i class="fas fa-search"></i>
</div>
</div>
</nav>
If it is not working for all the div's, check if you forgot to put <meta content="width=device-width, initial-scale=1" name="viewport" /> inside your <head> </head> tags where you have your HTML code. This should do the trick.
lately I've started coding with some css and html and I decided to make my own first website, so I had some problems in changing the position of a div containing two buttons("s'inscrire" and "se connecter") ... Also when I hover on the header list, it starts moving upwards and downwards, I changed the padding, the margin... But nothing happens!
#import url('https://fonts.googleapis.com/css?family=Montserrat|Raleway');
*{
margin:0;
padding: 0;
font-family: Raleway;
}
body{
background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)),
url('1.jpg');
background-position: center;
background-size: cover;
height: 100vh;
}
.main ul{
float: right;
display: block;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
position: sticky;
}
.main ul li{
display: inline-block;
width: 150px;
}
.main ul li i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
}
.main ul li a:hover{
position: relative;
display: block;
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.main ul li.active a{
background-color: #fff;
color: #000;
}
.main ul ul li{
list-style-type: none;
display: none;
}
.main ul li:hover ul li{
display: block;
}
.login ul{
float: right;
position: fixed;
list-style-type: none;
display: inline-block;
font-size: 12px;
}
.logo img{
float: left;
width: 150px;
height: auto;
margin-top: 15px;
margin-left: 0;
}
header{
background-color: rgba(202, 211, 200,0.6);
}
.main{
max-width: 1200px;
margin: auto;
}
.title img{
width: 40%;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%,-100%);
}
.title p{
width: 40%;
position: absolute;
top: 54%;
left: 50%;
font-size: 25px;
font-family: Montserrat;
font-weight: lighter;
transform: translate(-50%,-100%);
text-align: center;
color: #F8EFBA;
}
.button{
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%,-100%);
}
.button a i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.btn{
border: 1px solid #eccc68;
border-radius: 15px;
padding: 10px 30px;
color: #fff;
font-size: 20px;
text-decoration: none;
}
.btn:hover{
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.footer{
width: 100%;
position: fixed;
bottom: 0;
background-color: rgba(0,0,0,0.4);
height: 60px;
}
.footer ul{
transform: translateX(1800px);
margin-right: 0px;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
}
.footer ul li a i{
font-size: 20px;
padding-right: 5px;
color: #eccc68;
}
.footer ul li{
display: inline-block;
}
.footer h5{
font-size: 11px;
color: #eccc68;
text-align: center;
opacity: 0.7;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trip Buddy | Your free online travel guide</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
</head>
<body>
<header>
<div class="main">
<div class="logo">
<img src="2.png">
</div>
<ul>
<li class="active"><i class="fas fa-home"></i>Accueil</li>
<li><i class="fas fa-city"></i>Villes dispo
<ul>
<li>Marrakech</li>
<li>Rabat</li>
<li>Tanger</li>
<li>Essaouira</li>
</ul>
</li>
<li><i class="fas fa-hand-holding"></i>Services</li>
<li><i class="fas fa-user-alt"></i>Contact</li>
</ul>
</div>
<div class="login">
<ul>
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</div>
<div class="title">
<img src="2.png">
<p>Trip Buddy est ton premier accompagnant guide en ligne. Rejoignez notre nombreuse communauté et télecharger l'application sur toutes les platformes GRATUITEMENT!</p>
</div>
<div class="button">
<i class="far fa-play-circle"></i>Regarder video
<i class="far fa-question-circle"></i>Aide
</div>
</header>
<footer>
<div class="footer">
<ul>
<li><i class="fab fa-facebook"></i></li>
<li><i class="fab fa-twitter-square"></i></li>
<li><i class="fab fa-instagram"></i></li>
<li><i class="fab fa-snapchat-square"></i></li>
</ul>
<h5>
©Khalil 2019
</h5>
</div>
</footer>
</body>
</html>
Please if you can fix this problem I'm gonna be so grateful for your help. Thanks.
I have Changed the following CSS code and menu now fixed.
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
position: relative;
display: block;
transition:all 0.6s ease; /* this will be always at normal stage not at hover*/
}
.main ul li a:hover{
background-color: #fff;
color: #000;
}
Please have a look at this at codepen
#import url('https://fonts.googleapis.com/css?family=Montserrat|Raleway');
*{
margin:0;
padding: 0;
font-family: Raleway;
}
body{
background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)),
url('1.jpg');
background-position: center;
background-size: cover;
height: 100vh;
}
.main ul{
float: right;
display: block;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
position: sticky;
}
.main ul li{
display: inline-block;
width: 150px;
}
.main ul li i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.main ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
border-radius: 7px;
position: relative;
display: block;
transition:all 0.6s ease; /* this will be always at normal stage not at hover*/
}
.main ul li a:hover{
background-color: #fff;
color: #000;
}
.main ul li.active a{
background-color: #fff;
color: #000;
}
.main ul ul li{
list-style-type: none;
display: none;
}
.main ul li:hover ul li{
display: block;
}
.login ul{
float: right;
position: fixed;
list-style-type: none;
display: inline-block;
font-size: 12px;
}
.logo img{
float: left;
width: 150px;
height: auto;
margin-top: 15px;
margin-left: 0;
}
header{
background-color: rgba(202, 211, 200,0.6);
}
.main{
max-width: 1200px;
margin: auto;
}
.title img{
width: 40%;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%,-100%);
}
.title p{
width: 40%;
position: absolute;
top: 54%;
left: 50%;
font-size: 25px;
font-family: Montserrat;
font-weight: lighter;
transform: translate(-50%,-100%);
text-align: center;
color: #F8EFBA;
}
.button{
position: absolute;
top: 60%;
left: 50%;
transform: translate(-50%,-100%);
}
.button a i{
padding-right: 5px;
color: #eccc68;
opacity: 0.6;
}
.btn{
border: 1px solid #eccc68;
border-radius: 15px;
padding: 10px 30px;
color: #fff;
font-size: 20px;
text-decoration: none;
}
.btn:hover{
background-color: #fff;
color: #000;
transition: 0.6s ease;
}
.footer{
width: 100%;
position: fixed;
bottom: 0;
background-color: rgba(0,0,0,0.4);
height: 60px;
}
.footer ul{
transform: translateX(1800px);
margin-right: 0px;
list-style-type: none;
font-size: 15px;
margin-top: 20px;
}
.footer ul li a i{
font-size: 20px;
padding-right: 5px;
color: #eccc68;
}
.footer ul li{
display: inline-block;
}
.footer h5{
font-size: 11px;
color: #eccc68;
text-align: center;
opacity: 0.7;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Trip Buddy | Your free online travel guide</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/png" href="favicon.ico">
</head>
<body>
<header>
<div class="main">
<div class="logo">
<img src="2.png">
</div>
<ul>
<li class="active"><i class="fas fa-home"></i>Accueil</li>
<li><i class="fas fa-city"></i>Villes dispo
<ul>
<li>Marrakech</li>
<li>Rabat</li>
<li>Tanger</li>
<li>Essaouira</li>
</ul>
</li>
<li><i class="fas fa-hand-holding"></i>Services</li>
<li><i class="fas fa-user-alt"></i>Contact</li>
</ul>
</div>
<div class="login">
<ul>
<li>S'inscrire</li>
<li>Se connecter</li>
</ul>
</div>
<div class="title">
<img src="2.png">
<p>Trip Buddy est ton premier accompagnant guide en ligne. Rejoignez notre nombreuse communauté et télecharger l'application sur toutes les platformes GRATUITEMENT!</p>
</div>
<div class="button">
<i class="far fa-play-circle"></i>Regarder video
<i class="far fa-question-circle"></i>Aide
</div>
</header>
<footer>
<div class="footer">
<ul>
<li><i class="fab fa-facebook"></i></li>
<li><i class="fab fa-twitter-square"></i></li>
<li><i class="fab fa-instagram"></i></li>
<li><i class="fab fa-snapchat-square"></i></li>
</ul>
<h5>
©Khalil 2019
</h5>
</div>
</footer>
</body>
</html>
The navbar-collapse collapses/disappears when clicking a menu link to an actual "page" but it doesn't collapse/disappear when clicking a "custom" menu link to scroll to a different section on the same page.
I have the navbar-collapse appearing as a full screen when toggling the Hamburger Icon. The JQuery fixes this but it still doesn't work on IOS Safari.
HERE IS MY CSS
* { cursor: pointer; }
#site-header{
height: 85px;
top: 0;
z-index: 3000;
}
.logged-in #site-header{
top: 32px;
}
#primary {
margin-top: 85px;
}
.nav {
display: block;
}
.navbar {
height: 75px;
width: 100%;
padding: 0;
background: black;
}
.navbar-nav {
float: none!important;
}
.navbar-collapse {
position: absolute;
background: black;
width: 100%;
padding-right: 30px;
padding-top: 0px;
padding-bottom: 35px;
border: 0px;
margin-top: 0px;
height: 110vh;
left: 0;
top:0;
background-size: cover;
}
.navbar-image {
position: absolute;
opacity: .2;
right: 0px;
top:0%;
margin-top: -15px;
padding-left: 30px;
padding-right: 30px;
bottom: 0;
margin: auto;
z-index: 1;
}
.navbar-image:hover, .navbar-image:active {
-webkit-transition-duration: 5.8s;
-moz-transition-duration: 5.8s;
-o-transition-duration: 5.8s;
transition-duration: 5.8s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
overflow:hidden;
-webkit-transform:rotate(360deg);
-moz-transform:rotate(360deg);
-o-transform:rotate(360deg);
}
.collapsing {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition: height .01s;
-moz-transition: height .01s;
-ms-transition: height .01s;
-o-transition: height .01s;
transition: height .01s;
}
.navbar-collapse ul {
position: absolute;
margin-left: 50px;
margin-top: 80px;
z-index: 2;
}
.navbar-collapse ul li {
margin-bottom: 10px;
text-transform: uppercase;
letter-spacing: 1px;
}
.navbar-collapse ul li a{
color: white!important;
font-family: 'Montserrat', sans-serif;
font-style: normal;
font-weight: 300;
}
HERE IS THE HTML
<header id="site-header" class="container-fluid">
<nav class="navbar fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggler disable" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="icon-bar top-menu"></span>
<span class="icon-bar mid-menu"></span>
<span class="icon-bar bottom-menu"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav">
<li class="menu-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="menu-item">
<a class="nav-link" href="#">Somthing Else</a>
</li>
</ul>
</div>
</div>
</nav>
JQUERY
(function ($) {
$(document).ready(function () {
$(".navbar-collapse ul li a").on("click", function () {
$(".navbar-collapse").collapse("hide");
});
});
})(jQuery);
How to make child element inherit parent's width using Bootstrap 4.
I need to fix download_resume block's width.
I'm using two primary js script's.
1.First function change img like hover effect
2.Second function adding sticky class to our empty_row block make it position fixed
Please look this code in wide screen devices or in codepen for understand the problem and what I want to realize
// this function change img like hover effect using js
let avatarSimple = document.querySelector(".avatar_simple");
let avatarQuantumBreak = document.querySelector(".avatar_quantum_break");
avatarQuantumBreak.style.opacity = "0";
let hover = () => {
avatarQuantumBreak.style.opacity = "1";
}
let normal = () => {
avatarQuantumBreak.style.opacity = "0";
}
// this function adding sticky class to our empty_row block make it position fixed
window.onscroll = function() {
let w = document.documentElement.clientWidth;
if (w > 940) {
var scrolled = window.pageYOffset || document.documentElement.scrollTop;
scrolled >= 20 ? document.querySelector(".empty_row").classList.add("sticky") : document.querySelector(".empty_row").classList.remove("sticky");
}
}
.other_block {
background-color:lightblue;
}
.main_wrap {
margin-top:15px;
background-color:pink;
height:600px;
}
.home_link , .main_text {
color: #fff;
font-size: 1.5em;
}
.left_block {
/*height: 60%;*/
padding: 30px 20px 20px;
box-shadow: -4px 7px 15px 1px rgba(0,0,0,.2);
}
.avatar {
position: relative;
border-radius: 50%;
display: flex;
justify-content: center;
height: 195px;
}
.avatar_simple,
.avatar_quantum_break {
position: absolute;
display: block;
text-align:center;
transition: opacity 1s ease-out;
}
.avatar .avatar_simple img,
.avatar .avatar_quantum_break img {
border-radius: 50%;
display: inline-block;
}
.info {
margin-top: 33px;
}
.text_uppercase {
text-transform: uppercase;
color: #fff;
font-size: 1.4em;
text-align: center;
margin-bottom: 15px;
}
.text_muted {
text-align: center;
opacity: 0.65;
}
.social_links {
display: flex;
justify-content: center;
}
.social_links li {
list-style-type: none;
margin: 5px 12px;
vertical-align: middle;
}
.social_links li a {
color: #fff;
cursor: pointer;
transition: all .2s ease-out;
background-color: transparent;
}
.social_links li a i {
font-size: 1.25em;
transition: all .2s ease-out;
}
.social_links li a i:hover {
opacity: 0.65;
}
.download_resume {
position:absolute;
width: 100%;
left: 0%;
padding: 30px;
margin: 0;
font-size: .875em;
background-color: #313C42;
box-shadow: -4px 7px 15px 1px rgba(0,0,0,.2);
}
.text_widget {
vertical-align: middle;
}
.text_widget a {
background-color: #DEC746 !important;
border-color: #DEC746 !important;
color: #000 !important;
font-size: 15px !important;
padding: 12px 30px !important;
border-radius: 35px !important;
}
center {
display: block;
text-align: -webkit-center;
}
.btn_link:hover, .share-btn:hover {
box-shadow: -1px 2px 4px rgba(0,0,0,.25);
}
.btn_link {
font-weight: 700 !important;
}
.sticky {
position: fixed !important;
top: 2%;
width: 285px;
}
<div class="container">
<div class="row justify-content-between">
<div class="col-lg-3 col-xl-3 any_block"><div class="empty_row left_block" style="background-color: #1FA184;">
<div class="avatar" onmouseover="hover();" onmouseout="normal();">
<span class="avatar_simple">
<img src="https://certy.px-lab.com/developer/wp-content/uploads/sites/6/2017/08/certy-programmer-1-195x195.png">
</span>
<span class="avatar_quantum_break">
<img src="https://certy.px-lab.com/developer/wp-content/uploads/sites/6/2017/08/certy-programmer-2-195x195.png">
</span>
</div>
<div class="info">
<h2 class="text_uppercase">Sergio Ramos</h2>
<p class="text_muted">Front End Developer</p>
<ul class="social_links">
<li>
<a href="#">
<i class="fa fa-facebook"></i>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-linkedin"></i>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-github"></i>
</a>
</li>
</ul>
</div>
<div class="download_resume">
<div class="text_widget">
<center>
Download CV
</center>
</div>
</div>
</div></div>
<div class="col-lg-8 col-xl-8 other_block">
<div class="main_wrap">text</div>
</div>
</div>
</div>
Setting the width to inherit isn't the best solution. When you don't have "sticky" on it does things you don't expect.
I've added an extra div to wrap your top section in question. You're really only concerned about the padding staying for that top section with your picture when you move from sticky to non-sticky. This separates it from the resume download button. Then you don't need to specify any width on that div, as it will work like it is supposed to.
HTML (I've added the "left-block-padding" div)
<div class="container">
<div class="row justify-content-between">
<div class="col-lg-3 col-xl-3 any_block"><div class="empty_row left_block" style="background-color: #1FA184;">
<div class="left-block-padding">
<div class="avatar" onmouseover="hover();" onmouseout="normal();">
<span class="avatar_simple">
<img src="https://certy.px-lab.com/developer/wp-content/uploads/sites/6/2017/08/certy-programmer-1-195x195.png">
</span>
<span class="avatar_quantum_break">
<img src="https://certy.px-lab.com/developer/wp-content/uploads/sites/6/2017/08/certy-programmer-2-195x195.png">
</span>
</div>
<div class="info">
<h2 class="text_uppercase">Sergio Ramos</h2>
<p class="text_muted">Front End Developer</p>
<ul class="social_links">
<li>
<a href="#">
<i class="fa fa-facebook"></i>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-linkedin"></i>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-github"></i>
</a>
</li>
</ul>
</div>
</div>
<div class="download_resume">
<div class="text_widget">
<center>
Download CV
</center>
</div>
</div>
</div></div>
<div class="col-lg-8 col-xl-8 other_block">
<div class="main_wrap">text</div>
</div>
</div>
</div>
CSS (added .left-block-padding and removed position:absolute; and width: 100%; from .download_resume
.other_block {
background-color:lightblue;
}
.main_wrap {
margin-top:15px;
background-color:pink;
height:600px;
}
.home_link , .main_text {
color: #fff;
font-size: 1.5em;
}
.left_block {
/*height: 60%;*/
box-shadow: -4px 7px 15px 1px rgba(0,0,0,.2);
}
.avatar {
position: relative;
border-radius: 50%;
display: flex;
justify-content: center;
height: 195px;
}
.avatar_simple,
.avatar_quantum_break {
position: absolute;
display: block;
text-align:center;
transition: opacity 1s ease-out;
}
.avatar .avatar_simple img,
.avatar .avatar_quantum_break img {
border-radius: 50%;
display: inline-block;
}
.info {
margin-top: 33px;
}
.text_uppercase {
text-transform: uppercase;
color: #fff;
font-size: 1.4em;
text-align: center;
margin-bottom: 15px;
}
.text_muted {
text-align: center;
opacity: 0.65;
}
.social_links {
display: flex;
justify-content: center;
}
.social_links li {
list-style-type: none;
margin: 5px 12px;
vertical-align: middle;
}
.social_links li a {
color: #fff;
cursor: pointer;
transition: all .2s ease-out;
background-color: transparent;
}
.social_links li a i {
font-size: 1.25em;
transition: all .2s ease-out;
}
.social_links li a i:hover {
opacity: 0.65;
}
.download_resume {
left: 0%;
padding: 30px;
margin: 0;
font-size: .875em;
background-color: #313C42;
box-shadow: -4px 7px 15px 1px rgba(0,0,0,.2);
}
.text_widget {
vertical-align: middle;
}
.text_widget a {
background-color: #DEC746 !important;
border-color: #DEC746 !important;
color: #000 !important;
font-size: 15px !important;
padding: 12px 30px !important;
border-radius: 35px !important;
}
center {
display: block;
text-align: -webkit-center;
}
.btn_link:hover, .share-btn:hover {
box-shadow: -1px 2px 4px rgba(0,0,0,.25);
}
.btn_link {
font-weight: 700 !important;
}
.sticky {
position: fixed !important;
top: 2%;
width: 285px;
}
.left-block-padding {
padding: 30px 20px 20px;
}
JS (unchanged)
// this function change img like hover effect using js
let avatarSimple = document.querySelector(".avatar_simple");
let avatarQuantumBreak = document.querySelector(".avatar_quantum_break");
avatarQuantumBreak.style.opacity = "0";
let hover = () => {
avatarQuantumBreak.style.opacity = "1";
}
let normal = () => {
avatarQuantumBreak.style.opacity = "0";
}
// this function adding sticky class to our empty_row block make it position fixed
window.onscroll = function() {
let w = document.documentElement.clientWidth;
if (w > 940) {
var scrolled = window.pageYOffset || document.documentElement.scrollTop;
scrolled >= 20 ? document.querySelector(".empty_row").classList.add("sticky") : document.querySelector(".empty_row").classList.remove("sticky");
}
}
https://codepen.io/adprocas/pen/QmLjJM
Use width:inherit to inherit parent element's width
.download_resume {
position:absolute;
width: inherit;
left: 0%;
padding: 30px;
margin: 0;
font-size: .875em;
background-color: #313C42;
box-shadow: -4px 7px 15px 1px rgba(0,0,0,.2);
}
Code sample - https://codepen.io/nagasai/pen/xWKGvW