Element appearing with :focus-visible - html

In my project I have a list of 'result items' which can be favourited and then they appear on in a favourites column to the side of the page.
To allow keyboard users easy access, I have created a hidden cta which allows them to skip directly to their favourited item, without having to tab through all the result items first.
I only want this cta to be visible when it is tabbed to. My understanding is that :focus-visible would enable this. However, for some reason, it's not working for me. My HTML and CSS look like:
.sr-only-focusable {
position: absolute;
visibility: hidden;
left: 56%;
top: rem(65);
border-radius: 5px;
border: 1px solid #d7d7d7;
background-color: $white;
padding: 1rem 2rem;
z-index: 10;
}
.sr-only-focusable:focus-visible {
visibility: visible;
}
<div class="sr-only-focusable">
<button tabindex="0" #click="skipToShortlist">Skip To Shortlist</button>
</div>
Could anyone help me figure out where i'm going wrong?
Thanks in advance

The button element is what you're trying to tab to, not the div it's contained in. Rather than trying to get to the div, target the button instead. Also, use opacity because visibility doesn't seem to play nicely with tabindex. You can also apply your styling to the button as well.
.sr-only-focusable {
position: absolute;
left: 56%;
top: rem(65);
z-index: 10;
}
.myBtn {
display: inline-block;
font-family: Helvetica, Arial, sans-serif;
color: black;
margin: 0 auto;
font-size: 1.2vw;
font-weight: 700;
line-height: 1.25;
letter-spacing: 0.5px;
cursor: pointer;
text-decoration: none;
opacity: 0;
border-radius: 5px;
border: 1px solid #d7d7d7;
background-color: $white;
padding: 1rem 2rem;
}
.myBtn:focus-visible {
opacity: 1;
}
<div class="sr-only-focusable">
<button class="myBtn" tabindex="0" #click="skipToShortlist">Skip To Shortlist</button>
</div>

From my experience (mostly on chrome) elements with display:none or visibility:hidden cannot be focused by mouse or by keyboard.
Most implementations use something along the lines of this:
.wrapper {
background: black;
text-align: center;
width: 360px;
height: 100px;
padding: 40px;
box-sizing: border-box;
color: blanchedalmond;
}
.image-nav-button {
color: blanchedalmond;
text-decoration: none;
font-size: 20px;
line-height: 1em;
width:1px;
height:1px;
position:absolute;
clip: rect(1px,1px,1px,1px);
clip-path: inset(50%);
}
.next {
float: right;
}
.prev {
float: left;
}
.image-nav-button:focus {
outline: none;
/* Try uncommenting below, then clicking the buttons */
/* outline: 3px solid red; */
}
.image-nav-button:focus-visible {
outline: 3px solid blanchedalmond;
width:auto;
height:auto;
position:relative;
clip: none;
clip-path: none;
}
<div class="wrapper">
← Prev Image
Next Image →
</div>

Related

CSS animation on the container instead of on the link

I have a CSS border animation on an HTML link. The animation sets on mouse hover and it automatically adjusts to the with of the link. Once the mouse is hover, border animations appear in pairs, left-right + top-down. When the animation is over the borders will form a square around the link.
It works fine until the link gets a line break and instead of one line I have a link with two lines. In that case the animation will form around the top line in the link and ignore the line break.
I have been trying and trying and I cannot figure out a way to make the animation go around the whole link instead of only around the first meaning. Can anyone help me out?
Code Pen: https://codepen.io/jo-o-figueiredo/pen/KKZOjWM
Thanks in advance!
div.caixa {
margin: 4em auto;
padding: 4em;
box-sizing: border-box;
text-align: center;
}
.sparkle {
max-width: 10em;
color: #5a4d1a;
margin: auto auto;
font-size: 25px;
line-height: 40px;
text-decoration: underline;
text-decoration-color: #b1d6b1;
text-underline-offset: 0.5em;
text-decoration-thickness: 3px;
font-weight: 500;
}
.sparkle:hover {
cursor: pointer;
text-decoration: none;
color: #1a1a1a;
}
.u-hover--sparkle {
box-sizing: border-box;
position: relative;
padding: 0.75em;
}
.u-hover--sparkle::before,
.u-hover--sparkle::after {
content: "";
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
transition: transform .20s;
}
.u-hover--sparkle::before {
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
transform: scale3d(0, 1, 1);
}
.u-hover--sparkle::after {
border-left: 1px solid #1a1a1a;
border-right: 1px solid #1a1a1a;
transform: scale3d(1, 0, 1);
}
.u-hover--sparkle:hover::before,
.u-hover--sparkle:hover::after {
transform: scale3d(1, 1, 1);
transition: transform .35s;
}
<div class="wpb_text_column wpb_content_element caixa">
<div class="wpb_wrapper">
<p>
<a class="sparkle u-hover--sparkle" href="#paket" rel="noopener">Sällskap -
Sammankomster</a>
</p>
</div>
</div>
Set the .sparkle to display block so it covers the whole thing.
Also define how your text should break, because if it's a long word, it has no choice to go out of bound by default.
.sparkle {
display: block;
word-break: break-all;
/* rest of your code */
}
div.caixa {
margin: 4em auto;
padding: 4em;
box-sizing: border-box;
text-align: center;
}
.sparkle {
max-width: 10em;
color: #5a4d1a;
margin: auto auto;
font-size: 25px;
line-height: 40px;
text-decoration: underline;
text-decoration-color: #b1d6b1;
text-underline-offset: 0.5em;
text-decoration-thickness: 3px;
font-weight: 500;
display: block;
word-break: break-word;
}
.sparkle:hover {
cursor: pointer;
text-decoration: none;
color: #1a1a1a;
}
.u-hover--sparkle {
box-sizing: border-box;
position: relative;
padding: 0.75em;
}
.u-hover--sparkle::before,
.u-hover--sparkle::after {
content: "";
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
transition: transform .20s;
}
.u-hover--sparkle::before {
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
transform: scale3d(0, 1, 1);
}
.u-hover--sparkle::after {
border-left: 1px solid #1a1a1a;
border-right: 1px solid #1a1a1a;
transform: scale3d(1, 0, 1);
}
.u-hover--sparkle:hover::before,
.u-hover--sparkle:hover::after {
transform: scale3d(1, 1, 1);
transition: transform .35s;
}
<div class="wpb_text_column wpb_content_element caixa">
<a class="sparkle u-hover--sparkle" href="#paket" rel="noopener">Sällskap -
Sammankomster</a>
</div>
I think there are multiple things to point out:
Easy Fix: Add display: block; to the .sparkle class and increase max-width to enable the text to stand in one line.
Alternatively you could also apply the animation styles to the divs surrounding the Link
Optional: I think you could also remove the <p> element surrounding the link as it is unnecessarily making your markup more complex.

CSS style color and more wont load

I'm having a bit of a problem with my CSS code in my website project. I was designing a html form but when i applied the changes in the stylesheet file, the new text colors did not want to be applied etc. And i also added a specific color to this * in the code below but it did not want to change the color either.
.apply {
width: 320px;
height: 420px;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 70px 30px;
}
.apply input[type="text"], [type="text"], [type="email"]
{
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
h1 .pageHeader {
margin: 0;
padding: 0 0 20;
text-align: center;
font-size: 22px;
color: #fff;
}
body {
background-color: #24252A;
font-family: "Montserrat", sans-serif;
}
.required {
color: rgb(255,99,71);
}
text in your input will have given color only when this input have some value.
Without value there is displayed placeholder text which have his own styling.
look for ::placeholder pseudo element
input::placeholder {
color: red
}
<input placeholder="Type here...">

How to keep components auto resizable while creating templates in React JS?

So I am trying to put a background image and then center the text to it, but when I change the screen size the text misaligns and moves to the top.
Here's my code:
import React from "react";
import UniversalValues from "../constants.js";
export default function Body() {
return (
<div>
<div className="Container">
<img
className="ResizeImage"
src="https://images.unsplash.com/photo-1533139143976-30918502365b?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max"
alt="Background not loading! X_X"
/>
<div className="TextField">
<h1 className="BGH1">WE DO IT TOGETHER</h1>
<h1 className="BGH1">SO LET'S CREATE</h1>
</div>
</div>
</div>
);
}
Here is my css file:
.App {
font-family: sans-serif;
text-align: center;
}
.BGH1 {
letter-spacing: 0.06em;
font-family: "Cinzel", serif;
font-size: 5rem;
position: relative;
}
.BrandPoint {
font-size: 3rem;
font-family: "Cinzel", serif;
padding-left: 3rem;
}
.Container {
position: relative;
}
.dropbtn {
background: transparent;
color: white;
padding-bottom: 10px;
font-size: 1.2rem;
font-weight: bold;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #33393f;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
transition: transform 0.5s ease;
transform: scale(0.9);
color: #3eccb5;
border: 1px solid;
border-radius: 0.2rem;
border-color: #e0dede;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
transition: transform 0.5s ease;
transform: scale(0.9);
color: #3eccb5;
border: 1px solid;
border-radius: 0.2rem;
border-color: #e0dede;
}
.HeaderElem {
color: white;
padding-bottom: 10px;
font-size: 1.2rem;
}
.HeaderElem:hover {
transition: transform 0.5s ease;
transform: scale(0.9);
color: #3eccb5;
border: 1px solid;
border-radius: 0.2rem;
border-color: #e0dede;
}
.HeaderSeperator {
padding-left: 2rem;
}
.HeadUp {
position: fixed;
top: 0;
left: 0;
}
.ResizeImage {
height: auto;
width: 100%;
margin: 0;
padding: 0;
opacity: 0.99;
}
.TextField {
position: absolute;
bottom: 40%;
left: 35%;
color: white;
padding-left: 20px;
padding-right: 20px;
}
What I am getting vs What I wanted:
I want to pack this whole thing together and so it could just effectively change its shape according to the screen size. I have used Bootstrap but I am new to React and designing my entire website on codesandbox.io. Do let me know the best way to do so.
Thanks in advance.
I think your problem is purely HTML/CSS and not so much React. Thanks for flexbox centering content got a lot easier today.
Change your HTML like this:
<div>
<div class="Container">
<div class="imageContainer"></div>
<div class="TextField">
<h1 class="BGH1">WE DO IT TOGETHER</h1>
<h1 class="BGH1">SO LET'S CREATE</h1>
</div>
</div>
</div>
And your CSS like this:
.Container {
display: flex;
justify-content: center;
align-items: center;
background-color:blue;
position: relative;
color: white;
text-align: center;
height: 300px;
}
.imageContainer {
position: absolute;
width: 100%;
height: 100%;
opacity: 0.2;
background-image: url("https://images.unsplash.com/photo-1533139143976-30918502365b?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max");
background-position: center center;
}
Here is a fiddle test it: https://jsfiddle.net/gtqna9c1/7/
How it works
Instead of trying to center changing text by absolute positioning it is a lot easier to create conditions where the text is always centered, no matter what. The background image is now a simple background of a div that is covering your whole box.
The fiddle is simplified and coloured for clarity. Feel free to add paddings etc. as you wish.

Electron: Custom Titlebar: Buttons don't change their CSS properties back to normal (after mouse hover) when the cursor leaves the app

Greetings! This is my second time posting today, but that's how people learn, right?
Anyway! I am creating an app with Electron and I want to create a custom title bar. I have been successful but there is a small detail that kind of bothers me. I want the buttons to change their opacity when the mouse hovers them but when the cursor leaves the app after hovering the buttons, they don't change. Instead, I have to go to the app again, hover the button again and finally see the right behaviour.
Is there a way to fix this? It's not that fatal, but I am trying to make my app look good and pleasant to the eye as much as I can!
HTML:
<div class="titlebar">
<div class="dragzone"></div>
<h1>Dashboard - Wealm</h1>
<button id="closeApp">x</button>
<button id="minApp">-</button>
</div>
CSS:
.titlebar {
position: absolute;
top: 0;
width: 100%;
height: 29px;
overflow: hidden;
z-index: 50;
background: rgba(255, 255, 255, 0.8);
}
.titlebar .dragzone {
-webkit-app-region: drag;
overflow: hidden;
position: absolute;
left: 0;
width: 990px;
height: 29px;
}
.titlebar h1 {
float: left;
opacity: 0.85;
margin: 4px 0 0 43.5%;
font-family: Jost-400-Book;
font-size: 12pt;
}
.titlebar #closeApp {
font-weight: bold;
opacity: 0.55;
float: right;
background: none;
border: none;
outline: none;
font-family: Eight One;
font-size: 18pt;
margin-top: 2px;
}
.titlebar #minApp {
font-weight: bold;
opacity: 0.55;
float: right;
background: none;
border: none;
outline: none;
font-family: Eight One;
font-size: 18pt;
margin-top: 2px;
}
.titlebar #closeApp:hover {
opacity: 1;
}
.titlebar #minApp:hover {
opacity: 1;
}
Great news! I did found a solution! What I did - First of all, I replaced the content inside the buttons with paragraphs. It's the same text but in paragraph tags. I set the overflow property of the buttons to visible, in order to be able to set the height of the buttons to 0 without hiding the paragraphs themselves. Then I just played around with margins. It's up to you!
.titlebar #closeApp {
font-weight: bold;
background: none;
float: right;
opacity: 0.55;
border: none;
outline: none;
font-family: Eight One;
font-size: 18pt;
overflow: hidden;
padding-right: 0px;
margin-right: 8px;
margin-top: 8px;
}
.titlebar #closeApp p {
margin-bottom: 0;
margin-top: -5.45px;
}
.titlebar #minApp {
font-weight: bold;
background: none;
float: right;
opacity: 0.55;
border: none;
outline: none;
font-family: Eight One;
font-size: 18pt;
overflow: hidden;
margin-top: 8px
}
.titlebar #minApp p {
margin-bottom: 0;
margin-top: -5.45px;
}
Have a great day! Let me know if you have a question or the solution just doesn't work for you!

Center one char in a rounded button element cross browser

I have a button with just one character which I would like to have exactly in the middle of the button
<button>+</button>
I have the following css:
button {
border: 2px solid lightgrey;
border-radius: 20px;
background-color: #fff;
outline: none;
height: 40px;
width: 40px;
font-size: 30px;
font-weight: 700;
line-height: 30px;
color: grey;
cursor: pointer;
user-select: none;
display: inline-flex;
align-items: center;
justify-content: center;
text-align: center;
}
JSFIDDLE
I probably have to many css properties in here but I have tried many different solutions. I've tested this button on chrome, safari and iPad:
None of them seem to be exactly at the center of the button. How can I do this cross browser ?
UPDATE: Even with the suggestions given below, I still see differences in different browsers. It is still hard to pixel-perfect center the chars. The solution I switched to is to use a svg for the chars, which solves this problem.
Here, try this CSS only plus button. I prefer using SVGs for icons, but you can use this ccs only button too :)
Markup
<button class="plus-button plus-button--small"></button>
<button class="plus-button"></button>
<button class="plus-button plus-button--large"></button>
SCSS
.plus-button {
border: 2px solid lightgrey;
background-color: #fff;
font-size: 16px;
height: 2.5em;
width: 2.5em;
border-radius: 999px;
position: relative;
&:after,
&:before {
content: "";
display: block;
background-color: grey;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
&:before {
height: 1em;
width: 0.2em;
}
&:after {
height: 0.2em;
width: 1em;
}
}
.plus-button--small {
font-size: 12px;
}
.plus-button--large {
font-size: 22px;
}
https://jsfiddle.net/robi_osahan/gwgL7Loj/
You could try with these CSS:
button {
border: 2px solid lightgrey;
border-radius: 20px;
background-color: #fff;
outline: none;
height: 40px;
width: 40px;
cursor: pointer;
user-select: none;
position: relative;
}
span {
color: grey;
font-size: 30px;
font-weight: 700;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
Here's a jsfiddle: https://jsfiddle.net/e490xzpy/5/
button {
border: 2px solid lightgrey;
border-radius: 50%;
background-color: #fff;
outline: none;
height: 40px;
width: 40px;
font-size: 30px;
font-weight: 700;
line-height: 10px;
color: grey;
cursor: pointer;
user-select: none;
text-align: center;
display:block;
}
And the fiddler link is
https://jsfiddle.net/3gfkpm0h/1/
I didn't fork your code, in fact I was coding something similar myself. I'm sharing my experience with you about absolutely centering (or middling or whatever) the icon inside a button.
If you are using line-height and border at the same time, you should subtract the total width of the border (sum of top and bottom border-width),
Absolute centering may not always be satisfying with every font-face you use with the buttons. The centering may look a bit off due to that font's baseline.
So, here is my take. Two techniques that I often use for these kinds of things:
Subtract the border-width from the line-height and stay happy with it.
Bring it one step further by adding an extra element within the relatively positioned button, and absolutely middle it using CSS transforms!
Here are some examples for you to test it yourself.
.btn {
position: relative;
display: inline-block;
vertical-align: bottom;
border: 2px solid;
width: 40px;
height: 40px;
line-height: 36px;
/* line-height = (height) - (border-top-width) + (border-bottom-width); */
background-color: #fff;
border-radius: 50%;
font-weight: 700;
font-size: 30px;
}
.btn-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
line-height: 1;
}
<h3>Button without extra-element</h3>
<button class="btn">+</button>
<button class="btn">X</button>
<button class="btn">x</button>
<h3>Button with extra-element (.btn-icon)</h3>
<button class="btn"><span class="btn-icon">+</span></button>
<button class="btn"><span class="btn-icon">X</span></button>
<button class="btn"><span class="btn-icon">x</span></button>
See yourself what suits best for you. Hope it helped. Cheers!