惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
AI
AI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
F
Full Disclosure
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Recorded Future
Recorded Future
N
News and Events Feed by Topic
雷峰网
雷峰网
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Project Zero
Project Zero
罗磊的独立博客
G
GRAHAM CLULEY
腾讯CDC
P
Privacy International News Feed
V
V2EX
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
H
Heimdal Security Blog
L
LINUX DO - 热门话题
Forbes - Security
Forbes - Security
美团技术团队
MongoDB | Blog
MongoDB | Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog

Ahmad Shadeed

Better fluid sizing with round() Use Cases for Field Sizing The Basics of Anchor Positioning Item Flow CSS Relative Colors Balancing Text In CSS Should masonry be part of CSS grid? CSS display contents CSS Grid Areas CSS Cap Unit An Interactive Guide to CSS Container Queries CSS :has() Interactive Guide CSS Nesting UX in DevTools CSS Nesting Future CSS: State Container Queries Rebuilding a comment component with modern CSS Conditional CSS with :has and :nth-last-child CSS Text balancing with text-wrap:balance CSS Masking Do we need CSS flex-wrap detection? My CSS Wishlist Conditional CSS CSS Style Queries Inside the mind of a frontend developer: Article layout Inside the mind of a frontend developer: Hero section CSS container queries are finally here The CSS behind Figma First Look At The CSS object-view-box Property Learn CSS Subgrid CSS :has Parent Selector Aligning Content In Different Wrappers Flexbox Dynamic Line Separator Hello, CSS Cascade Layers Building UI Components With SVG and CSS A Deep CSS Dive Into Radial And Conic Gradients Defensive CSS Building Real-life Components: Facebook Messenger Conditional Border Radius In CSS CSS Container Query Units Less Absolute Positioning With Modern CSS Aligning a Button Label Vertically Comparing Design Mockups To Code Result Using HSL Colors In CSS Custom Scrollbars In CSS Let CSS Container Queries For Designers The State of CSS Cross-Browser Development Overflow Issues In CSS Inspect Element As A Way To Increase Your Curiosity Handling Text Over Images in CSS Digging Into CSS Logical Properties Clipping Scrollable Areas On The inline-start Side Understanding Clip Path in CSS The Art of Building Real-life Components Handling Short And Long Content In CSS CSS Scroll Snap A Deep Dive Into CSS Grid minmax() CSS Variables 101 Finding The Root Cause of a CSS Bug Learn CSS centering How to detect browser support for Flexbox Gap CSS Mistakes While On Autopilot Digging Into the Flex Property Understanding CSS Multiple Backgrounds Aligning Logo Images in CSS Grid for layout, Flexbox for components Colors in CSS Thinking About The In-between Design Cases min(), max(), and clamp() CSS Functions Image Techniques On The Web Everything About Auto in CSS Learn Box Alignment Let Learn CSS Positioning Intrinsic Sizing In CSS CSS Grid Template Areas In Action Hiding Elements On The Web Creating a Variable Color Font From Scratch Building a Football Ticket With CSS and SVG Blending Modes in CSS CSS Variables With Inline Styles Implementing Dark Mode For My Website Rebuilding Apple Music Header in HTML & CSS Accessible Checkbox Layout Flickering On Browser Resize Enhancing The Clickable Area Size Custom Underlines with SVG Part 3: The Process of Implementing A UI Design From Scratch Part 2: The Process of Implementing A UI Design From Scratch CSS Flexbox: 5 Real World Use Cases I Used CSS Inline Flex For The First Time The Process of Implementing A UI Design From Scratch Common CSS Issues For Front-End Projects Handling Long and Unexpected Content in CSS How to Build Web Form Layouts With CSS Grid Grid Layout Ah-ha Moment Enhancing Our Components with CSS :empty Building Resizeable Components with Relative CSS Units CSS Writing Mode The Journey of Learning Front End Web Development on a Daily Basis
Building An Old Nav Design
Ahmad Shadeed · 2019-04-15 · via Ahmad Shadeed

The Layout Maestro

I spent years teaching CSS layout on this blog. I put everything I know into The Layout Maestro course: 70+ lessons and 150+ interactive examples that teach you how to think CSS layouts, not just memorize syntax.

Get the course

While surfing the web, I noticed an old navigation design that dates back to 2010. I used to design such things on Photoshop that are rich with shadows, gradients, backgrounds and separator lines. They are called Skeuomorphic designs.

Today, in 2019, I would take you into how I would approach and build the navigation below in HTML&CSS, without using images.

Zooming in a bit..

In this article, I will explain the following:

  • The checkerboard pattern
  • Top and Bottom shadows
  • Using mix-blend-mode

Building The Checkerboard Pattern

As you may already noticed, there is a checkerboard pattern in the background. In order to build this, I need to have multiple CSS gradients. Here is the code used:

$direction: 45deg;

div {
  width: 300px;
  height: 200px;
  background-color: #fff;
  background-image: linear-gradient(
      $direction,
      green 25%,
      transparent 0,
      transparent 75%,
      green 0,
      green
    ), linear-gradient($direction, blue 25%, transparent 0, transparent
        75%, blue 0, blue);
  background-size: 50px 50px;
  background-position:
    0 0,
    25px 25px;
  background-repeat: repeat;
}

The Result

As a start, I will break down the above into one small square as below.

1. How it works

The first gradient starts from zero to 25%, which is green. Then, it continue from 25% to 75%, which is blue. Finally, it goes 75% to 100% in green.

What does zero mean in the gradient? It’s a keyword for informing CSS to continue from the last percentage. For example, if we have linear-gradient(red 20%, blue 0, blue 50%.

The value 0 is equal to 25%. Adding it will ensure that the transition from a color to another is sharp.

Once that is done, it’s time to rotate the gradient by adding a degree.

linear-gradient($direction, green 25%, transparent 0, transparent 75%, green 0, green)

Where $direction equal 45 degrees.

The blue color were added for explanation purposes, I will replace it with transparent. Here is the current result:

2. The First Gradient

I need to define a size (width & height) for the gradient, and also make it repeat.

$direction: 45deg;

div {
  background-image: linear-gradient(
    $direction,
    green 25%,
    transparent 0,
    transparent 75%,
    green 0,
    green
  );
  background-size: 50px 50px;
  background-repeat: repeat;
}

Thankfully, we don’t need to define background-repeat since this is the default behaviour.

3. The Second Gradient

The blue gradient is exactly the same as the green one, except the color and position.

All CSS Background properties can handle multiple values. I will use that to position the blue gradient 25px from the top and left sides.

div {
  background-image: linear-gradient(
      $direction,
      green 25%,
      transparent 0,
      transparent 75%,
      green 0,
      green
    ), linear-gradient($direction, blue 25%, transparent 0, transparent
        75%, blue 0, blue);
  background-size:
    0 0,
    50px 50px;
  background-position:
    0 0,
    25px 25px;
}

0 0 is for the green one, and 25px 25px is for the blue.

Once that is repeated, it will look like the below.

CodePen Demo

See the Pen Checkerboard by Ahmad Shadeed (@shadeed) on CodePen.

Deconstructing The Navigation Background

Here are the elements of the CSS background (From bottom to top):

  • Light blue To Dark Blue Gradient
  • Checkerboard Pattern
  • Bottom Shadow
  • Top Shadow

I will add the above gradients in the same order in CSS.

ul {
  background-image: 
  /*[1]*/
    linear-gradient(rgba(0, 0, 0, 0.2), transparent),
    /*[2]*/ linear-gradient(to top, rgba(0, 0, 0, 0.3), transparent),
    /*[3]*/ linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent
          0, transparent 75%, rgba(0, 0, 0, 0.05) 0, rgba(0, 0, 0, 0.05)),
    /*[4]*/ linear-gradient(45deg, rgba(0, 0, 0, 0.05) 25%, transparent
          25%, transparent 75%, rgba(0, 0, 0, 0.05) 75%, rgba(0, 0, 0, 0.05)),
    /*[5]*/ linear-gradient(var(--color-1), var(--color-2));
  background-size:
    100% 7px,
    100% 10px,
    8px 8px,
    8px 8px,
    100%;
  background-position:
    top,
    bottom,
    0 0,
    4px 4px,
    100%;
  background-repeat: repeat-x, repeat-x, repeat, repeat, repeat;
}

Each CSS gradient from the above has a commented number, I tried to explain what each one do.

1. Top Shadow

The one at the top of the navigation. It has a width of 100% and a height of 7px.

2. Bottom Shadow

The one at the top of the navigation. It has a width of 100% and a height of 10px.

3. First Gradient For The Checkerboard

Which is similar to the green one in our example above.

4. Second Gradient For The Checkerboard

Which is similar to the blue one in our example above.

5. Base Gradient (Blue to dark blue)

A regular gradient.

Current Result

That doesn’t look good. Let’s solve that!

ul {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
}

li {
  flex-grow: 1;
}

a {
  display: block;
  text-decoration: none;
  letter-spacing: 1.5px;
  font-size: 15px;
  padding: 14px 0 16px;
  text-shadow: 0 1px 0 rgba(#00edf4, 0.8);
}

I used Flexbox to divide the available space equally between the navigation items.

Separator Line

I used to create this separator in Photoshop 10 years ago. There are two lines, one of them is white and the other is black. Notice how each line start from the center and is fading on the top and bottom sides.

How can we make this in CSS?

The first thing I thought about is using pseudo elements. Each <a> element except the first child will have an :before pseudo element. Each <a> element except the last child will have an :after element.

li {
  &:not(:first-child) {
    a {
      &:before {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 1px;
        background: #000;
      }
    }
  }

  &:not(:last-child) {
    a {
      &:after {
        content: "";
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 1px;
        background: #fff;
      }
    }
  }
}

The result

Notice that we have solid lines and they’re not blending with the blue-ish background. How to make them fade and blend?

Well, I will use CSS Radial Gradients to create a fading effect for each line.

li {
  &:not(:first-child) {
    a {
      &:before {
        /*Other styles*/
        width: 10px;
        background: radial-gradient(
          circle 25px,
          rgba(#000, 1) 0,
          transparent
        );
      }
    }
  }

  &:not(:last-child) {
    a {
      &:after {
        /*Other styles*/
        width: 10px;
        background: radial-gradient(
          circle 25px,
          rgba(#fff, 1) 0,
          transparent
        );
      }
    }
  }
}

For explanation purposes, I gave a width of 10px to each line so you can clearly see the effect. Notice how the top and bottom edges are fading.

How to blend them with the background?

The first thing I thought about is CSS mix-blend-mode: overlay and opacity. This made it blend really well!

li {
  &:not(:first-child) {
    a {
      &:before {
        /*Other styles*/
        mix-blend-mode: overlay;
        opacity: 0.65;
      }
    }
  }

  &:not(:last-child) {
    a {
      &:after {
        /*Other styles*/
        mix-blend-mode: overlay;
        opacity: 0.65;
      }
    }
  }
}

After resetting the width of each line to 1px, we’ll get a smooth separator line that blends with its background.

Final Result

Check out the CodePen demo:

See the Pen Old Nav by Ahmad Shadeed (@shadeed) on CodePen.

Credits

  • I learned about the checkerboard pattern long time ago from a CSS pattern published by Lea Verou on her blog.

Thank you for reading.

{% include share.html text = “Building An Old Nav Design” link = “https://ishadeed.com/article/building-an-old-nav-design/” %}