I have a button than on hover has a dropdown menu associated with it. This works perfectly fine on chrome and I can select items from the dropdown but on Firefox the behaviour is different where the dropdown disappears as I leave the button to click on a dropdown item.
Here is my CSS and a JS fiddle attached.
button {
position:relative;
}
.flags_home_middle {
top: 68%;
right: 23%;
left: inherit;
}
.flags_item_features {
-webkit-transition-duration: .8s;
transition-duration: .8s;
opacity: 0;
visibility: hidden;
padding: 3px !important;
width: 211px;
position: absolute;
top: 51%;
left: 23%;
}
.flags_item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.flags_home_middle {
top: 68%;
right: 23%;
left: inherit;
}
.flags_item_features {
-webkit-transition-duration: .8s;
transition-duration: .8s;
opacity: 0;
visibility: hidden;
padding: 3px !important;
width: 211px;
position: absolute;
top: 51%;
left: 23%;
}
.flags_item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.btn_buy_features:hover .flags_item_features {
opacity: 1;
visibility: visible;
background: #EBEBEB;
box-shadow: 0 3px 9px -2px rgba(0, 0, 0, .5);
}
https://jsfiddle.net/3nn7pc21/
It seems to me that Firefox doesn't consider children of interactive elements with new stacking context when using hover. To overcome this I've put your whole menu alongside the button and made your container serve as a relative parent. Also I've increased the safe zone a bit using pseudo-element.
https://jsfiddle.net/3nn7pc21/4/
button {
position:relative;
}
.buy-button-wrapper
{
position: relative;
}
.flags_home_middle {
top: 68%;
right: 23%;
left: inherit;
}
.flags_item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.flags_home_middle {
top: 68%;
right: 23%;
left: inherit;
}
.flags_item_features {
-webkit-transition-duration: .8s;
transition-duration: .8s;
opacity: 0;
visibility: hidden;
padding: 3px !important;
width: 211px;
position: absolute;
top: 10px;
left: 10px;
}
.flags_item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.btn_buy_features:hover + .flags_item_features,
.flags_item_features:hover
{
opacity: 1;
visibility: visible;
background: #EBEBEB;
box-shadow: 0 3px 9px -2px rgba(0, 0, 0, .5);
}
.flags_item_features:before
{
content: "";
display: block;
position: absolute;
left: -10px;
top: -10px;
right: -10px;
bottom: -10px;
}
<div class="buy-button-wrapper">
<button type="button" class="btn-buy btn_buy_features custom_btn active" style="margin: 0 auto;">BUY</button>
<div class="flags_item flags_item_features flags_home_middle">
<div class="border_link">
<span class="country_name"> <img src="/wp-content/uploads/2017/01/1_2_2.png">US</span>
</div>
<div class="border_link">
<span class="country_name"> <img src="/wp-content/uploads/2017/01/1_2_3.png">EU</span>
</div>
<div class="border_link">
<span class="country_name"> <img src="/wp-content/uploads/2017/01/1_2_1.png">UK</span>
</div>
</div>
</div>
I don't know how appropriate is this!! But removing "will-change:transform" a default behavior of dropdown-menu (bootstrap) worked for me.
Related
I am new to programming and I want to make a website where I want to put a text to the left bottom corner of an image. How to put it there and how to let it stay there when the screen is resized. And is my code ok ? or should I change something ?
JSFIDDLE
.flex{
position: relative;
display: flex;
justify-content: space-evenly;
}
.container-one a{
position: relative;
}
img{
display: block;
width: 100%;
height: 100%;
}
.box-one{
position: absolute;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5);
height: 100%;
width: 100%;
bottom: 0px;
left: 0px;
right: 0px;
top: 0px;
opacity: 0;
transition: 0.5s ease;
}
.container-one:hover .box-one {
opacity: 1;
}
span{
text-decoration: none;
color: red;
float:
}
<div class="flex">
<div class="container-one">
<a href="#dog">
<img src="https://d1nhio0ox7pgb.cloudfront.net/_img/g_collection_png/standard/256x256/dog.png">
<div class="box-one">
<span>dog</span>
</div>
</a>
</div>
<div class="container-two">
</div>
</div>
you can do it with very simple css code.
Try this:
.box-one span {
position: absolute;
bottom: 0px;
}
You can add position: absolute with the bottom-left alignment to your .box-one span which is your text element
.box-one span {
position: absolute;
bottom: 0px;
left: 0px;
}
.flex {
position: relative;
display: flex;
justify-content: space-evenly;
}
.container-one a {
position: relative;
}
img {
display: block;
width: 100%;
height: 100%;
}
.box-one {
position: absolute;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5);
height: 100%;
width: 100%;
bottom: 0px;
left: 0px;
top: 0px;
opacity: 0;
transition: 0.5s ease;
}
.box-one span {
position: absolute;
bottom: 0px;
left: 0px;
}
.container-one:hover .box-one {
opacity: 1;
}
span {
text-decoration: none;
color: red;
}
<div class="flex">
<div class="container-one">
<a href="#dog">
<img src="https://d1nhio0ox7pgb.cloudfront.net/_img/g_collection_png/standard/256x256/dog.png">
<div class="box-one">
<span>dog</span>
</div>
</a>
</div>
<div class="container-two">
</div>
</div>
I'm trying to create a background effect using before and after pseudo elements by making it one pixel taller and wider than the actual element, but it always seems to have one extra pixel to the right or left. This only happens when the browsers is maximized (Firefox, Chrome and Edge), but does not happen when the browser has a smaller width.
*, *::before, *::after{ box-sizing: border-box; }
body {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
background-color: #111;
}
img {
max-width: 300px;
display: block;
padding: 4px;
}
.main-box {
position: relative;
}
.img-box {
padding: 0;
margin: 0;
background-color: #000;
}
.img-box::before{
content: '';
position: absolute;
top: -1px;
left: -1px;
right: -1px;
bottom: -1px;
filter: blur(10px);
z-index: -2;
}
.img-box::after{
content: '';
position: absolute;
top: -1px;
left: -1px;
right: -1px;
bottom: -1px;
z-index: -1;
}
.img-box::before, .img-box::after{
background-image: linear-gradient(45deg, #ff0000, #111, #0000ff);
opacity: 0.7;
transition: opacity ease-out 150ms;
}
.main-box:hover .img-box::after {
opacity: 1;
}
<div class="main-box">
<div class="img-box"><img src="https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" alt="keyboard"></div>
</div>
It's not quite clear in the picture, but in the browser all sides of the background-image is 1px more except for the left side where it's 2px more.
OUTPUT: Thicker line on the left
This looks like antialiasing. I guess you have either your browser's either your OS's zoom level set to something else than 100%.
Some browsers will try to round the positionning, but at some zoom level, this can't be done properly and you'll end up having one side floored and the other ceiled.
To circumvent this, you can use the translate property which should allow proper antialiasing to kick in (it will be blurry, but of the same size).
*, *::before, *::after{ box-sizing: border-box; }
body {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
background-color: #111;
}
img {
max-width: 300px;
display: block;
padding: 4px;
}
.main-box {
position: relative;
}
.img-box {
padding: 0;
margin: 0;
background-color: #000;
}
.img-box::before{
content: '';
position: absolute;
top: 0px;
left: 0px;
width: calc( 100% + 2px );
height: calc( 100% + 2px );
transform: translate(-1px,-1px);
filter: blur(10px);
z-index: -2;
}
.img-box::after{
content: '';
position: absolute;
top: 0px;
left: 0px;
width: calc( 100% + 2px );
height: calc( 100% + 2px );
transform: translate(-1px,-1px);
z-index: -1;
}
.img-box::before, .img-box::after{
background-image: linear-gradient(45deg, #ff0000, #111, #0000ff);
opacity: 0.7;
transition: opacity ease-out 150ms;
}
.main-box:hover .img-box::after {
opacity: 1;
}
<div class="main-box">
<div class="img-box"><img src="https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" alt="keyboard"></div>
</div>
I need my h1 "Мышонок" to remain fully visible when I click hamburger menu.
When I click the menu, my white h1 becomes behind it, and I can't figure out how to make it 100% visible.
I tried to mess with z-index but I was unfortunate. Noob here. Please help
#import url("https://fonts.googleapis.com/css?family=Oswald:200,300,400,500,600,700&display=swap");
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
font-family: "Oswald", sans-serif;
}
img {
width: 100%;
height: auto;
}
/* Utility */
.container {
margin: 0 auto;
max-width: 1160px;
padding: 0 20px;
overflow: hidden;
}
.overlay {
top: 0;
left: 0;
right: 0;
bottom: 0;
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.hidden {
display: none;
}
/* Home */
.showcase {
position: relative;
height: 100vh;
background-image: url(../img/homebg/bg1.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
animation: slide 18s infinite;
transition: 100ms ease-in-out;
width: 100%;
}
.showcase h1 {
font-size: 3.5rem;
font-weight: 500;
color: #fff;
padding-top: 40px;
text-transform: uppercase;
z-index: 1001;
}
#keyframes slide {
0% {
background-image: url(../img/homebg/bg1.jpg);
}
20% {
background-image: url(../img/homebg/bg2.jpg);
}
40% {
background-image: url(../img/homebg/bg3.jpg);
}
60% {
background-image: url(../img/homebg/bg4.jpg);
}
80% {
background-image: url(../img/homebg/bg5.jpg);
}
100% {
background-image: url(../img/homebg/bg1.jpg);
}
}
.menu-wrap {
position: fixed;
top: 0;
left: 0;
z-index: 1001;
width: 100%;
height: 100%;
}
.menu-wrap .toggler {
position: absolute;
top: 55px;
right: 280px;
z-index: 1002;
cursor: pointer;
width: 50px;
height: 50px;
opacity: 0;
}
.menu-wrap .hamburger {
position: absolute;
top: 55px;
right: 270px;
z-index: 1001;
width: 70px;
height: 60px;
padding: 1rem;
background: transparent;
display: flex;
align-items: center;
justify-content: center;
}
/* Hamburger Icon */
.menu-wrap .hamburger>div {
position: relative;
flex: none;
width: 100%;
height: 4px;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.4s ease;
}
.menu-wrap .hamburger>div::before,
.menu-wrap .hamburger>div::after {
content: "";
position: absolute;
z-index: 1;
top: -10px;
width: 100%;
height: 4px;
background: inherit;
}
.menu-wrap .hamburger>div::after {
top: 10px;
}
/* Toggler Animation */
.menu-wrap .toggler:checked+.hamburger>div {
transform: rotate(135deg);
}
.menu-wrap .toggler:checked+.hamburger>div:before,
.menu-wrap .toggler:checked+.hamburger>div:after {
top: 0;
transform: rotate(90deg);
}
.menu-wrap .toggler:checked:hover+.hamburger>div {
transform: rotate(225deg);
}
/* Show Menu */
.menu-wrap .toggler:checked~.menu {
visibility: visible;
}
.menu-wrap .toggler:checked~.menu>div {
transform: scale(1);
transition-duration: 0.75;
}
.menu-wrap .toggler:checked~.menu>div>div {
opacity: 1;
transition: opacity 0.1s ease 0.1s;
}
/* Menu overlay */
.menu-wrap .menu {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
visibility: hidden;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.menu-wrap .menu>div {
background: rgba(0, 0, 0, 0.5);
width: 200vw;
height: 200vw;
display: flex;
flex: none;
align-items: center;
justify-content: center;
transform: scale(0);
transition: all 0.4s ease;
border-radius: 50%;
}
.menu-wrap .menu>div>div {
text-align: center;
max-width: 90vw;
max-height: 100vh;
opacity: 0;
transition: opacity 0.4s ease;
}
.menu-wrap .menu>div>div>ul>li {
list-style: none;
font-size: 3rem;
padding: 1rem;
}
.menu-wrap .menu>div>div>ul>li>a {
color: #fff;
text-decoration: none;
}
<div class="hidden">
<img src="img/homebg/bg2.jpg" />
<img src="img/homebg/bg3.jpg" />
<img src="img/homebg/bg4.jpg" />
<img src="img/homebg/bg5.jpg" />
</div>
<!-- Home -->
<div class="showcase">
<div class="overlay">
<div class="container">
<h1>Мышонок</h1>
<!-- Hamburger -->
<div class="menu-wrap">
<input type="checkbox" class="toggler" />
<div class="hamburger">
<div></div>
</div>
<div class="menu">
<div>
<div>
<ul>
<li>Personal</li>
<li>Men</li>
<li>Women</li>
<li>Video</li>
<li>About</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I don't know what more details to add, stackoverflow, I believe I described it as much as I could
Here is What I was able to come up with to be able to solve your issue: https://jsfiddle.net/L7ac6j3v/8/
One of the main issues I think you were facing was over complicating it for yourself by using crazy z-index values like 999 to 1005 etc, you'll see I have removed or replaced alot of the values with easy to work with values like 1,2 etc
Another main issue I was seeing was your use of the position style and not having position: absolute when trying to work with the z-index of an element
As a side note a way that I like to test if elements are positioned correctly is to use cursor: pointer and pointer-events
Hope this helps :)
I cannot understand why a simple hover effect on a div won't work in IE10.
CSS:
.portfolio {
margin-bottom: 130px;
.portfolioContainer {
display: flex;
flex-wrap: wrap;
margin-left: -10px;
margin-right: -10px;
.portfolioBox {
display: flex;
width: 50%;
height: 250px;
padding: 10px;
.moreBoxInfo {
display: none;
}
.portfolioBoxLogo {
width: 50%;
background-color: $lighter_gray;
display: flex;
align-items: center;
justify-content: center;
padding: 5px;
img {
display: block;
transform: scale(0.8);
max-width: 90%;
width: 100%;
}
}
.portfolioBoxImg {
width: 50%;
background-position: center;
background-size: cover;
position: relative;
cursor: pointer;
&:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: $primary;
opacity: 0;
transition: opacity .5s;
z-index: 1;
}
.portfolioBoxText {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 20px;
opacity: 0;
transition: opacity .5s;
z-index: 2;
p {
font-size: 16px;
line-height: 20px;
text-align: left;
}
}
.more {
position: absolute;
right: 20px;
bottom: 20px;
#include fontFamilySize("HelveticaNeueThin", 36px, 42px);
cursor: pointer;
display: none;
z-index: 3;
}
&:hover {
&:before {
opacity: .95;
}
.portfolioBoxText {
opacity: 1;
}
.more {
display: block;
}
}
}
}
}
}
HTML:
<div class="portfolio">
<div class="portfolioContainer">
<div class="portfolioBox">
<div style="background-image: url( img/participadas/forcemanager-img.jpg)" class="portfolioBoxImg">
<div class="portfolioBoxText">
<p>Aplicació per accelerar les vendes en equips comercials basada en Intel·ligència Artificial.</p>
</div>
<span class="more">+</span>
</div>
</div>
</div>
</div>
This SASS code compiles perfectly well.
The expected working code should be that when I hover the div.portfilioBoxImg, the :before, .more and .portfolioBoxText should gain opacity: 1, but it won't work.
I have other hovers around the site, and they work fine, but this one doesn't.
I tried getting rid of transition, without opacity and adding display none/block, but those works on themselves, what it doesn't works is the hover effect.
Compiled CSS extracted from chrome:
.portfolio .portfolioContainer .portfolioBox .portfolioBoxImg:before
This works perfectly on IE11, Firefox, chrome...
JSFiddle: http://jsfiddle.net/vy5npu3a/
EDIT
I tried a hover within the body with the ::before, and it doesn't works either, but with an anchor a it does. Maybe some elements don't work?
The doctype html was missing. I can swear i had try it before without success, but seems like now works.
I'd like to get this effect:
But I cant move only the content, leaving fixed the container. If you see my fiddle, I'm moving all together, the content and the container.
And even I'd like to put the hover on the circle div, not in the content like it is right now, because now when the animation ends it losing the hover.
A little detail to keep in mind:
I need to update at runtime the text to display due it should be
translated depending on the language selected by the user.
Here is my fiddle
.frame {
display: flex;
background-color: green;
height: 200px;
width: 200px;
flex-direction: center;
justify-content: center;
align-items: center;
}
.oval {
display: flex;
background-color: white;
border-radius: 50px;
width: 100px;
height: 100px;
}
.box {
display: flex;
flex-direction: column;
background-color: gray;
height: 100px;
width: 100px;
position: relative;
top: 25px;
transition: top 200ms ease-in;
border-radius: 50px;
}
.box:hover {
top: -50px;
transition: top 200ms ease-in;
animation: ticker 25s cubic-bezier(1, 0, .5, 0);
}
#keyframes ticker {
0% {
margin-top: 0
}
25% {
margin-top: -30px
}
50% {
margin-top: -60px
}
75% {
margin-top: -90px
}
100% {
margin-top: 0
}
}
.box-inn {
flex: 1;
margin: 5%;
color: white;
text-align: center;
align-items: center;
}
.first {
background-color: blue;
}
.second {
background-color: red;
}
<div class="frame">
<div class="oval">
<div class="box">
<div class="box-inn first">
Text 1
</div>
<div class="box-inn second">
Text 2
</div>
</div>
</div>
</div>
You can use pseudo-elements. First hide :after with transform: translateY(100%) and overflow: hidden on parent, and on hover you translate :before for 100% and move :after to 0.
.elem {
position: relative;
width: 100px;
height: 100px;
border: 1px solid white;
color: white;
border-radius: 50%;
background: #4CA5D0;
overflow: hidden;
}
.elem:after,
.elem:before {
content: 'Top';
position: absolute;
transition: all 0.3s ease-in;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.elem:after {
content: 'Bottom';
transform: translateY(100%);
}
.elem:hover:before {
transform: translateY(-100%);
}
.elem:hover:after {
transform: translateY(0);
}
<div class="elem"></div>
If you don't want to use pseudo-elements Fiddle
If your icons are images you may want a non-pseudo element method. Here's an example using a font awesome icon to illustrate an image (fa icons can be used with pseudo elements, however)
.link {
position: relative; /* for absolute positioned children to work */
display: inline-flex;
flex-direction: column;
height: 100px; /* this method uses absolutely position chldren so..*/
width: 100px; /* ..a fixed width and height was needed */
color: white;
border-radius: 100%;
border-color: white;
border-style: solid;
border-width: 2px;
overflow: hidden; /* hides the overflowing elements */
}
.icon {
position: absolute;
top: 50%; /* vertically position icon in center in combination with transform -50% */
left: 50%; /* same deal with horizontal centering */
transform: translate(-50%, -50%); /* horizontal, vertical */
transition: all 0.2s ease;
}
.text {
position: absolute;
top: 150%; /* positions text under the .link container element */
left: 50%;
transform: translate(-50%, -50%);
transition: all 0.2s ease;
}
.link:hover .icon {
top: -50%; /* positions icon above the .link container element */
}
.link:hover .text {
top: 50%; /* moves text into center of .link container element */
}
/* styling - ignore */
body {display: flex;justify-content: center;align-items: center; height: 100vh;margin: 0;font-size: 24px;background-color: hsl(189, 72%, 45%);font-variant: small-caps;font-family: verdana;}.icon i {font-size: 40px;}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="link" href="https://jsfiddle.net/Hastig/4akmbgc1/">
<div class="icon"><i class="fa fa-home"></i></div>
<div class="text">fiddle</div>
</a>
fiddle
https://jsfiddle.net/Hastig/4akmbgc1/
Following #Nenad Vracar answer:
On:
I need to update at runtime the text to display due it should be
translated depending on the language selected by the user.
You can use data-attributes along with the attr() CSS function in the pseudo-elements' content property.
Note: Change these data-attributes with JS in your language handling logic.
.elem {
position: relative;
width: 100px;
height: 100px;
border: 1px solid white;
color: white;
border-radius: 50%;
background: #4CA5D0;
overflow: hidden;
}
.elem:after,
.elem:before {
content: attr(data-top-text);
position: absolute;
transition: all 0.3s ease-in;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.elem:after {
content: attr(data-bottom-text);
transform: translateY(100%);
}
.elem:hover:before {
transform: translateY(-100%);
}
.elem:hover:after {
transform: translateY(0);
}
<div class="elem" data-top-text="top_text" data-bottom-text="bottom_text"></div>
Another alternative is to use the :lang pseudo-class.
Using lang attribute in the element.
.elem {
position: relative;
width: 100px;
height: 100px;
border: 1px solid white;
color: white;
border-radius: 50%;
background: #4CA5D0;
overflow: hidden;
}
.elem:after,
.elem:before {
content: "top_text";
position: absolute;
transition: all 0.3s ease-in;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.elem:after {
content: "bottom_text";
transform: translateY(100%);
}
.elem:hover:before {
transform: translateY(-100%);
}
.elem:hover:after {
transform: translateY(0);
}
.elem:lang(es):before {
content: "texto_superior";
}
.elem:lang(es):after {
content: "texto_inferior";
}
<div class="elem"></div>
<div class="elem" lang="es"></div>
Changing the html lang attribute:
document.getElementById('change-lang').addEventListener('click', function() {
document.documentElement.setAttribute('lang', 'es');
});
.elem {
position: relative;
width: 100px;
height: 100px;
border: 1px solid white;
color: white;
border-radius: 50%;
background: #4CA5D0;
overflow: hidden;
}
.elem:after,
.elem:before {
content: "top_text";
position: absolute;
transition: all 0.3s ease-in;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.elem:after {
content: "bottom_text";
transform: translateY(100%);
}
.elem:hover:before {
transform: translateY(-100%);
}
.elem:hover:after {
transform: translateY(0);
}
:lang(es) .elem:before {
content: "texto_superior";
}
:lang(es) .elem:after {
content: "texto_inferior";
}
<div class="elem"></div>
<button id="change-lang">Cambiar a Español</button>