7 Awesome CSS3 Techniques You Should give a Try

The evolution of CSS (Cascading Style Sheets) with HTML has been incredible. There are hoards of features like Flexbox, CSS Grid and CSS custom properties introduced recently.

Its continuous advancement and huge potential are what that captivate the developers to try new CSS techniques and exceed the boundaries of what it can do. The combination of both HTML 5 and CSS3 technology is, no doubt, a flash-killer.

There is no wonder that a well-executed CSS plan can almost control any facet of design and lead to better user experience, which is quite necessary. After all, visitors carry certain expectations when they view your site through a laptop, desktop, tablet or any other medium.

But what are the trending CSS techniques? Isn’t it an obvious question that crosses the mind when we talk about designing an attractive user-friendly website.

This is why we have come up with some of the fresh CSS techniques and tips to master your web designing skills. Each one includes some explanations and sample code snippets.

So let’s get straight to it!

1. Vertically Align With Flexbox

Earlier developers used to face a lot of difficulties aligning a text or any other element vertically center. But now, after the introduction of the new CSS3 specification Flexbox, things have become much easier.

The property, display: flex provides an effortless way for users to align any text or element at the center. Here is the sample code!

HTML:

<div class="align-vertically">
Vertically centered!
</div>

CSS:

.align-vertically {
  background: #FFA500;
  color: #hhh;
  display: flex;
  align-items: center;
  height: 200px;
}

In the above CSS code, display: flex describes the Flexbox layout for the element, whereas align-items: center; is responsible for the vertical centering of the text.

RESULT:

Awesome CSS3 Techniques

2. Responsive CSS Grid

Do not make your grid an exception make it responsive too, like everything else in your design.

There are so many ways through which you can make your grid responsive with CSS Grid. And the best part of using it is, you will be able to create a more flexible grid that gives you the desired look, no matter what the device size is.

In addition to this, the CSS grid also allows you to work with unequal and equal column sizes. It is a great piece of technology packed with the options which give freedom to the users to have control over their designs.

You can use various breakpoints, the height of multiple dimensions and do other placements, as shown in the example below.

HTML:

 <div class="grid">
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
  <div class="grid-item"></div>
</div>

CSS:

.grid
 {
  display: grid;
  grid-template-rows: repeat(5, 1fr); 
  grid-auto-columns: calc((100vh - 3em) / 4);
  grid-auto-flow: column;
  grid-gap: 1em;
  height: 100vh;
}
.grid-item:nth-child(3n)
 {
  background-color: purple;
}
.grid-item:nth-child(3n + 2) 
{
  background-color: pink;
}

The fraction unit (fr) used in the above CSS code is the flexible unit that separates the open space according to your guidelines. Each fr statement is for the column, then you can add up the gaps and make the grid ready.

RESULT:

Awesome CSS3 Techniques

3. Text Animations

You might have created background animations with CSS, but now it also influences how users interact and engage with the text elements of a website. From hover adjustments to making words float in the air, CCS3 has made it all possible.

Websites that don’t have many enticing elements to engage their users can make the best out of this trait. Here is a small example of it.

HTML:

<div class="Menu">
<ul class="Menu-list" data-offset="10">
<li class="Menu-list-item" data-offset="20" onclick>
LIVE
<span class="Mask"><span>LIVE</span></span>
<span class="Mask"><span>LIVE</span></span>
</li>
<li class="Menu-list-item" data-offset="16" onclick>
LAUGH
<span class="Mask"><span>LAUGH</span></span>
<span class="Mask"><span>LAUGH</span></span>
</li>
<li class="Menu-list-item" data-offset="12" onclick>
LOVE
<span class="Mask"><span>LOVE</span></span>
<span class="Mask"><span>LOVE</span></span>
</ul>
</div>

CSS:

$perspective:     60rem;
$font-size:       5.25rem;
$split-position:  50%;
$split-thickness: 3px;
$split-color:     #FF2C75;
%font-settings {
font-family: "Comic Sans MS", system-ui, sans-serif;
font-style: normal;
font-weight: normal;
-webkit-font-smoothing: antialiased;
-webkit-font-kerning: normal;
-webkit-text-size-adjust: 100%;
}
html,
body {
  width: 100vw;
  height: 100vh;
}
body {
  @extend %font-settings;
  background: linear-gradient(45deg, #02001F,#008080);
  transform-style: preserve-3d;
  transform: perspective($perspective);
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center; 
}
.Menu-list {
  font-size: $font-size;
  line-height: 1.2;
  text-transform: uppercase;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: rotateX(-10deg) rotateY(20deg); // overwritten by JS
}
.Menu-list-item {
  position: relative;
  color: transparent;
  cursor: pointer;
  &::before {
    content: '';
    display: block;
    position: absolute;
    top: $split-position;
    left: -10%;
    right: -10%;
    height: $split-thickness;
    border-radius: $split-thickness;
    margin-top: -($split-thickness / 2);
    background: $split-color;
    transform: scale(0);
    transition: transform .8s cubic-bezier(.16,1.08,.38,.98);
    z-index: 1;
  }
}
.Mask {
  display: block;
  position: absolute;
  overflow: hidden;
  color: $split-color;
  top: 0;
  height: $split-position;
  transition: all .8s cubic-bezier(.16,1.08,.38,.98);
  span { display: block; }
}
.Mask + .Mask {
  top: $split-position - 0.1;
  height: 100 - $split-position + 0.1;
  span { transform: translateY(-$split-position); }
}
.Menu-list-item:hover,
.Menu-list-item:active {
  .Mask { color: #FFF; transform: skewX(12deg) translateX(5px); }
  .Mask + .Mask { transform: skewX(12deg) translateX(-5px); }
  &::before { transform: scale(1); }
}

Like this, you can also create several dynamic text elements for your website. Isn’t it fun?

RESULT:

Awesome CSS3 Techniques

4. Columns layout

Usually, column-based layouts are created by using Javascript, which is quite complicated and time-consuming. But CSS has brought a way around to ease up the task of developers and web designers.

Following is the CSS column rule through which you can make a column-based layout for your website.

HTML:

<div class="container">
Place a container component in order to start building the format. Sometimes you may be able to get rid of the container later, but getting the container component makes it easier to handle across different web browsers for most fixed-width layouts. It defines how wide the content of the web page will be, as well as any external margins and inside padding.
</div>

CSS:

.container {
  /* Old Chrome, Safari and Opera */
  -webkit-column-count: 3;
  -webkit-column-gap: 40px;
  -webkit-column-rule-style: solid;
  -webkit-column-rule-width: 4px;
  -webkit-column-rule-color: orange;
  /* Old Firefox */  
  -moz-column-count: 3; 
  -moz-column-gap: 40px;
  -moz-column-rule-style: solid;
  -moz-column-rule-width: 4px;
  -moz-column-rule-color: orange;  
  /* Standard syntax */
  column-count: 3;
  column-gap: 40px;
  column-rule-style: solid;
  column-rule-width: 4px;
  column-rule-color: orange;
}

RESULT:

Awesome CSS3 Techniques

5. Screen Orientation

Many people think that screen orientation and device orientation both work for the same purpose. But that’s not the case. The orientation of the screen is a bit different from the device.

Even if a device is not capable of detecting its orientation, a screen always can. And if the device is capable also, then it’s good to have control over the screen orientation so that you can maintain or change the interface of your website.

There are 2 ways in which a screen orientation can be handled; CSS or Javascript. But it’s easy when you do it with CSS Orientation Media Query. As it enables the content to adjust its format, no matter if the browser window is in the landscape mode or portrait mode. To understand better, let’s look at the following example.

HTML:

<ul id="toolbar">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>
<p>If you want a button bar to stretch along the device's longest display dimension. You can do that quickly and automatically by using a media query.</p>

zzzzz

CSS:

/* First let's define some common styles */

html, body {
  width : 100%;
  height: 100%;
}

body {
  border: 1px solid black;

  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

p {
  font   : 1em sans-serif;
  margin : 0;
  padding: .5em;
}

ul {
  list-style: none;

  font   : 1em monospace;
  margin : 0;
  padding: .5em;

  -moz-box-sizing: border-box;
  box-sizing: border-box;

  background: black;
}

li {
  display: inline-block;
  margin : 0;
  padding: 0.5em;
  background: white;
}
/* For portrait, we want the toolbar on top */

@media screen and (orientation: portrait) {
  #toolbar {
    width: 100%;
  }
}

/* For landscape, we want the toolbar stick on the left */

@media screen and (orientation: landscape) {
  #toolbar {
    position: fixed;
    width: 2.65em;
    height: 100%;
  }

  p {
    margin-left: 2em;
  }

  li + li {
    margin-top: .5em;
  }
}

RESULT:

Awesome CSS3 Techniques

6. Comma Separated Lists

There is no doubt that Bullet lists are very commonly used in writing to convey any information more precisely and clearly. But one thing that most people struggle with is to add commas on every point of the lists.

With this below-mentioned code snippet, you can easily add commas on your list except for the last one.

HTML:

<ul>
  <li>Apple</li>
  <li>Pineapple</li>
  <li>Custard Apple </li>
</ul>

CSS:

body{ 
  font-family: Arial;
  font-size:30px;
}

ul > li:not(:last-child)::after {
  content: ",";
}

RESULT:

Awesome CSS3 Techniques

7. Animated Checkbox

Well, most of the people are very much aware of the CSS background and text animations. But, not many know about checkbox animations.

Yes, apart from background and texts, you can also make your checkbox section look visually appealing. Isn’t it great?

Below is an example which you can refer:

HTML:

<h1>Animated checkboxes using iconfonts</h1>
<!-- A list of checkboxes -->
<ul>
	<li>
		<input type="checkbox" name="one" id="one" />
		<label for="one">Create checkbox</label>
	</li>
	<li>
		<input type="checkbox" name="two" id="two" />
		<label for="two">Assign label</label>
	</li>
	<li>
		<input type="checkbox" name="three" id="three" />
		<label for="three">Import iconfont</label>
	</li>
	<li>
		<input type="checkbox" name="four" id="four" />
		<label for="four">Iconify label pseudo elements</label>
	</li>
	<li>
		<input type="checkbox" name="five" id="five" />
		<label for="five">Animate icon widths</label>
	</li>
	<li>
		<input type="checkbox" name="six" id="six" />
		<label for="six">Color the icons</label>
	</li>
</ul>

CSS:

@import 
(import 2 fonts one or heading and other for text)
h1 {
	font-size: 15;
	padding: 12px;
	text-align: center;
}
ul {
	width: 290px;
	margin: 0 auto;
}
ul li {
	list-style-type: none;
	padding: 10px;
}

/*Adding custom checkbox icons*/
label {
	position: relative;
	padding-left: 30px;
	font-size: 14px;
	cursor: pointer;
}
label:before, label:after {
	font-family: FontAwesome;
	font-size: 21px;
	/*absolutely positioned*/
	position: absolute; top: 0; left: 0;
}
label:before {
	content: '\f096'; /*unchecked*/
}
label:after {
	content: '\f046'; /*checked*/
	/*checked icon will be hidden by default by using 0 max-width and overflow hidden*/
	max-width: 0;
	overflow: hidden;
	opacity: 0.5;
	/*CSS3 transitions for animated effect*/
	transition: all 0.35s;
}

/*hiding the original checkboxes*/
input[type="checkbox"] {
	display: none;
}
/*when the user checks the checkbox the checked icon will animate in*/
input[type="checkbox"]:checked + label:after {
	max-width: 25px; /*an arbitratry number more than the icon's width*/
	opacity: 1; /*for fade in effect*/
}

/*adding some colors for fun*/
#one+label:before, #one+label:after {color: hsl(0, 45%, 40%);}
#two+label:before, #two+label:after {color: hsl(60, 45%, 40%);}
#three+label:before, #three+label:after {color: hsl(120, 45%, 40%);}
#four+label:before, #four+label:after {color: hsl(180, 45%, 40%);}
#five+label:before, #five+label:after {color: hsl(240, 45%, 40%);}
#six+label:before, #six+label:after {color: hsl(300, 45%, 40%);}

RESULT:

Awesome CSS3 Techniques

Wrapping words:

If we go deep down, then the possibility of CSS and HTML is endless. Hence we hope that the above-implemented techniques help you gain some knowledge and will be helpful to you in designing a great website.

Like it? Share it.

One Comment

  1. Great post

Leave a Comment Yourself

Your email address will not be published. Required fields are marked *