CSS

20 Useful CSS Tips For Beginners

Posted on

In the old days, we depend a lot of on developers and programmers to help update the website, even when it’s just a minor one. Thanks to the CSS and it’s flexibility, styles can be extract independently away from the codes. Now, with some basic understanding of CSS, even a novice can easily change the style of a website.

Whether you are interested in picking up CSS to create your own website, or merely to tweak your blog’s look and feel a little – it’s always good to start with the fundamentals to gain a stronger foundation. Let’s take a look at some CSS Tips we thought might be useful for beginners. Full list after jump.

  1. Use reset.css

    When it comes to rendering CSS styles, browsers like Firefox and Internet Explorer have different ways of handling them. reset.css resets all fundamental styles, so you starts with a real blank new stylesheets.

    Here are few commonly used reset.css frameworks – Yahoo Reset CSS,Eric Meyer’s CSS Reset, Tripoli

  2. Use Shorthand CSS

    Shorthand CSS gives you a shorter way of writing your CSS codes, and most important of all – it makes the code clearner and easier to understand.

    Instead of creating CSS like this

    1
    2
    3
    4
    5
    6
    .header {<br>
          background-color: #fff;<br>
          background-image: url(image.gif);<br>
          background-repeat: no-repeat;<br>
          background-position: top left; <br>
        }

    It can be short-handed into the following:

    1
    2
    3
    .header {<br>
          background: #fff url(image.gif) no-repeat top left<br>
        }

    MoreIntroduction to CSS Shorthand, Useful CSS shorthand properties

  3. Understanding Class and ID

    These two selectors often confuse beginners. In CSS, class is represented by a dot “.” while id is a hash ‘#”. In a nutshell id is used on style that is unique and don’t repeat itself, class on the other side, can be re-use.

    MoreClass vs. ID | When to use Class, ID | Applying Class and ID together

  4. Power of <li>

    <li> a.k.a link list, is very useful when they are use correctly with <ol> or<ul>, particulary to style a navigation menu.

    MoreTaming Lists, Amazing LI

  5. Forget <table>, try <div>

    One of the greatest advantage of CSS is the use of <div> to achieve total flexibility in terms of styling. <div> are unlike <table>, where contents are ‘locked’ within a <td>‘s cell. It’s safe to say most <table> layouts are achievable with the use of <div> and proper styling, well maybe except massive tabular contents.

    MoreTables are dead, Tables Vs. CSS, CSS vs tables

  6. CSS Debugging Tools

    It’s always good to get instant preview of the layout while tweaking the CSS, it helps understanding and debugging CSS styles better. Here are some free CSS debugging tools you can install on your browser: FireFox Web Developer, DOM Inspector, Internet Explorer Developer Toolbar, and Firebug.

  7. Avoid Superfluous Selectors

    Sometimes your CSS declaration can be simpler, meaning if you find yourself coding the following:

    • 1
      ul li { ... }
    • 1
      ol li { ... }
    • 1
      table tr td { ... }

    They can be shorten down to just

    • 1
      li { ... }
    • 1
      td { ... }

    Explanation: <li> will only exist within <ul> or <ol> and <td> will only be inside <tr> and <table> so there’s really not necessary to re-insert them.

  8. Knowing !important

    Any style marked with !important will be taken into use regardlessly if there’s a overwriting rule below it.

    1
    .page {<br> background-color:blue !important;<br>   background-color:red;<br>}

    In the example above, background-color:blue will be adapted because it’s marked with !important, even when there’s a background-color:red; below it. !important is used in situation where you want to force a style without something overwriting it, however it may not work in Internet Explorer.

  9. Replace Text with Image

    This is commonly practice to replace <h1>title</h1> from a text based title to an image. Here’s how you do it.

    1
    2
    3
    4
    5
    6
    h1 {<br>
    text-indent:-9999px;<br>
    background:url("title.jpg") no-repeat;<br>
    width:100px;<br>
    height:50px;<br>
    }

    Explanation: text-indent:-9999px; throws your text title off screen, replaced by an image declared by background: {...} with a fixed width andheight.

  10. Understand CSS Positioning

    The following article gives you a clear understanding in using CSS positioning – position: {...}

    MoreLearn CSS Positioning in Ten Steps

  11. CSS @import vs <link>

    There are 2 ways to call an external CSS file – respectively using @importand <link>. If you are uncertain which method to use, here’s few articles to help you decide.

    MoreDifference Between @import and link

  12. Designing Forms in CSS

    Web forms can be easily design and customize with CSS. These following articles show you how:

    MoreTable-less form, Form Garden, Styling even more form controls

  13. Get Inspired

    If you are looking around for nicely designed CSS-based website for inspiration, or just simply browsing to find some good UI, here are some CSS showcase site we recommend:

    Need more? Here’s a round up of 74 CSS Galleries.

  14. Rounded Corners in CSS

    This following article gives you an idea how to create cross-browser compatible rounded borders with CSS.

  15. Keep CSS Codes Clean

    If your CSS codes are messy, you are going to end up coding in confusion and having a hard time refereing the previous code. For starters, you can create proper indentation, comment them properly.

    More12 Principles For Keeping Your Code Clean, Format CSS Codes Online

  16. Typography Measurement: px vs em

    Having problem choosing when to use measurement unit px or em? These following articles might give you a better understanding on the typography units.

    MoreUnits of Measurement in CSS, CSS Font size explained, Using Points, Pixels, Ems, or Percentages for CSS Fonts

  17. CSS Browsers Compatibility Table

    We all know each browser has different ways of rendering CSS styles. It’s good to have a reference, a chart or a list that shows the entire CSS compatibility for each browser.

    CSS support table: #1, #2, #3, #4.

  18. Design Multicolumns in CSS

    Having problem getting the left, middle and right column to align properly? Here are some articles that might help:

  19. Get a Free CSS Editors

    Dedicated editors are always better than a notepad. Here are some we recommend:

    More – Simple CSS, Notepad ++, A Style CSS Editor

  20. Understanding Media Types

    There are few media types when you declare CSS with <link>. print, projection and screen are few of the commonly used types. Understanding and using them in proper ways allow better user accessibility. The following article explains how to deal with CSS Media types.

    MoreCSS and Media Types, W3 Media Types, CSS Media Types,CSS2 Media Types

5 tips to help you prepare for your responsive design site

Posted on Updated on

Responsive web design has gained incredible traction among designers, developers, and potential site owners. A responsive site’s efficient ability to adjust layouts on the fly for desktops, tablets, mobile and other devices with varying screen sizes makes it incredibly valuable. If you’re just delving into responsive design, it can seem like a daunting task. To help get you started, I’ve compiled a list of useful tips to prepare for your responsive web design.

 

  1. Know your platforms and browsers.
    Are you developing for a mobile site or a desktop? And for which browsers? Knowing this ahead of time helps you assess what your limits are, if any, like knowing you may want to steer away from CSS3 on IE while embracing it on mobile because CSS3 on mobile is awesome.
  2. Know the min and max sizes.
    No site can be infinitely responsive. Once you know the answers to #1, it may help in deciding the minimum and maximum resolution. This way you know what you’re aiming for when re-sizing elements on your site. Images and page elements can only get so large or small before they start to look strange or break the UI.
  3. Percentages in CSS.
    Percentages should be used for just about everything, mainly padding, margin and/or the widths of elements. What I like to do is find out what these numbers are with pixels and then use my browser inspector to get the closest I can with percentage. Also, instead of trying to be a math whiz, I’ll let Google find me a calculator and just get my percentages that way. Decimals are okay in percentages as well: http://www.percentagecalculator.net/
  4. Fonts should steer away from percentages.
    While percentages are fantastic for CSS, re-sizing fonts with percentages can be tricky. It can be done but there is a risk that re-sizing font with percentages may render your type completely unreadable, at some point. That’s certainly something we want to avoid, so instead, it’s best to either leave the original desktop sizes alone or bring them down a point or two, so long as it’s still readable. Keep to using pixels with font sizes and line heights so that you can have more control.
  5. Sometimes bigger is the way to go on a smaller platform.
    I used to think that responsive meant taking a desktop site and just shrinking everything down to proportion. That’s not necessarily the case, and to adjust to smaller screen sizes like tablets and phones, it’s better practice to shift elements and/or make elements larger. Simplify the design to give the user a legible version of the site with everything that’s necessary. Clicking an element with a mouse versus your fingertips is an entirely different experience.

What other useful tips do you have for responsive web design? Share with us in comments.

5 useful CSS tips for responsive design

Posted on Updated on

In the past few years, responsive web design, or RWD, has been steadily gaining steam in the development world. With the explosion of mobile devices, tablets, notebooks, e-readers, and more, responsive design becomes ever more relevant.

In today’s post, we bring 5 useful CSS tips to consider for responsive design.

 

  1. Media Queries. Media Queries are your friend. Use as many of these in your css as you need to. I used to think that I should have some sort of limit to using these, but I realized depending on site design, if you need 10 different Media Queries to make your site shift smoothly – then by all means, use 10.
  2. Auto. Whenever I’m using a percentage width on an element, usually an image, but I don’t want to distort the image, I’ll make sure to put the height at auto. This keeps the image in proportion with its percentage width. And if you ever want to keep the image from getting too large or small with height or width, this is where max-width/height comes in handy.
    .my-img { width: 100%; height: auto; }
  3. Min-height/max-height, min-width/max-width. Once you know you’re minimum and maximum sizes, depending on what platforms/browsers your site is for, you’ll be using these a lot to keep elements from getting too large or too small.Some elements work great at being at 100% width, like a banner, but at some point, this can get heavy as you would need a pretty large image to ensure that this would resize smoothly on all screen resolutions – which is why restricting sizes are handy. It would also help to make your max and min sizes a class for easy application site-wide.
    <div class=“container”>
    <img src=“images/my_img_a.jpg” class=“max-min” />
    <img src=“images/my_img_b.jpg” class=“max-min” />
    <img src=“images/my_img_c.jpg” class=“max-min” />
    <img src=“images/my_img_d.jpg” class=“max-min” />
    </div>
    .container { width: 600px; }
    .container img { width: 25%; height: auto; }
    .max-min { max-width: 150px; min-width: 75px; }
  4. Box-sizing. When I discovered this, my mind was blown. Using box-sizing on anything with a percentage width will take padding into account rather than having to adjust the width due to padding. Of course, this only works best on mobile or any browser that supports CSS3.
  5. Overflow: hidden. I don’t just use this for responsive design, but it’s such a handy trick to have. Instead of using clearing divs, I can clear containers by just applying an overflow of hidden on them. I like to make this a class for easy application as well, and it’s so much cleaner than inserting an extra div for clearing.
    <div class=“container overflow-hidden”>
    <img src=“images/my_img_a.jpg” class=“max-min” />
    <img src=“images/my_img_b.jpg” class=“max-min” />
    <img src=“images/my_img_c.jpg” class=“max-min” />
    <img src=“images/my_img_d.jpg” class=“max-min” />
    </div>
    .overflow-hidden { overflow: hidden; }
    .container img { float: left; }

What are your favorite CSS tips for responsive design? Share them below.

 

Positioning in web design

Posted on

Understanding how positioning in the web works is crucial for responsive web design, as it allows us speak the same language with developers and helps make better design decisions. Compared to static design tools (Photoshop, Illustrator, Sketch) it’s more complex as well, because the position depends on everything around it; scrolling, screen size and other factors.
To complicate things even more, different types of position in the web have names that are quite confusing – Static, Absolute, Relative and Fixed – where static isn’t really static and absolute depends on the placement. Therefore here is a short, visual manual of what is what.

 

The Z-index

Z-indexBefore we jump to positioning, lets explain what the Z-index is as it affects all types of positioning in some way. So Z-index is a simple way to tell which element is in front of another one, similar to layers in the static design apps.

DO: Use for buttons, clickable stuff.
DON’T: Avoid text being on top of that clickable stuff as it becomes unclickable…

 

Static position

Static positionStatic is the default positioning type. Although the name suggests that nothing is moving it isn’t the case. Static means elements are static to the flow – if one moves, another will move as well.

DO: Your safest bet it will scale on all browsers well. Adding Min and Max limits horizontally and vertically will help to keep the design perfect.
DON’T: Watch out for text blocks with changing content as it can break the design.

Absolute position

Absolute position

Absolute positioning defines the element based on X and Y property. The tricky part is that it will be absolute to the parent element that has a position of Relative, Absolute or Fixed. If there are none, it will be absolute to the page. Absolutely positioned elements don’t care much about the flow, meaning they live in their own universe and aren’t affected by anything around them. It will appear on top of any static positioned element.

DO: A menu or logo that needs to be always on the top of the page? Go for it!
DON’T: Absolute and Responsive aren’t best friends.

Relative position

Relative position

Relatively positioned elements behave exactly like static ones, but they serve as a local frame of reference for absolutely positioned child elements.

DO: Use on a parent container for absolute positioned elements.
DON’T: If a logo or a badge has to always sit on top of the screen, don’t wrap them in a relative element.

Fixed position

Fixed position

Fixed means the position will always be locked to the size of the browser’s window (viewport).

DO: Navigation that is always visible on the top of the screen? Yes!
DON’T: If something is behind a fixed element it won’t be clickable.

Real life

In real life the type of position is often changed as we go and they are mixed together. For example if you want a banner be scrollable until it reaches the top, then at first it will be absolute, but then it will become fixed by adding some JavaScript.

These are the basics, but there is more.

What if you want to align two elements side by side? This is where float properties, inline blocks and margins come into play.