Friday, 16 August 2019
Thursday, 15 August 2019
Wednesday, 14 August 2019
Staggered CSS Transitions
Let's say you wanted to move an element on :hover for a fun visual effect.
@media (hover: hover) {
.list--item {
transition: 0.1s;
transform: translateY(10px);
}
.list--item:hover,
.list--item:focus {
transform: translateY(0);
}
}
Cool cool. But what if you had several list items, and you wanted them all to move on hover, but each one offset with staggered timing?
The trick lies within transition-delay and applying a slightly different delay to each item. Let's select each list item individually and apply different delays. In this case, we'll select an internal span just for fun.
@media (hover: hover) {
.list li a span {
transform: translateY(100px);
transition: 0.2s;
}
.list:hover span {
transform: translateY(0);
}
.list li:nth-child(1) span {
transition-delay: 0.0s;
}
.list li:nth-child(2) span {
transition-delay: 0.05s;
}
.list li:nth-child(3) span {
transition-delay: 0.1s;
}
.list li:nth-child(4) span {
transition-delay: 0.15s;
}
.list li:nth-child(5) span {
transition-delay: 0.2s;
}
.list li:nth-child(6) span {
transition-delay: 0.25s;
}
}
See the Pen
Staggered Animations by Chris Coyier (@chriscoyier)
on CodePen.
If you wanted to give yourself a little more programmatic control, you could set the delay as a CSS custom property:
@media (hover: hover) {
.list {
--delay: 0.05s;
}
.list li a span {
transform: translateY(100px);
transition: 0.2s;
}
.list:hover span {
transform: translateY(0);
}
.list li:nth-child(1) span {
transition-delay: calc(var(--delay) * 0);
}
.list li:nth-child(2) span {
transition-delay: calc(var(--delay) * 1);
}
.list li:nth-child(3) span {
transition-delay: calc(var(--delay) * 2);
}
.list li:nth-child(4) span {
transition-delay: calc(var(--delay) * 3);
}
.list li:nth-child(5) span {
transition-delay: calc(var(--delay) * 4);
}
.list li:nth-child(6) span {
transition-delay: calc(var(--delay) * 5);
}
}
This might be a little finicky for your taste. Say your lists starts to grow, perhaps to seven or more items. The staggering suddenly isn't working on the new ones because this doesn't account for that many list items.
You could pass in the delay from the HTML if you wanted:
<ul class="list">
<li><a href="#0" style="--delay: 0.00s;">① <span>This</span></a></li>
<li><a href="#0" style="--delay: 0.05s;">② <span>Little</span></a></li>
<li><a href="#0" style="--delay: 0.10s;">③ <span>Piggy</span></a></li>
<li><a href="#0" style="--delay: 0.15s;">④ <span>Went</span></a></li>
<li><a href="#0" style="--delay: 0.20s;">⑤ <span>To</span></a></li>
<li><a href="#0" style="--delay: 0.25s;">⑥ <span>Market</span></a></li>
</ul>
@media (hover: hover) {
.list li a span {
transform: translateY(100px);
transition: 0.2s;
}
.list:hover span {
transform: translateY(0);
transition-delay: var(--delay); /* comes from HTML */
}
}
Or if you're Sass-inclined, you could create a loop with more items than you need at the moment (knowing the extra code will gzip away pretty efficiently):
@media (hover: hover) {
/* base hover styles from above */
@for $i from 0 through 20 {
.list li:nth-child(#{$i + 1}) span {
transition-delay: 0.05s * $i;
}
}
}
That might be useful whether or not you choose to loop for more than you need.
The post Staggered CSS Transitions appeared first on CSS-Tricks.
from CSS-Tricks https://ift.tt/2Z0abLz
via IFTTT
Contextual Utility Classes for Color with Custom Properties
In CSS, we have the ability to access currentColor which is tremendously useful. Sadly, we do not have access to anything like currentBackgroundColor, and the color-mod() function is still a ways away.
With that said, I am sure I am not alone when I say I'd like to style some links based on the context, and invert colors when the link is hovered or in focus. With CSS custom properties and a few, simple utility classes, we can achieve a pretty powerful result, thanks to the cascading nature of our styles:
See the Pen
Contextually colouring links with utility classes and custom properties by Christopher Kirk-Nielsen (@chriskirknielsen)
on CodePen.
To achieve this, we'll need to specify our text and background colors with utility classes (containing our custom properties). We'll then use these to define the color of our underline, which will expand to become a full background when hovered.
Let's start with our markup:
<section class="u-bg--green">
<p class="u-color--dark">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, <a href="#">sed do eiusmod tempor incididunt</a> ut labore et dolore magna aliqua. Aliquam sem fringilla ut morbi tincidunt. Maecenas accumsan lacus vel facilisis. Posuere sollicitudin aliquam ultrices sagittis orci a scelerisque purus semper.
</p>
</section>
This gives us a block containing a paragraph, which has a link. Let's set up our utility classes. I'll be defining four colors that I found on Color Hunt. We’ll create a class for the color property, and a class for the background-color property, which will each have a variable to assign the color value (--c and --bg, respectively). So, if we were to define our green color, we’d have the following:
.u-color--green {
--c: #08ffc8;
color: #08ffc8;
}
.u-bg--green {
--bg: #08ffc8;
background-color: #08ffc8;
}
If you are a Sass user, you can automate this process with a map and loop over the values to create the color and background classes automatically. Note that this is not required, it’s merely a way to create many color-related utility classes automatically. This can be very useful, but keep track of your usage so that you don’t, for example, create seven background classes that are never used on your site. With that said, here is the Sass code to generate our classes:
$colors: ( // Define a named list of our colors
'green': #08ffc8,
'light': #fff7f7,
'grey': #dadada,
'dark': #204969
);
@each $n, $c in $colors { // $n is the key, $c is the value
.u-color--#{$n} {
--c: #{$c};
color: #{$c};
}
.u-bg--#{$n} {
--bg: #{$c};
background-color: #{$c};
}
}
What happens if we forget to apply a utility class in your markup, though? The --c variable would naturally use currentColor… and so would --bg! Let’s define a top-level default to avoid this:
html {
--c: #000000;
--bg: #ffffff;
}
Cool! Now all we need is to style our link. We will be styling all links with our trusty <a> element in this article, but you could just as easily add a class like .fancy-link.
Additionally, as you may know, links should be styled in the "LoVe-HAte" order: :link, :visited, :hover (and :focus!), and :active. We could use :any-link, but browser support isn't as great as CSS custom properties. (Had it been the other way around, it wouldn't have been much of an issue.)
We can start declaring the styles for our links by providing an acceptable experience for older browsers, then checking for custom property support:
/* Styles for older browsers */
a {
color: inherit;
text-decoration: underline;
}
a:hover,
a:focus,
a:active {
text-decoration: none;
outline: .0625em solid currentColor;
outline-offset: .0625em;
}
a:active {
outline-width: .125em;
}
@supports (--a: b) { /* Check for CSS variable support */
/* Default variable values */
html {
--c: #000000;
--bg: #ffffff;
}
a {
/*
* Basic link styles go here...
*/
}
}
Let's then create the basic link styles. We'll be making use of custom properties to make our styles as DRY as possible.
First, we need to set up our variables. We want to define a --space variable that will be used on various properties to add a bit of room around the text. The link's color will also be defined in a variable with --link-color, with a default of currentColor. The fake underline will be generated using a background image, whose size will be adjusted depending on the state with --bg-size, set to use the --space value by default. Finally, to add a bit of fun to this, we'll also fake a border around the link when it's :active using box-shadow, so we'll define its size in --shadow-size, set to 0 in it's inactive state. This gives us:
--space: .125em;
--link-color: currentColor;
--bg-size: var(--space);
--shadow-size: 0;
We’ll first need to adjust for the fallback styles. We'll set our color to make use of our custom property, and remove the default underline:
color: var(--link-color);
text-decoration: none;
Let's next create our fake underline. The image will be a linear-gradient with two identical start and end points: the text's color --c. We make sure it only repeats horizontally with background-repeat: repeat-x;, and place it at the bottom of our element with background-position: 0 100%;. Finally, we give it its size, which is 100% horizontally, and the value of --bg-size vertically. We end up with this:
background-image: linear-gradient(var(--c, currentColor), var(--c, currentColor));
background-repeat: repeat-x;
background-position: 0 100%;
background-size: 100% var(--bg-size);
For the sake of our :active state, let's also define the box shadow, which will be non-existent, but with our variable, it'll be able to come to life: box-shadow: 0 0 0 var(--shadow-size, 0) var(--c);
That's the bulk of the basic styles. Now, what we need to do is assign new values to our variables depending on the link state.
The :link and :visited are what our users will see when the link is "idle." Since we already set up everything, this is a short ruleset. While we technically could skip this step and declare the --c variable in the initial assignment of --link-color, I'm assigning this here to make every step of our styles crystal clear:
a:link,
a:visited {
--link-color: var(--c);
}
The link now looks pretty cool, but if we interact with it, nothing happens… Let's create those styles next. Two things need to happen: the background must take up all available height (aka 100%), and the text color must change to be that of the background, since the background is the text color (confusing, right?). The first one is simple enough: --bg-size: 100%;. For the text color, we assign the --bg variable, like so: --link-color: var(--bg);. Along with our pseudo-class selectors, we end up with:
a:hover,
a:focus,
a:active {
--bg-size: 100%;
--link-color: var(--bg);
}
Look at that underline become a full-on background when hovered or focused! As a bonus, we can add a faked border when the link is clicked by increasing the --shadow-size, for which our --space variable will come in handy once more:
a:active {
--shadow-size: var(--space);
}
We're now pretty much done! However, it looks a bit too generic, so let's add a transition, some padding and rounded corners, and let's also make sure it looks nice if the link spans multiple lines!
For the transitions, we only need to animate color, background-size and box-shadow. The duration is up to you, but given links are generally around 20 pixels in height, we can put a small duration. Finally, to make this look smoother, let's use ease-in-out easing. This sums up to:
transition-property: color, background-size, box-shadow;
transition-duration: 150ms;
transition-timing-function: ease-in-out;
will-change: color, background-size, box-shadow; /* lets the browser know which properties are about to be manipulated. */
We'll next assign our --space variable to padding and border-radius, but don't worry about the former — since we haven't defined it as an inline-block, the padding won't mess up the vertical rhythm of our block of text. This means you can adjust the height of your background without worrying about line-spacing! (just make sure to test your values)
padding: var(--space);
border-radius: var(--space);
Finally, to ensure the styles applies properly on multiple lines, we just need to add box-decoration-break: clone; (and prefixes, if you so desire), and that's it.
When you're done, we should have these styles:
/* Styles for older browsers */
a {
color: inherit;
text-decoration: underline;
}
a:hover,
a:focus,
a:active {
text-decoration: none;
outline: .0625em solid currentColor;
outline-offset: .0625em;
}
a:active {
outline-width: .125em;
}
/* Basic link styles for modern browsers */
@supports (--a: b) {
/* Default variable values */
html {
--c: #000000;
--bg: #ffffff;
}
a {
/* Variables */
--space: .125em;
--link-color: currentColor;
--bg-size: var(--space);
--shadow-size: 0;
/* Layout */
padding: var(--space); /* Inline elements won't affect vertical rhythm, so we don't need to specify each direction */
/* Text styles */
color: var(--link-color);/* Use the variable for our color */
text-decoration: none; /* Remove the default underline */
/* Box styles */
border-radius: var(--space); /* Make it a tiny bit fancier ✨ */
background-image: linear-gradient(var(--c, currentColor), var(--c, currentColor));
background-repeat: repeat-x;
background-position: 0 100%;
background-size: 100% var(--bg-size);
box-shadow: 0 0 0 var(--shadow-size, 0) var(--c, currentColor); /* Used in the :active state */
box-decoration-break: clone; /* Ensure the styles repeat on links spanning multiple lines */
/* Transition declarations */
transition-property: color, background-size, box-shadow;
transition-duration: 150ms;
transition-timing-function: ease-in-out;
will-change: color, background-size, box-shadow;
}
/* Idle states */
a:link,
a:visited {
--link-color: var(--c, currentColor); /* Use --c, or fallback to currentColor */
}
/* Interacted-with states */
a:hover,
a:focus,
a:active {
--bg-size: 100%;
--link-color: var(--bg);
}
/* Active state */
a:active {
--shadow-size: var(--space); /* Define the box-shadow size */
}
}
Sure, it's a bit more convoluted that just having an underline, but used hand-in-hand with utility classes that allow you to always access the text and background colors, it's a quite nice progressive enhancement.
It’s up to you to enhance this using three variables for each color, either rgb or hsl format to adjust opacity and such. You can also add a text-shadow to simulate text-decoration-skip-ink!
The post Contextual Utility Classes for Color with Custom Properties appeared first on CSS-Tricks.
from CSS-Tricks https://ift.tt/302Zd5g
via IFTTT
How to Get Started Building Links for SEO
Posted by KameronJenkins
Search for information about SEO, and you’ll quickly discover three big themes: content, user experience, and links. If you’re just getting started with SEO, that last theme will likely seem a lot more confusing and challenging than the others. That’s because, while content and user experience are under the realm of our control, links aren’t… at least not completely.
Think of this post as a quick-and-dirty version of The Beginner’s Guide to SEO’s chapter on link building. We definitely recommend you read through that as well, but if you’re short on time, this condensed version gives you a quick overview of the basics as well as actionable tips that can help you get started.
Let’s get to it!
What does “building links” mean?
Link building is a term used in SEO to describe the process of increasing the quantity of good links from other websites to your own.
Why are links so important? They’re one of the main (although not the only!) criteria Google uses to determine the quality and trustworthiness of a page. You want links from reputable, relevant websites to bolster your own site’s authority in search engines.
For more information on different types of links, check out Cyrus Shepard’s post All Links are Not Created Equal: 20 New Graphics on Google's Valuation of Links.
“Building links” is common SEO vernacular, but it deserves unpacking or else you may get the wrong idea about this practice. Google wants people to link to pages out of their own volition, because they value the content on that page. Google does not want people to link to pages because they were paid or incentivized to do so, or create links to their websites themselves — those types of links should use the “nofollow” attribute. You can read more about what Google thinks about links in their webmaster guidelines.
The main thing to remember is that links to your pages are an important part of SEO, but Google doesn’t want you paying or self-creating them, so the practice of “building links” is really more a process of “earning links” — let’s dive in.
How do I build links?
If Google doesn’t want you creating links yourself or paying for them, how do you go about getting them? There are a lot of different methods, but we’ll explore some of the basics.
Link gap analysis
One popular method for getting started with link building is to look at the links your competitors have but you don’t. This is often referred to as a competitor backlink analysis or a link gap analysis. You can perform one of these using Moz Link Explorer’s Link Intersect tool.
Link Intersect gives you a glimpse into your competitor’s link strategy. My pal Miriam and I wrote a guide that explains how to use Link Explorer and what to do with the links you find. It’s specifically geared toward local businesses, but it’s helpful for anyone just getting started with link building.
Email outreach
A skill you’ll definitely need for link building is email outreach. Remember, links to your site should be created by others, so to get them to link to your content, you need to tell them about it! Cold outreach is always going to be hit-or-miss, but here are a few things that can help:
- Make a genuine connection: People are much more inclined to help you out if they know you. Consider connecting with them on social media and building a relationship before you ask them for a link.
- Offer something of value: Don’t just ask someone to link to you — tell them how they’ll benefit! Example: offering a guest post to a content-desperate publisher.
- Be someone people would want to link to: Before you ask anyone to link to your content, ask yourself questions like, “Would I find this valuable enough to link to?” and “Is this the type of content this person likes to link to?”
There are tons more articles on the Moz Blog you can check out if you’re looking to learn more about making your email outreach effective:
- Supercharge Your Link Building Outreach! 5 Tips for Success - Whiteboard Friday
- Link Building in 2019: Get by With a Little Help From Your Friends
- How We Increased Our Email Response Rate from ~8% to 34%
- Why You Should Steal My Daughter's Playbook for Effective Email Outreach
Contribute your expertise using services like HARO
When you’re just getting started, services like Help a Reporter Out (HARO) are great. When you sign up as a source, you’ll start getting requests from journalists who need quotes for their articles. Not all requests will be relevant to you, but be on the lookout for those that are. If the journalist likes your pitch, they may feature your quote in their article with a link back to your website.
Where do I go from here?
I hope this was a helpful crash-course into the world of link building! If you want to keep learning, we recommend checking out this free video course from HubSpot Academy that walks you through finding the right SEO strategy, including how to use Moz Link Explorer for link building.
Remember, link building certainly isn’t easy, but it is worth it!
Sign up for The Moz Top 10, a semimonthly mailer updating you on the top ten hottest pieces of SEO news, tips, and rad links uncovered by the Moz team. Think of it as your exclusive digest of stuff you don't have time to hunt down but want to read!
from The Moz Blog https://ift.tt/2MgvF0L
via IFTTT
Passkeys: What the Heck and Why?
These things called passkeys sure are making the rounds these days. They were a main attraction at W3C TPAC 2022 , gained support in Saf...
-
These things called passkeys sure are making the rounds these days. They were a main attraction at W3C TPAC 2022 , gained support in Saf...
-
Posted by kerryjones We’ve created more than 800 content campaigns at Fractl over the years, and we’d be lying if we told you every single ...
-
Usually, when “unused” comes up in conversation regarding CSS, it’s about removing chunks of CSS that are not used in your site or, at least...