Wednesday, 3 October 2018

How Do You Put a Border on Three Sides of an Element?

I saw a little conversation about this the other day and figured it would be fun to look at all the different ways to do it. None of them are particularly tricky, but perhaps you'll favor one over another for clarity of syntax, efficiency, or otherwise.

Let's assume we want a border on the bottom, left, and right (but not top) of an element.

Explicitly declare each side

.three-sides {
  border-bottom: 2px solid black;
  border-right:  2px solid black;
  border-left:   2px solid black;
}

While that's pretty clear, it's still making use of shorthand. Completely expanded it would be like this:

.three-sides {
  border-bottom-color: black;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  
  border-left-color: black;
  border-left-style: solid;
  border-left-width: 2px;
  
  border-right-color: black;
  border-right-style: solid;
  border-right-width: 2px;
}

Knock off one of the sides

You can save a little code by declaring the border on all four sides with shorthand and then removing the one you don't want:

.three-sides {
  border: 2px solid black;
  border-top: 0;
}

Shorthand just the width

.three-sides {
  border-color: black;
  border-style: solid;
  /* top, right, bottom, left - just like margin and padding */
  border-width: 0 2px 2px 2px;
}

As a fun little aside here, you don't need to declare the border color to get a border to show up, because the color will inherit the currentColor! So this would work fine:

.three-sides {
  /* no color declared */
  border-style: solid;
  border-width: 0 2px 2px 2px;
}

And you'd have red borders if you did:

.three-sides {
  color: red;
  border-style: solid;
  border-width: 0 2px 2px 2px;
}

Strange, but true.

If you want to add the color explicity, you can kinda mix-and-match shorthand, so this will work fine:

.three-sides {
  border: solid green; 
  border-width: 2px 0 2px 2px;
}

The post How Do You Put a Border on Three Sides of an Element? appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2y0MDaF
via IFTTT

Tuesday, 2 October 2018

Selectors That Depend on Layout

"Why the heck don't we have ::first-column?"

I heard someone ask that the other day and it's a valid question. I'd even take that question further by asking about ::nth-column() or whatever else relates to CSS columns. We have stuff like ::first-letter and ::first-line. Why not others?

There are many notable things missing from the "nth" crowd. Seven years ago, I wrote "A Call for ::nth-everything" and it included clear use cases like, perhaps, selecting the first two lines of a paragraph.

I don't know all the technical details of it all, but I know there are some fairly decent reasons why we don't have all of these in CSS. Part of it is the difficulty of getting it specced (e.g. words and characters get tricky across written languages) and part of it is the difficulty of implementing them. What I just found out is that there is a FAQ document that explains!

So, why don't we have ::first-column? Because it's a "selector that depends on layout":

This falls into a class of problems that unlikely to be solvable in CSS: selectors in general, and pseudo classes in particular, cannot depend on layout, because otherwise they could be used to modify layout in a way that made them no longer match, which would modify the layout back to where it was, so they match again, and we get stuck in an infinite loop of contradictions.

For a simple example:

:stuck { position: static; }

Now what?

Some of the changes web developers might want to apply with a :stuck pseudo class may be safe and not trigger such loops, but selectors are a generic mechanism, and would enable this kind of contradictions.

So even though many of the problem people are trying to address using such pseudo classes are legitimate, selectors are unlikely to be the answer.

What we've got are infinite loops that are basically the problem (but read the FAQ — it goes into great detail about the nuance of it). In a related way, the same reason we don't have element queries in CSS.

It's a little tricky to think about because even stuff like ::first-line are riddled with paradoxes. Say you use it to increase the font-size. That means fewer characters fit on the line, so the characters that originally matched are now pushed down and don't match anymore. Seems a bit loopy, but that's been sorted out. Plus, classics like :hover potentially causing jitter. The document talks about these things in clear terms. It's not all cut and dry!

The whole FAQ is a fascinating read and covers much more than this situation.

Direct Link to Article — Permalink

The post Selectors That Depend on Layout appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2OrDhhJ
via IFTTT

Apply a Filter to a Background Image

You can apply a filter to an entire element quite easily with the filter property. But what if you want to apply a filter just to the background of an element? It's weirdly tricky.

There are CSS properties that specific to backgrounds, like background-blend-mode — but blending and filters are not the same thing. It sorta seems to be the reason we have backdrop-filter, but not quite. That does filtering as the background interacts with what is behind the element.

There is no background-filter, unfortunately. What are we to do?

Use a pseudo-element instead of a background

If you put the contents of the element in an inside wrapper, you can set that on top of a pseudo-element that is simply pretending to be a background.

.module {
  position: relative;
}
.module::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-image: url(graphic-to-be-filtered.jpg);
  filter: grayscale(100%);
}
.module-inside {
  /* This will make it stack on top of the ::before */
  position: relative;
}

See the Pen Apply Filter to Psuedo Element by Chris Coyier (@chriscoyier) on CodePen.

See how the "background" gets filtered with grayscale there? We called the grayscale filter there and applied it only to the pseudo-element, leaving the rest of the content inside unfiltered.

It depends on what kind of filtering you want... you might be able to fake it with blend modes

I ran into this issue as I was specifically trying to grayscale the background image of an element. Since, as we've covered, there is no specific property just for that, I thought about background-blend-mode, particularly how there are blending options for things like saturation and color. If I could set pure black over the top of the graphic, then I could blend them — like I can with multiple backgrounds — and essentially fake a grayscale effect.

Note that you can't use a solid color by itself when working with multiple backgrounds (that would be a background-color not background-image), so we have to fake that as well with a no-transition linear-gradient.

.module {
  background-image:
    linear-gradient(black, black),
    url(image-to-be-fake-filters.jpg);
  background-size: cover;
  background-blend-mode: saturation;
}

See the Pen Apply Fake Filter with Blend Mode by Chris Coyier (@chriscoyier) on CodePen.

Dan Wilson's explorations

Dan got way into this and made an exploratory Pen in which there are three layers:

  1. Top layer: a vignette from a radial-gradient
  2. Middle layer: solid color
  3. Bottom layer: image graphic

You can adjust the colors used on the top two layers and apply different blend modes to each one. That was another thing I learned! Just like you can comma-separate to make multiple backgrounds (and likewise with background-size, background-position and such to apply those values to specific backgrounds) you can also comma-separate background-blend-mode to apply different blending effects to each layer.

See the Pen Multiple Backgrounds, Multiple Blend Modes by Dan Wilson (@danwilson) on CodePen.

The post Apply a Filter to a Background Image appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2DQXLfP
via IFTTT

Netlify

(This is a sponsored post.)

It's always fun to watch developers discover Netlify for the first time. It's so easy. One way to do it is to just literally drag and drop a folder onto them and it will be online. Even better, connect a Git repo to a Netlify site and tell it what branch you want to watch, then any commits to that branch will automatically go live, even running your site's build as it does it. I heard one developer say, "It's like someone actually designed hosting and deployment."

That lends itself nicely to static sites, but don't think that static sites are only for certain types of sites or limiting in some way. That's what the JAMstack is all about! Wanna learn more about that? Come to JAMstack_conf!

Netlify does a ton to help you power your JAMstack site as well. They'll process your forms. They'll help you with authentication. They'll do your A/B testing. They'll even run your cloud functions. Pretty incredible, really.

Direct Link to Article — Permalink

The post Netlify appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2NXivam
via IFTTT

A Slice of MozCon Magic: The 2018 Video Bundle is HERE!

Posted by HayleyBowyer

Your tweets haven't gone unnoticed — we know the MozCon #FOMO is very real. Many of you would be there in a second if it weren’t for busy schedules and pesky back-to-back meetings. So, while you're hard at work, we’re here to make one thing easy: providing you with the insights you need whenever you need them.

Yes, that’s right — the MozCon 2018 Video Bundle is here and we can’t wait share it with you!

Ready to dive in? Feel free to skip straight to the fun part!

Buy the MozCon 2018 Video Bundle

Did you attend MozCon 2018? You’re in luck! The full video bundle is included with your ticket price. Check your inbox for an email with a link to exclusive video access. Can’t find it? Email us — we're happy to help!

If you weren’t able to make it, MozCon 2018 was awesome, to say the least. I’m not just saying that because I want to see you at MozCon 2019, but because, in just three short days, I witnessed magic happen.

No, not the kind you find at Disneyland (even though I firmly believe MozCon is Disneyland for marketers… but that’s another story), but the kind you find when you bring hundreds of people together from different walks of life, each with their own special talents, and watch them create one of the most thought-provoking, engaging, and inclusive communities I've ever seen. They fostered a wealth of knowledge and resources that left everyone with plenty of new ideas and answers to marketing’s most challenging questions. That, coupled with the impressive speaker line up and innovative topics, made 2018 one of the best MozCons to date. I am honored to have been a part of it.

Even our attendees thought so:

99.1% of attendees said they were either satisfied, very satisfied, or extremely satisfied with the conference overall.

And when it came to the topics, 77.8% said the topics were just the right amount of advanced — there was plenty to learn, but we weren’t too overwhelmed.


Here’s what Lily Ray, SEO Director at Path Interactive, had to say about MozCon 2018:

I’ve made MozCon an annual ritual. I leave each year feeling invigorated with new ideas, new skills, and a refreshed approach to client strategies. The information I’ve learned at MozCon has improved my abilities as an SEO and has led to better results for my clients.



I hope you experience a slice of MozCon magic with the MozCon 2018 Video Bundle. With it, you’ll gain access to 12 hours of content full of actionable tactics you can instantly put to work for you and your team. The sessions are sure to help energize your online marketing strategy.

What you’ll get:

For just $299, you can enjoy the full MozCon experience from the comfort of your home or office. The bundle includes:

  • 26 full-length videos from some of the brightest minds in digital marketing
  • Instant downloads and streaming to your computer, tablet, or mobile device
  • Downloadable slide decks for presentations

Buy the MozCon 2018 Video Bundle

Not convinced yet? Watch a session now… for free!

To help you decide whether the video bundle is right for you, we're sharing one of our highest-rated sessions with you for free! In this session, Moz’s own marketing scientist and SEO extraordinaire Dr. Pete Meyers discusses mapping keywords to searcher intent and capitalizing on the promise of ranking to drive results that attract clicks and customers. Enjoy!

Ranking is a Promise: Can You Deliver? with Dr. Pete Meyers

Finally, a BIG thank you to the team who made MozCon and this video bundle possible. We love sharing all this knowledge and couldn’t do it without the support of our vendors, partners, and the entire MozCon team.

And to the community, we wish you happy learning and hope to see you at MozCon 2019!


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/2P426gG
via IFTTT

Monday, 1 October 2018

Preventing a Grid Blowout

The Shapes of CSS

CSS is capable of making all sorts of shapes. Squares and rectangles are easy, as they are the natural shapes of the web. Add a width and height and you have the exact size rectangle you need. Add border-radius and you can round that shape, and enough of it you can turn those rectangles into circles and ovals.

We also get the ::before and ::after psuedo elements in CSS, which give us the potential of two more shapes we can add to the original element. By getting clever with positioning, transforming, and many other tricks, we can make lots of shapes in CSS with only a single HTML element.

Square

Rectangle

Circle

Oval

Triangle Up

Triangle Down

Triangle Left

Triangle Right

Triangle Top Left

Triangle Top Right

Triangle Bottom Left

Triangle Bottom Right

Curved Tail Arrow via Ando Razafimandimby

Trapezoid

Parallelogram

Star (6-points)

Star (5-points) via Kit MacAllister

Pentagon

Hexagon

Octagon

Diamond Square via Joseph Silber

Diamond Shield via Joseph Silber

Diamond Narrow via Joseph Silber

Cut Diamond via Alexander Futekov

Egg

Pac-Man

Talk Bubble

12 Point Burst via Alan Johnson

8 Point Burst via Alan Johnson

Badge Ribbon via Catalin Rosu

Space Invader via Vlad Zinculescu

TV Screen

Magnifying Glass

Facebook Icon via Nathan Swartz

The post The Shapes of CSS appeared first on CSS-Tricks.



from CSS-Tricks https://ift.tt/2QoJLeG
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...