I am having a problem with an element when I use the translate-y in active state, it makes the background-image disappear. Click the element and you will see the image disappear.
The Css:
.glyphsblock i {
display: inline-block;
position: relative;
width: 38px;
height: 38px;
background-size: contain;
background-repeat: no-repeat;
background-position: center, center;
border: 1px solid #fff;
margin: 1px;
flex-shrink: 0;
cursor: pointer;
transition: all ease 0.1s;
}
.glyphsblock i:before {
background: radial-gradient(#8ed3c8, #224945);
content: " ";
width: 100%;
height: 100%;
position: absolute;
z-index: -1;
top: 0;
left: 0;
}
.glyphsblock i:active {
transform: translateY(2px);
}
.glyph-A {
background-image: url(https://atlasdatabase.github.io/glyphs/a.png);
}
HTML Code:
<div class="glyphsblock">
<i class="glyph-A"></i>
</div>
Also a jsfiddle of the issue: https://jsfiddle.net/go0tbb53/
Refactor your CSS to remove the negative z-index, which can produce unpredictable results. This is what was causing the transform to glitch and hide the glyph icon.
I've adjusted your snippet so now the i itself has the radial gradient, and the ::before pseudo-element is laying the glyph graphic on top of it.
You can see it working below:
.glyphsblock i {
background: radial-gradient(#8ed3c8, #224945);
display: inline-block;
position: relative;
width: 38px;
height: 38px;
border: 1px solid #fff;
margin: 1px;
flex-shrink: 0;
cursor: pointer;
transition: all ease 0.1s;
}
.glyphsblock i::before {
background-size: contain;
background-repeat: no-repeat;
background-position: center, center;
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.glyphsblock i:active {
transform: translateY(2px);
}
.glyph-A::before {
background-image: url(https://atlasdatabase.github.io/glyphs/a.png);
}
<div class="glyphsblock">
<i class="glyph-A"></i>
</div>
This may not be totally conventional, but I changed your jsfiddle to use a sized div for the background and an image for the icon itself. If you want to use multiple icons, simply make a larger wrapper div for multiple of what is currently called glyphsblock.
Also, my solution doesn't have any javascript, which is helpful :)
.bg-grad {
background: radial-gradient(#8ed3c8, #224945);
width: 38px;
height: 38px;
z-index: -1;
position: absolute;
}
.glyphsblock:active {
transform: translateY(2px);
cursor: pointer;
transition: all ease 0.1s;
}
<div class="glyphsblock">
<div class="bg-grad">
</div>
<img src="https://atlasdatabase.github.io/glyphs/a.png" height=38px width=38px/>
</div>
Related
I'm having troubles getting a z-index value element with a higher integer to place over another.
This is the issue I am facing.
The bottom half of the register button is being overlapped by the background image.
The code below has been adjusted a bit to only show the code that is being used here. You can see the full site by visiting: https://stangline.com/.
Here is the code:
CSS
.buttonFrame {
margin: 80px auto 50px auto;
display: block;
z-index: 4;
position: relative;
}
.buttonList {
display: inline-block;
vertical-align: top;
}
.homeButton {
font-size: 2rem;
text-decoration: none;
text-transform: uppercase;
letter-spacing: .2rem;
padding: 20px;
cursor: pointer;
box-sizing: border-box;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
position: relative;
z-index: 4;
}
#homeRight {
width: 60%;
height: 100%;
position: absolute;
right: 0;
top: 0;
display: block;
z-index: 2;
}
#homeRightImgFill {
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
width: 95%;
position: relative;
margin: 0 auto;
padding-top: 50%;
z-index: 2;
}
HTML
<div class="buttonFrame">
<a href="/forums" class="homeButton homeButtonGradient buttonList">
Visit Forum
</a>
<a href="/register/" class="homeButton buttonList homeButtonBlue p-navgroup-link--register" data-xf-click="overlay" data-follow-redirects="on">
<span>Register</span>
</a>
</div>
</div>
</div>
</div><div class="homeCont" id="homeRight">
<div id="homeRightImgFill"></div>
</div>
Apply z-index:4 on homeCont class
I don't understand why in the code below, the link hover effect starts from the middle instead of going from left to right. Can someone please explain why this happens?
.orange-link {
color: orange;
position: relative;
text-decoration: none;
}
.orange-link:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
background: orange;
bottom: 0;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.orange-link:hover:before,
.orange-link:focus:before {
transform: scaleX(1);
}
<p>Visit the official rules <a class="orange-link" href="#">here</a> on how to send in a write-in entry.</p>
It's because the default origin of CSS transforms is the center of the element.
"By default it is at the center of the element and can be moved. It is used by several transforms, like rotations, scaling or skewing, that need a specific point as a parameter."
— https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transforms/Using_CSS_transforms
The line spans the full width, but is scaled to 0 (from the center) to start. Then, on hover, the line is scaled back up to it's original full width.
You need to change the transform-origin so that it starts from the left:
.orange-link {
color: orange;
position: relative;
text-decoration: none;
}
.orange-link:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
background: orange;
bottom: 0;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
transform-origin:left bottom;
}
.orange-link:hover:before,
.orange-link:focus:before {
transform: scaleX(1);
}
<p class="read-or-listen-to-excerpt">
Visit the official rules <a class="orange-link" href="#">here</a> on how to send in a write-in entry.
</p>
You need to add transform-origin: top left; to .orange-link:before
Fiddle
Unless you specify the transform-origin, it will default to the center.
It is happening because you are scaling the element. It scales from the middle because the origin is in the middle (by default). As seen here
By default, the origin of a transform is "50% 50%", which is exactly in the center of any given element.
The possible fix can be to use the width
.orange-link {
color: orange;
position: relative;
text-decoration: none;
}
.orange-link::before {
content: "";
position: absolute;
width: 100%;
height: 3px;
left: 0 !important;
background: orange;
bottom: 0;
width: 0%;
border-radius: 5px;
transition: 0.25s linear;
}
.orange-link:hover::before,
.orange-link:focus::before {
width: 100%;
}
.orange-link {
color: orange;
position: relative;
text-decoration: none;
}
.orange-link::before {
content: "";
position: absolute;
width: 100%;
height: 3px;
left: 0 !important;
background: orange;
bottom: 0;
width: 0%;
border-radius: 5px;
transition: 0.25s linear;
}
.orange-link:hover::before,
.orange-link:focus::before {
width: 100%;
}
<p class="read-or-listen-to-excerpt">
Visit the official rules <a class="orange-link" href="#">here</a> on how to send in a write-in entry.
</p>
Or you can even shift the origin by transform-origin: bottom left; and do this
.orange-link {
color: orange;
position: relative;
text-decoration: none;
}
.orange-link:before {
content: "";
position: absolute;
width: 100%;
height: 3px;
background: orange;
bottom: 0;
transform-origin: bottom left;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.orange-link:hover:before,
.orange-link:focus:before {
transform: scaleX(1);
}
<p class="read-or-listen-to-excerpt">
Visit the official rules <a class="orange-link" href="#">here</a> on how to send in a write-in entry.
</p>
I'm trying to achieve a drop down cover effect (Not sure how it's really called) with the following code:
.new_events_list {
position: absolute;
width: 26%;
height: 28vh;
background-color: #323642;
cursor: pointer;
}
#new_events_list_effect {
background-color: #ee5f95;
width: 100%;
opacity: 0.5;
top: -100%;
transition: 0.5s;
}
div.new_events_list:hover #new_events_list_effect {
top: 0%;
transition: 0.5s;
}
div.new_events_list:hover img {
filter: grayscale(0.5);
transition: 1s;
}
<div class="new_events_list" style="overflow: hidden;border-radius: 10px;">
<img class="new_events_list" id="photo1" src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" alt="event_list_1" style=" object-fit: cover; width: 100%;border-radius: 10px;">
<div class="new_events_list" id="new_events_list_effect">
</div>
</div>
The problem that I'm facing is that once you hover over the photo the pink block drops down with the corners visible which only disappear after a second or so. Could anyone explain to me how I could possibly drop down the pink coloured div without the corners being visible?
Thank you very much for your help in advance.
The following code should work:
.new_events_list {
position: relative;
width: 26%;
backgorund-color: black;
border-radius: 10px;
overflow: hidden;
}
.image {
width: 100%;
}
.new_events_list_effect {
position: absolute;
height: 100%;
width: 100%;
background-color: #ee5f95;
opacity: 0.5;
top: -100%;
transition: 0.5s;
border-radius: 10px;
}
.new_events_list:hover .new_events_list_effect {
top: 0%;
transition: 0.5s;
}
<div class="new_events_list">
<img src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" class="image">
<div class="new_events_list_effect"></div>
</div>
I have an image, with text on top. When I rollover the Image I want the opacity of the background image to lower, but not the opacity for the text above it.
I thought that since the text was in a span i could simply tell the span to have the opacity: 1 !important; however that doesn't seem to do the trick. Can anyone help?
Here is the JSFiddle: https://jsfiddle.net/zerojjc/xrwao8n9/
HTML:
<div class="boxThird">
<a class="btnBox boxOne" href="<?php bloginfo('url'); ?>/" title="About Heath, Fania & Co"><span>About</span></a>
</div>
CSS:
.boxThird {
float: left;
width: 33.33%;
height: 400px;
background: #000;
}
.boxThird span {
margin-left: 25px;
position: relative;
top: 344px;
text-decoration: none;
border-bottom: 1px solid #fff;
}
.btnBox {
display: block;
text-align: left;
color: #fff;
text-shadow: 0px 0px 2px #555;
text-transform: uppercase;
text-decoration: none;
font-weight: 400;
font-size: 2em;
letter-spacing: .125em;
}
.boxOne {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
}
.boxOne {
background-image: url(https://i.imgur.com/izS0fLZ.jpg);
}
.boxOne:hover{
opacity: 0.8;
}
.boxOne:hover span{
opacity: 1 !important;
}
Opacity cascades, which means that if you have a span inside a div and they both have 0.8 opacity, the child-span would actually have 80% opacity of the parents 80% opacity (so IDK, 64% opacity). So by setting opacity: 1 to your span, you basically set it to the parents 0.8 opacity.
To prevent this, you can move the background image into a :before pseudo element and just change the :before opacity.
You can see a working example here:
https://jsfiddle.net/xr06hby2/
Relevant CSS:
.boxOne {
position: relative;
}
.boxOne:before {
content: '';
background-image: url(https://i.imgur.com/izS0fLZ.jpg);
background-position: center;
background-size: cover;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 1;
transition: opacity 0.3s;
}
.boxOne:hover:before{
opacity: 0.3;
}
Does anybody know how to algin a line under my text automatically to all?
here is my animation
<div class="line"><div>behance.net</div>
</div>
<br>
<div class="line"><div>google.pl</div>
</div>
<br>
<div class="line"><div>twitter.com</div>
</div></br>
CSS
.line{
font-family:Tahoma;
width:0px;
position: absolute;
background:black;
transition:width 0.4s ease ;
}
div:hover{
position: absolute;
width:86px;
}
.line div{
background:#fff;
position:relative;
bottom:1px;
}
In the first example, everything works fine, the width of line is ok, but in other no.
You can try this - DEMO
HTML
<div class="line">behance.net <span></span></div> <br />
<div class="line">google.pl <span></span></div> <br />
<div class="line">twitter.com <span></span></div> <br />
CSS
.line {
font: 400 1em Tahoma;
margin: 5px;
display: inline-block;
overflow: hidden;
padding: 2px 0;
position: relative;
}
.line span {
display: block;
position: absolute;
left: -90px;
bottom: 1px;
height: 1px;
width: 100%;
background: #c00;
-webkit-transition: all .4s;
}
.line:hover span {
left: 0;
}
Another solution with less markup:
demo
<div class='line'>behance.net</div><br>
<div class='line'>google.pl</div><br>
<div class='line'>twitter.com</div><br>
CSS:
.line {
display: inline-block;
position: relative;
background-position: -85px 0;
transition: 1s;
cursor: pointer;
}
.line:before {
position: absolute;
right: 0; top: 0; bottom: 0; left: 0;
background: linear-gradient(0deg, crimson 1px, transparent 1px) no-repeat;
background-position: inherit;
background-size: 100% 100%;
color: transparent;
content: '';
}
.line:hover { background-position: 0 0; }
Note:
My demo uses -prefix-free which adds prefixes as needed. WebKit browsers still need prefixes for transitions and gradients. You'll have to add these yourself in your code. When you do, please remember to always put the unprefixed ones last!