I am making buttons by using the anchor tag. I want to make an effect but it is not working as expected. pseudo-element is flowing over the button and text is also being hidden as well. But I want something like this, the pseudo-element will be in between the button and background.
section {
padding: 80px 0;
}
section.one {
background: #76B39D;
}
.button {
color: white;
margin: 10px;
font-size: 17px;
font-weight: 700;
letter-spacing: 1px;
text-transform: capitalize;
}
.button-type-1 {
border: 2px solid #fff;
padding: 10px 33px;
overflow: hidden;
position: relative;
}
.button-type-1:after {
position: absolute;
content: '';
width: 0px;
height: 0px;
background: #fff;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
border-radius: 50%;
z-index: 0;
transition: all 0.4s ease;
}
.button-type-1:hover:after {
width: 200px;
height: 200px;
}
.button-type-1:hover,
.button-type-1:focus {
text-decoration: none;
}
<section class="one">
read
</section>
I like to do, the pseudo element background will be fit to button size on hover.
And the button text will also be seen but i thing z-index is messed up somewhere or anything else.
z-index 1 your relative .button-type-1 and -1 the :after pseudo.
Also, make your button inline-block to prevent the :after element overflow
section {
padding: 80px 0;
}
section.one {
background: #76B39D;
}
.button {
color: white;
margin: 10px;
font-size: 17px;
font-weight: 700;
letter-spacing: 1px;
text-transform: capitalize;
}
.button-type-1 {
border: 2px solid #fff;
padding: 10px 33px;
overflow: hidden;
position: relative;
display: inline-block;
z-index:1;
}
.button-type-1:after {
position: absolute;
content: '';
width: 0px;
height: 0px;
background: #fff;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
border-radius: 50%;
z-index: -1;
transition: all 0.4s ease;
}
.button-type-1:hover:after {
width: 200px;
height: 200px;
}
.button-type-1:hover,
.button-type-1:focus {
text-decoration: none;
color:#000;
}
<section class="one">
read
</section>
Related
I designed a blue button with a white text on it, but the blue effect on the button prevents the white text and destroys the text. How can I complete the text without destroying the effect?
.button {
position: relative;
top: -250px;
left: 200px;
display: inline-block;
text-decoration: none;
text-transform: uppercase;
color: #fff;
outline: 2px solid #0059f3;
padding: 30px 60px;
overflow: hidden;
transition: color 1s;
}
.button:hover {
color: #0059f3;
}
.button::before {
content: '';
position: absolute;
top: 0;
left: -50px;
z-index: 0;
width: 150%;
height: 100%;
background-color: #0059f3;
transform: scaleX(0) skewX(35deg);
transform-origin: left;
transition: transform 1s;
}
.button:hover::before {
transform: scaleX(1) skewX(35deg);
}
It's hard to explain this. I'm trying to do something like this:
https://codepen.io/pen/yLBaJOq
.button {
position: relative;
display: inline-block;
padding: 20px;
line-height: 10px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
border: 9px solid black;
border-radius: 55px;
transition: all 0.35s ease-in-out;
color: black;
cursor: pointer;
overflow: hidden;
z-index: 1;
background-color: transparent;
}
.button:before {
content: '';
display: block;
position: absolute;
background-color: red;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-30deg);
transform-origin: center;
width: calc(100% + 30px);
height: 0;
padding-top: 0%;
transition: all 0.35s ease-in-out;
z-index: -1;
}
.button:hover {
color: #fff;
border: 9px solid red;
}
.button:hover:before {
padding-top: 200%;
}
But there's a thin line between the border and the element. Like the pseudo-element :before is not filling out the parent 100%. Image of what I mean:
It's happening in all browsers I'm trying (Chrome, FF, Safari, all Mac).
So I'm wondering if I can prevent this from happening, while still keeping a similar hover effect.
I could of course just use the transition on the background color and scrap the idea with the pseudo-element as the background.
Add background color to the button hover.
Change:
.button:hover {
color: #fff;
border: 9px solid red;
}
to:
.button:hover {
color: #fff;
border: 9px solid red;
background-color: red;
}
.button {
position: relative;
display: inline-block;
padding: 20px;
line-height: 10px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
border: 9px solid black;
border-radius: 55px;
transition: all 0.35s ease-in-out;
color: black;
cursor: pointer;
overflow: hidden;
z-index: 1;
background-color: transparent;
}
.button:before {
content: '';
display: block;
position: absolute;
background-color: red;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-30deg);
transform-origin: center;
width: calc(100% + 30px);
height: 0;
padding-top: 0%;
transition: all 0.35s ease-in-out;
z-index: -1;
}
.button:hover {
color: #fff;
border: 9px solid red;
background: red;
}
.button:hover:before {
padding-top: 200%;
}
<div class="button">WOAH</div>
The parent's background-color and the border-radius is hidden behind the pseudo element. Why is the pseudo element not behind the parent even though it has a z-index of -1?
.btn {
text-decoration: none;
background-color: royalblue;
font-family: sans-serif;
font-weight: bold;
border-radius: 5px;
color: white;
display: inline-block;
padding: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.btn::after {
content: "";
display: inline-block;
width: 100%;
height: 100%;
background-color: cornflowerblue;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Download free app
The culprit is the transform property that create a stacking context thus your pseudo element will painted inside this stacking context and will logically be above the background whataver the z-index you will use.
Remove transform to see the difference. I increased the border-radius and changed the color to better see.
.btn {
text-decoration: none;
background-color: red;
font-family: sans-serif;
font-weight: bold;
border-radius: 50px;
color: white;
display: inline-block;
padding: 20px;
position: absolute;
top: 50%;
left: 50%;
}
.btn::after {
content: "";
display: inline-block;
width: 100%;
height: 100%;
background-color: cornflowerblue;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Download free app
In case you want the pseudo element to be below the parent you should avoid any properties that create a stacking context or it will be impossible.
Or you consider another pseudo element to create the background layer and you will be able to control the stacking like you want:
.btn {
text-decoration: none;
font-family: sans-serif;
font-weight: bold;
color: white;
padding: 20px;
position: absolute;
transform:translate(-50%,-50%);
top: 50%;
left: 50%;
}
.btn::before,
.btn::after{
content: "";
position: absolute;
top: 0;
left: 0;
right:0;
bottom:0;
z-index:-1;
}
.btn::before {
background-color: cornflowerblue;
}
.btn::after {
background-color: red;
border-radius: 50px;
}
Download free app
Some related questions:
Why elements with z-index can never cover its child?
Is there any way to place z-index according not to its parent element
You just need to add overflow: hidden; to the parent element.
.btn {
text-decoration: none;
background-color: royalblue;
font-family: sans-serif;
font-weight: bold;
border-radius: 5px;
color: white;
display: inline-block;
padding: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
}
.btn::after {
content: "";
display: inline-block;
width: 100%;
height: 100%;
background-color: cornflowerblue;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Download free app
Im having a very annoying problem in Shopify. My banners were working fine but all of a sudden this class called "row" came up and is pushing my banner off to the side on both mobile and desktop. I cant get my banners to work correctly, I went through my entire code to see if I had any errors and I do not, I tried to look for a ".row" that could be messing up everything but its only gridlock .row and that is something I dont feel I should be messing with, as im not sure what it does. Anyhow, thank you for your time!
Any help is greatly appreciated!
Problem
What I see as the issue
CSS
.bannerheadercontainer {
width: 100vw;
position: relative;
top: 0px;
left: calc(-50vw + 50%);
display: table;
padding: 0px;
margin: 0px;
}
.bannercontainer {
position: relative;
width: 100%;
}
.bannercontainer .btnstyle {
font-weight: bold;
position: absolute;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-appearance: none;
color: white;
font-size: 15px;
font-size: 4vw;
border: none;
border-radius: 0px! important;
height: 16%;
text-align: center;
line-height: 0vw;
cursor: pointer;
}
.bannercontainer .imgstyle {
position: absolute;
}
.bannercontainer .btnstyle span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.bannercontainer .btnstyle span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.bannercontainer .btnstyle:hover span {
padding-right: 25px;
}
.bannercontainer .btnstyle:hover span:after {
opacity: 1;
right: 0;
}
.bannercontainer .btnstyleDesktop {
position: absolute;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-appearance: none;
color: white;
font-weight: bold;
font-size: 8px;
font-size: 1.5vw;
border: none;
border-radius: 0px! important;
height: 12%;
text-align: center;
line-height: 0vw;
cursor: pointer;
}
.bannercontainer .btnstyleDesktop span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.bannercontainer .btnstyleDesktop span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.bannercontainer .btnstyleDesktop:hover span {
padding-right: 25px;
}
.bannercontainer .btnstyleDesktop:hover span:after {
opacity: 1;
right: 0;
}
.bannerimg {
filter: brightness(30%);
}
/*------ CSS MOBILE ONLY -----*/
#media only screen and (max-width: 599px) {
.bannerheadercontainer {
top: -10px;
}
.pagetitle {
font-size: 18px !important;
}
.overlaybanner {
top: -1px;
height: 98%;
}
.index-banner {
height: 300px !important;
background-size: 200% 100%;
background-repeat: no-repeat;
}
.styc-container {
width: 100%;
}
.index-gray-section-style {
background-color: #F9F9F9;
min-height: 390px;
width: 100%;
}
.index-gray-section-connected {
background-color: #F9F9F9;
min-height: 390px;
width: 100%;
}
}
HTML CODE
<!----START BANNER----->
<div id="content-desktop">
<div class="bannerheadercontainer">
<img style="width: 100%;" class="bannerimg" src="https://cdn.shopify.com/s/files/1/0025/8719/7497/files/ecobanner-compressor_2048x2048.png?v=1529095445">
<div class="overlayheaderbanner"></div>
<div class="pagetitle">ECO-FRIENDLY</div>
</div>
</div>
<div id="content-mobile">
<div class="bannerheadercontainer">
<img style="width: 100%;" class="bannerimg" src="https://cdn.shopify.com/s/files/1/0025/8719/7497/files/eco-compressor_large.png?v=1529427950">
<div style="top: 0px; height: 97%;" class="overlayheaderbanner"></div>
<div class="pagetitle">ECO-FRIENDLY</div>
</div>
</div>
<!----END BANNER----->
Change width '100vw to 100%' in your code, it will work
.bannerheadercontainer { width: 100%;}
I have a quite simple website. It scans for pictures via php and then displays them one at a time with two buttons on top. The bottons are used to switch back and forth between them.
On the very top of the page there are a couple of links, but I can not click them. When I double klick them, the picture gets highlighted instead of the text my cursor is above. I have tried it without js and php and the issue is still there.
I am not very experienced in HTML. I think it might be something about the z-index, but I cannot fix it.
body {
background-color: #FFFFFFf
}
.menup1 {
float: left;
padding-left: 5.5%;
box-sizing: border-box;
font-size: 35px;
background: #fffff;
color: black;
}
a {
color: black;
cursor: pointer;
}
p {
color: black;
}
.listelemt {}
ul {
float: left;
font-size: 40px;
padding-top: 10px;
}
ul li {
padding-top: 15px;
}
.container {
position: relative;
width: 100%;
padding-top: 200px;
}
.container .btnF {
position: absolute;
top: 50%;
left: 50%;
transform: translate(600%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
.container .btnB {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-675%, -50%);
-ms-transform: translate(105%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
<div class="menup1">Vorspeise</div>
<div class="menup1">Suppen</div>
<div class="menup1">Dessert</div>
<div class="menup1">Kuchen</div>
<div class="menup1">Hauptgänge</div>
<div class="menup1">Konditorei</div>
<div class="container">
<img id="rezept" src="1.jpg" height=auto width=100%/>
<button class="btnF" id="btnF">+</button>
<button class="btnB" id="btnB">-</button>
</div>
I hope you can help me out here. I could manage to work out all the js and php things involved, but languages that don't follow programming rules... Not my best part.
The reason you have the box over the links is the floats aren't being cleared. That means the box that contains the links collapses, which is probably why you need to add so much padding. If you add clear: both to the container you will be able to click the links.
If you want to keep everything else the same I suggest adding a wrapper around the menu and setting position: relative, then you can give that a z-index greater than the container.
The menu buttons which are both position: absolute then need higher z-index too.
.menu {
position: relative;
z-index: 2;
}
.menup1 {
float: left;
padding-left: 5.5%;
box-sizing: border-box;
font-size: 35px;
background: #fffff;
color: black;
}
a {
color: black;
cursor: pointer;
}
p {
color: black;
}
.listelemt {}
ul {
float: left;
font-size: 40px;
padding-top: 10px;
}
ul li {
padding-top: 15px;
}
.container {
position: relative;
z-index: 1;
width: 100%;
padding-top: 200px;
}
.container .btnF {
position: absolute;
z-index: 3;
top: 50%;
left: 50%;
transform: translate(600%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
.container .btnB {
position: absolute;
z-index: 4;
top: 50%;
left: 50%;
transform: translate(-675%, -50%);
-ms-transform: translate(105%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
<div class="menu">
<div class="menup1">Vorspeise</div>
<div class="menup1">Suppen</div>
<div class="menup1">Dessert</div>
<div class="menup1">Kuchen</div>
<div class="menup1">Hauptgänge</div>
<div class="menup1">Konditorei</div>
</div>
<div class="container">
<img id="rezept" src="1.jpg" height=auto width=100%/>
<button class="btnF" id="btnF">+</button>
<button class="btnB" id="btnB">-</button>
</div>
The problem isn't with z-index, but rather that your container is overlapping your menu items. To correct this, replace padding-top: 200px with margin-top: 200px, and give the container float: left. Alternatively, if you don't want to add any 'offset' with your container, you can clear the float before initialising it with clear: left on the container.
Also note that both your body and .menup1 have invalid background-colours; when specifying hex codes, you must either specify three, four or six letters/digits. Five is invalid.
Both of these have been fixed in the following:
body {
background-color: #ffffff;
}
.menup1 {
float: left;
padding-left: 5.5%;
box-sizing: border-box;
font-size: 35px;
background: #ffffff;
color: black;
}
a {
color: black;
cursor: pointer;
}
p {
color: black;
}
.listelemt {}
ul {
float: left;
font-size: 40px;
padding-top: 10px;
}
ul li {
padding-top: 15px;
}
.container {
position: relative;
float: left;
width: 100%;
margin-top: 200px;
}
.container .btnF {
position: absolute;
top: 50%;
left: 50%;
transform: translate(600%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
.container .btnB {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-675%, -50%);
-ms-transform: translate(105%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 6px 12px;
border: none;
cursor: pointer;
border-radius: 1px;
height: 50px;
width: 50px;
}
<div class="menup1">Vorspeise</div>
<div class="menup1">Suppen</div>
<div class="menup1">Dessert</div>
<div class="menup1">Kuchen</div>
<div class="menup1">Hauptgänge</div>
<div class="menup1">Konditorei</div>
<div class="container">
<img id="rezept" src="1.jpg" height=auto width=100%/>
<button class="btnF" id="btnF">+</button>
<button class="btnB" id="btnB">-</button>
</div>