DEV Community

Cover image for 5 ESSENTIAL CSS TRICKS EVERY DESIGNER SHOULD KNOW
Mr Daily
Mr Daily

Posted on

5 ESSENTIAL CSS TRICKS EVERY DESIGNER SHOULD KNOW

  1. Overriding all styles
    This should be used sparingly, because if you do this for everything, you’re going to find yourself in trouble in the long run. However, if you want to override another CSS style for a specific element, use !important after the style in your css. For example, if I wanted the H2 headers in a specific section of my site to be red instead of blue, I would use the following CSS:
    .section h2 { color:red !important; }

  2. Easily resize images to fit
    Sometimes you get in a pinch where images need to fit a certain width, while scaling proportionally. An easy way to do this is to use max width to handle this. Here is an example:
    img {
    max-width:100%;
    height:auto;
    }
    This means that the largest the image could ever be is 100%, and the height is automatically calculated, based on the image width. In some cases, you might have to also have to specify the width at 100%.

  3. Apply CSS to multiple classes, or selectors
    Let’s say you wanted to add an identical border around all images, the blog section and the sidebar. You don’t have to write out the same exact CSS 3 times. Just list those items out, separated by commas. Here is an example:
    .blog, img, .sidebar {
    border: 1px solid #000;
    }
    Whether you’ve been a web designer for years, or you’re just starting out, learning how to build websites the right way can seem like a rocky, never-ending journey. Once you’ve narrowed down which languages you want to learn, you have to learn and refine your skills.
    No matter what you learn, CSS is one of those essential, but daunting skills you have to master. It doesn’t have to be so difficult, though, especially if you know a few handy and lesser-known CSS techniques to get the job done.

  4. Drop caps
    Everyone loves drop caps. It reminds us of the traditional printed book, and is a great way to start a page of content. That 1st, large letter really grabs your attention. There’s an easy way to create a drop cap in css, and it’s by using the pseudo element: :first letter. Here’s an example :
    p:first-letter{
    display:block;
    float:left;
    margin:3px;
    color:#f00;
    font-size:300%;
    }
    What this does is set the letter to 3x the size of the other letters. It sets 3px of space around the letter to prevent overlapping, and sets the color of the letter to red.

Top comments (1)

Collapse
 
efleurine profile image
Emmanuel

Drop Cap is actually a good idea. I will try it in a post