Overflow: hidden not being filled 100% by psuedo element? - html

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>

Related

Hover Effect turns off text

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);
}

Hover over div buttons with pseudo class doesn't sync correctly

I'm trying to create a transition for both an div button and a pseudo element, but for some reason, these transitions appear to be out of sync with each other, resulting in the pseudo element reaching a background color before the div does. I've tried various combinations of style rules, but I never managed to accomplish an ease-in-out transition to work correctly.
.tracking__history {
display: flex;
justify-content: flex-start;
align-items: center;
}
.skew-btn-left {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 120px;
font-size: 20px;
color: #2E8DEF;
background: #0000;
border-top: 5px solid #13bcfa;
border-left: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
}
.skew-btn-left::after {
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
margin-top: -5px;
margin-left: -5px;
background: #0000;
border-top: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
border-right: 5px solid #13bcfa;
transform-origin: top left;
-ms-transform: skew(30deg, 0deg);
-webkit-transform: skew(30deg, 0deg);
transform: skew(30deg, 0deg);
transition: background 1s;
}
.skew-btn-right {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 120px;
margin-left: 40px;
font-size: 20px;
color: #13bcfa;
background: #0000;
border-top: 5px solid #13bcfa;
border-right: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
transition: all .5s;
}
.skew-btn-right::after {
content: " ";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
margin-top: -5px;
margin-left: -5px;
background: #0000;
border-top: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
border-left: 5px solid #13bcfa;
transform-origin: bottom left;
-ms-transform: skew(30deg, 0deg);
-webkit-transform: skew(30deg, 0deg);
transform: skew(30deg, 0deg);
}
div.skew-btn-right:hover,
div.skew-btn-left:hover,
div.skew-btn-right:hover.skew-btn-right::after,
div.skew-btn-left:hover.skew-btn-left::after {
background: #13bcfa;
}
.skew-btn-left a, .skew-btn-right a {
display: flex;
justify-content: center;
align-items: center;
padding: 5px 0px;
text-decoration: none;
color: #13bcfa;
text-transform: uppercase;
}
.skew-btn-left:hover a, .skew-btn-right:hover a {
color: #fff;
}
<div class="tracking__history">
<div class="skew-btn-left">
Tracking
</div>
<div class="skew-btn-right">
History
</div>
</div>
You're transitioning at different speeds, you're also transitioning all attributes which in this case involves things you aren't trying to transition on the pseudo-elements so they're lagging. Sync up your transitions and specify that you're targeting the color and background attributes and you should be good. I simplified your code a bit and if you don't want to transition the text color you can just remove it from the transition.
.tracking__history {
display: flex;
justify-content: flex-start;
align-items: center;
}
.skew-btn-left {
display: flex;
justify-content: center;
align-items: center;
padding: 5px 0px;
text-decoration: none;
color: #13bcfa;
text-transform: uppercase;
position: relative;
width: 120px;
font-size: 20px;
background: white;
border-top: 5px solid #13bcfa;
border-left: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
transition: background 0.5s linear, color 0.5s linear;
}
.skew-btn-left::after {
content: "";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
margin-top: -5px;
margin-left: -2px;
background: white;
color: white;
border-top: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
border-right: 5px solid #13bcfa;
transform-origin: top left;
-ms-transform: skew(30deg, 0deg);
-webkit-transform: skew(30deg, 0deg);
transform: skew(30deg, 0deg);
transition: background 0.5s linear, color 0.5s linear;
}
.skew-btn-right {
display: flex;
justify-content: center;
align-items: center;
padding: 5px 0px;
text-decoration: none;
color: #13bcfa;
text-transform: uppercase;
position: relative;
width: 120px;
margin-left: 40px;
font-size: 20px;
background: white;
border-top: 5px solid #13bcfa;
border-right: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
transition: background 0.5s linear, color 0.5s linear;
}
.skew-btn-right::after {
content: "";
position: absolute;
display: block;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
margin-top: -5px;
margin-left: -5px;
background: white;
color: white;
border-top: 5px solid #13bcfa;
border-bottom: 5px solid #13bcfa;
border-left: 5px solid #13bcfa;
transform-origin: bottom left;
-ms-transform: skew(30deg, 0deg);
-webkit-transform: skew(30deg, 0deg);
transform: skew(30deg, 0deg);
transition: background 0.5s linear, color 0.5s linear;
}
.skew-btn-right:hover,
.skew-btn-left:hover,
.skew-btn-right:hover.skew-btn-right::after,
.skew-btn-left:hover.skew-btn-left::after {
background: #13bcfa;
color: white;
transition: background 0.5s linear, color 0.5s linear;
}
<div class="tracking__history">
<a class="skew-btn-left" href="">Tracking</a>
<a class="skew-btn-right" href="">History</a>
</div>
Here is another idea with less of code:
.tracking__history {
display: flex;
}
.tracking__history a {
padding: 10px;
position: relative;
z-index: 0;
font-size: 20px;
color: #13bcfa;
text-transform: uppercase;
text-decoration: none;
overflow: hidden;
transition: .2s;
}
.tracking__history a:hover {
color: #fff;
}
.tracking__history a:before {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border: 5px solid #13bcfa;
transform: skewX(25deg); /* control the curvature here */
transition: inherit;
}
.tracking__history a:hover:before {
background: #13bcfa;
}
.tracking__history a:first-child {
padding-right: 30px;
margin-right: -5px;
border-left: 5px solid #13bcfa;
}
.tracking__history a:last-child {
padding-left: 30px;
margin-left: -5px;
border-right: 5px solid #13bcfa;
}
.tracking__history a:first-child:before {
border-left: none;
transform-origin: bottom;
}
.tracking__history a:last-child:before {
border-right: none;
transform-origin: top;
}
<div class="tracking__history">
Tracking
History
</div>
I tried with your buttons, but couldn't. Maybe you'll find these button as a good alternative (needs customizing). From How do I create a trapezoidal button using CSS? and CSS Trapezoid Button With Solid Border
.trapezoid {
width: 230px;
text-align: center;
height: 0;
position: relative;
border-right: 50px solid transparent;
border-top: 40px solid #2963BD;
border-left: 50px solid transparent;
box-sizing: content-box;
transition: all 1s;
}
.trapezoid span {
position: absolute;
top: -30px;
left: 25%;
color: #fff;
}
.trapezoid:hover {
border-top-color: red;
}
.btn {
width: 100px;
height: 50px;
background: red;
float: left;
transition: all 1s;
color: white;
}
.rit {
float: left;
width: 0;
height: 0;
border-top: 50px solid red;
border-right: 100px solid transparent;
transition: all 1s;
}
.wrapper:hover .btn {
background: blue;
}
.wrapper:hover .rit {
border-top-color: blue;
}
button 1:
<div class="trapezoid"><span>Trapezoid Button</span></div>
<hr> button 2:
<span class="wrapper">
<div class="btn">Content</div>
<div class="rit"></div>
</span>

How to replace <b> </b> tags with a circle

I was told they should not be in there, but how do I remove them?
https://jsfiddle.net/jqzs6d3o/
That is all I am doing in the code.
Removing the <b> </b> tags from the html it.
How would that be done?
Is this something hard to do?
Removing <b></b> removes the blue circle. I want to keep the circle and remove <b></b>
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 22px;
left: 5px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
Added some styles #circle ID and changed your positioning a bit of .exitnew Also made b display: none; Check the changes below.
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 17px;
left: -1px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
display: none;
box-sizing: border-box;
position: relative;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
#circle {
background-color:#fff;
border-width: 2rem;
border:4px solid darkblue;
height:45px;
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
width: 45px;
margin-left: 1rem;
position: absolute;
}
<button class="exitnew" id="circle" type="button" aria-label="Close"><b></b></button>
You can utilize the button itself as the circle.
With this you’ll have cleaner code where you can just completely remove b tag without losing the circle.
.exitnew {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 38px;
height: 40px;
border: 5px solid blue;
border-radius: 50%;
}
Here’s the changes I made.
https://jsfiddle.net/Lnbuxvc0/

Transform: Translate Imprecise In Firefox?

Codepen
I just created a custom selection pop-up. Now inspecting it in other browsers, I can't avoid, but notice the little offset of the white "dot", inside the radio button, Firefox renders. Chrome and Edge will display it just fine, but Firefow won't. And rather out of curiosity I'd like to know, why's that? And how to avoid?
The "dot":
&::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
Entire radio button:
input[type=radio] {
position: relative;
height: 24px;
width: 24px;
margin: 0;
border-radius: 50%;
border: solid 1px var(--light-contrast);
background-color: var(--light);
appearance: none;
cursor: pointer;
&:checked {
border-color: var(--accent);
background-color: var(--accent);
}
&:focus {
outline: 0;
}
&::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
}
Whole snippet:
:root {
--dark: #212121;
--dark-contrast: #424242;
--light: #fafafa;
--light-contrast: #cfd8dc;
--accent: #2196f3;
}
*,
::after,
::before {
box-sizing: border-box;
}
html {
font-family: 'Roboto', sans-serif;
font-size: 1rem;
line-height: 1.5;
}
body {
display: grid;
place-items: center;
height: 100vh;
margin: 0;
background-color: var(--dark);
}
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.select {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
max-width: 300px;
background-color: var(--dark-contrast);
color: #fff;
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.25);
cursor: pointer;
user-select: none;
padding: 1.25rem 1.5rem;
border-radius: 4px;
}
.select:focus {
outline: 0;
}
.select:focus .list {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
pointer-events: all;
}
.select:hover {
background-color: #484848;
}
.select::after {
display: inline-block;
content: '';
border-left: .3755rem solid transparent;
border-right: .3755rem solid transparent;
border-top: .375rem solid #fff;
}
.select .list {
position: fixed;
top: 50%;
left: 50%;
width: clamp(300px, 75vw, 320px);
border-radius: 4px;
background-color: var(--light);
color: #000;
transform: translate(-50%, -50%) scale(0);
transition: all 400ms ease;
opacity: 0;
pointer-events: none;
overflow: hidden;
}
.select .list label {
display: flex;
align-items: center;
padding: 1.25rem 1.5rem;
cursor: pointer;
}
.select .list label:hover {
background-color: #ededed;
}
.select .list label:active {
background-color: #e1e1e1;
transition: 200ms ease;
}
.select .list label input[type=radio] {
margin-right: 1rem;
}
input[type=radio] {
position: relative;
height: 24px;
width: 24px;
margin: 0;
border-radius: 50%;
border: solid 1px var(--light-contrast);
background-color: var(--light);
appearance: none;
cursor: pointer;
}
input[type=radio]:checked {
border-color: var(--accent);
background-color: var(--accent);
}
input[type=radio]:focus {
outline: 0;
}
input[type=radio]::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
<div class="select" tabindex="1">
Select
<div class="list">
<label for="select-radio1">
<input type="radio" id="select-radio1" name="select-radio">
Chrome
</label>
<label for="select-radio2">
<input type="radio" id="select-radio2" name="select-radio">
Safari
</label>
<label for="select-radio3">
<input type="radio" id="select-radio3" name="select-radio">
Firefox
</label>
</div>
</div>
Subpixel rendering is handled differently across browsers.
As this SO-Post states:
[...] the problem arises from a different approach to subpixel calculus between browsers.
Also: there is no cross-browser solution, but only workarounds.

Keep the pseudo element in between the background and main content

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>