CSS Tricks

Discussion in 'Web Design, HTML And CSS' started by pradeep, Oct 5, 2005.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    All you all might be knowing, CSS based pages are search-engine friendly, so we all try to implement CSS in our web pages, so here are a few CSS tricks which will help you work with ease.

    CSS font shorthand rule

    When styling fonts with CSS you may be doing this:

    Code:
    font-weight: bold;
     font-style: italic;
     font-variant: small-caps;
     font-size: 1em;
     line-height: 1.5em;
     font-family: verdana,sans-serif
    There's no need though as you can use this CSS shorthand property:

    Code:
    font: bold italic small-caps 1em/1.5em verdana,sans-serif
    Much better! Just a few of words of warning: This CSS shorthand version will only work if you're specifying both the font-size and the font-family. The font-family command must always be at the very end of this shorthand command, and font-size must come directly before this. Also, if you don't specify the font-weight, font-style, or font-variant then these values will automatically default to a value of normal, so do bear this in mind too.

    Two classes together

    Usually attributes are assigned just one class, but this doesn't mean that that's all you're allowed. In reality, you can assign as many classes as you like! For example:

    HTML:
    <p class="text side">... 
    Using these two classes together (separated by a space, not with a comma) means that the paragraph calls up the rules assigned to both text and side. If any rules overlap between the two classes then the class which is below the other in the CSS document will take precedence.

    CSS border default value

    When writing a border rule you'll usually specify the colour, width and style (in any order). For example, border: 3px solid #000 will give you a black solid border, 3px thick. However the only required value here is the border style.

    If you were to write just border: solid then the defaults for that border will be used. But what defaults? Well, the default width for a border is medium (equivalent to about 3 to 4px) and the default colour is that of the text colour within that border. If either of these are what you want for the border then you can leave them out of the CSS rule!

    CSS document for printing

    Lots of web pages have a link to a print-friendly version. What many of them don't realise is that there's no need because you can set up a second CSS document to be called up when a user prints the page.

    So, your page header should contains links to two CSS documents, one for the screen, and one for printing:

    HTML:
    <link type="text/css" rel="stylesheet" href="stylesheet.css" media="screen" />
     <link type="text/css" rel="stylesheet" href="printstyle.css" media="print" />
    The first line of code calls up the CSS for the screen (notice the inclusion of media="screen") and the second line calls up the CSS for the printable version (using media="print").

    So, what commands should you put in this second CSS document? To work it out, open a blank document and save it as printstyle.css. Next, point the screen CSS command to this document so that the command reads:

    HTML:
    <link type="text/css" rel="stylesheet" href="printstyle.css" media="screen" />
    Now just keep entering CSS commands until the display on the screen matches how you want the printed version to look. You'll certainly want to make use of the display: none command for navigation, decorative images and non-essential items. For more advice on this, read Print Different, which also mentions the other media for which you can specify CSS files.
     
    karthikp likes this.
  2. juresh

    juresh New Member

    Joined:
    Sep 11, 2008
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    HI

    nice read. I think you need some more points to add. Ok I have some.
    thanks
     
  3. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    Two classes together

    Usually attributes are assigned just one class, but this doesn't mean that that's all you're allowed. In reality, you can assign as many classes as you like! For example:

    <p class="text side">...</p>

    Using these two classes together (separated by a space, not with a comma) means that the paragraph calls up the rules assigned to both text and side. If any rules overlap between the two classes then the class which is below the other in the CSS document will take precedence.
     
  4. Full Zip Hoody

    Full Zip Hoody New Member

    Joined:
    Sep 29, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Programer
    Location:
    US of A
    CSS based pages are search-engine friendly, so we all try to implement CSS in our web pages thanks for the tricks!
     
  5. juliaandrews

    juliaandrews New Member

    Joined:
    May 12, 2011
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    I have no brief knowledge so thanks for sharing the detailed information.
    Thanks
     
  6. haleysalvador

    haleysalvador New Member

    Joined:
    Apr 15, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.dotline.com.au/
    CSS stands for Cascading Style Sheet and it is useful to add a style to a web document. CSS specifies a priority scheme to determine which style rules apply if more than one rule matches against a particular element. It is also easy to use and once CSS is ready then it will call for any new web design.
     
  7. shrnmlss6

    shrnmlss6 New Member

    Joined:
    Jul 20, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thanks pradeep for sharing this nice concepts on CSS
     
  8. kumkum01

    kumkum01 New Member

    Joined:
    Apr 13, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    In my point of view it is very harmful suggestion in this site.....Thanks for share useful information in here...:snore::snore::snore:
     
  9. karthikp

    karthikp New Member

    Joined:
    Sep 3, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    The multiple classes and document printing tips were quite informative. I'm familiar with the basics of CSS and am looking to expand my knowledge. These tips are really good. Hope you post more tips like these! :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice