Skip to main content

5 CSS Tips and Tricks to Try in Your Next Project

 

5 CSS Tips and Tricks to Try in Your Next Project



Looking for inspiration on how to add a twist to your project design? Take a look at these 5 CSS techniques and have fun experimenting with some bold ideas!

1. Bring back the 90’s with the background-clip

Have you ever wondered how to apply a gradient or a texture to the text in CSS? The good news is you can easily achieve that with the background-clip property!

First, we need to apply the background color to our <h1>, then use the value text for the background-clip property and set the text color to transparent.

<h1 class="wordart">The background is clipped to this text</h1>

h1 { 
     background-color: #ff1493;
     background-image: linear-gradient(319deg, #ff1493 0%, #0000ff 37%, #ff8c00 100%);
}
.wordart {
     -webkit-background-clip: text;
     color: transparent;
}

And voilà, the 90’ style WordArt is ready!



2. Crazy shapes with clip-path

If you like to experiment with your designs, you might want to try the clip-path property. Clip-path creates a clipping region that sets what part of an element should be shown. Anything outside the clip-path (shape’s boundary) won’t be visible.

To create this simple polygon I applied .clipped class on the image and used this path:

.clipped {
      clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

How does it work? Well, the set of two values before a comma are X (horizontal axis) and Y (vertical axis) coordinates.

Let’s consider our initial rectangular image. The path (starting from the upper right corner where X =0 and Y = 0) would look like this: (0 0, 100% 0, 100% 100%, 0 100%).

Now coming back to our simple polygon - the initial coordinates start exactly in the middle of the X-axis, so that’s why the first pair is X50% and Y0. From there we want to draw a line to the next point which is in the middle of the Y-axis, so what we get is X100% and Y50%. The next line goes from that point to X50% and Y100%, and so on. It can be difficult to wrap your head around it at first, so the best way is to try it yourself and experiment a little!


3. It’s all about the details - change text selection color

This is a simple one, but it can add that extra touch to your design. To change the color of the selected text use ::selection pseudo element that will override the browser settings and apply the color you choose.

::selection {
      background: black;
      color: white;
}


4. Add filters to your images

Thanks to the filter CSS property you can add graphical effects like blur or color shift to an element, for example, an image or a background.

Below you can see 4 images. The first image is the original with no filters applied. The second one is the same pic with the blur effect on it, then goes sepia effect and saturate effect on the last one. Pretty cool, huh?

.blur {
  filter: blur(5px);
  }

.sepia {
  filter: sepia(75%);
 }

.saturate {
  filter: saturate(10%);
}


5. Check the browser support

Let’s finish off with a handy CSS-rule @supports that allows you to adjust your declarations for CSS properties depending on browser support. State your condition in the parenthesis - the code will be rendered only if the condition is true. If the browser doesn’t understand a given CSS property the codewon’t be generated. You can use @supports not to provide an alternative CSS (just make sure that the browser supports @supports!)

@supports (display: grid) {
  div {
    display: grid;
  }
}
@supports not (display: grid) {
  div {
    float: left;
  }
}

Thanks a lot for reading.








Comments

Popular posts from this blog

How to Use else if in JavaScript with Examples

  How to Use else if in JavaScript with Examples The if and else-if statements are commonly used commands in the field of programming. Computer programmers learn if statements during their beginner-level courses, which makes this a very basic lesson for developers. The statement has a very similar use in JavaScript, Java and C, but we will be focusing on how to use if and else if in Javascript, in this article.    “If” is just the first conditional statement, which is followed by a series of conditions that help you make more complex decisions throughout the program. Once you have a stronghold over these conditional statements, you can start working your way through small programs.  Apart from “If” we have “else-if”, then we have “else-if else-if”, and then there’s nested-if as well. Below you can find each of these if statements explained with examples.  Using IF in JavaScript The if statement is always followed by a condition. Then it is further followed...

Detecting The User's Color Scheme Preference With CSS

Detecting The User's Color Scheme Preference With CSS If you’re a developer, chances are that you use dark mode on your machine and code editor. If not, what are you waiting for? Join the dark side! Jokes apart, it is common nowadays to allow users to select a different theme when visiting a website. Now you can do this with CSS only, not the theme selection itself, for that you still need JS but with CSS you can now detect the user’s machine color scheme (light or dark) and display the correct colors on your website immediately. To do this we need to use the CSS variables. According to the website  Can I use , the “CSS variables” feature is available on 95% of the currently used browsers around the world. We also need to use the  prefers-color-scheme  media query, which according to  Can I use  is supported by about 90% of the currently used browsers. In this article, I will show you how to use the CSS variables and the  prefers-color-scheme  to setup...

Top 10 Python Frameworks Ranked on Github

  Top 10 Python Frameworks Ranked on Github A framework is a library that makes building web applications easier. Frameworks provide a structure for developers so they can focus more on the business logic of their applications. Python has one of the largest ecosystems with a great number of different libraries, frameworks, and tools for developers. Let's take a look at the best Python  frameworks for web development . Here is a list of the ten highest-ranked Python frameworks  on GitHub. Django    Django is an open-source framework that makes things very fast and scalable. It enables programmers to develop apps and websites of different complexity within a short time. Django's advantages are reusability of components, less code, low coupling, and a principle of not repeating. Moreover, the framework is easy to use. You don't need special tools to develop a Django project. You can write it in a typical text editor, such as notepad. In this way, Django is easy to ...