Tag: dyssahagun.com

  • I’m Seeing Red: How the color red is being useful in CSS

    So, you want to visualize how large your background is with margins and paddings?

    Utilize the color “red”. It’s easy to type in the keyboard and it appears instantly like a bright red fruit in the midst of the forest.

    For example:
    [code lang=”html” title=”HTML”]
    <div class="favorite-things">
    <ul>
    <li>Mobile phone</li>
    <li>Television</li>
    <li>Couch</li>
    </ul>
    </div>
    [/code]

    [code lang=”css” title=”CSS”]
    .favorite-things li {
    margin:1em 0;
    padding:1em;
    border-bottom:1px solid #ccc;
    }
    [/code]

    Let’s say you want to see how a background-color upon hover would affect an <li> element, you could do this in Firebug or any DOM inspection tool:

    [code lang=”css” title=”CSS”]
    .favorite-things li {
    background-color:red;
    }
    [/code]

    The element would show if you’ve got the correct spacing in your paddings and margins.

  • In CSS, what’s first in Mobile First?

    Remember when I suggested that you forget about the CSS while writing the HTML?

    Now that you’ve got your HTML markup ready, it’s time to mind the CSS.

    So what’s the first thing to do in applying the Mobile First principle?

    Forget about the floats

    Forget about which goes to the left or right. Remember, we’re building the presentational layer of the website for mobile viewports which are narrow so it’s OK to stack everything first.

    I’m currently experimenting by styling these properties in order:

    • background-color
    • color

    Styling the background-color according to the mock-up will give us a visual cue of each blocks hierarchy in a vertical manner. Then set the actual color of the text contained in each block.

    After these, it’s time to go more detailed based on the mock-up. Maybe exporting the image assets is next.

    I’ll keep you posted!

  • Background Check: Use background-color to set the background color

    Don’t simply use the shorthand if you want to set only the background color:

    [code lang=”css” title=”CSS”]
    div {background:red;}
    [/code]

    Because what that really means is:
    [code lang=”css” title=”CSS”]
    div {background:none repeat scroll 0 0 red;}
    [/code]

    The background values in order are:

    • background-image
    • background-repeat
    • background-attachment
    • background-position
    • background-color

    One of the conflicts in using the shorthand in styling only the background color is that it sets the background-image to none.

    In case that you need to style the same selector with a background image, the value in the shorthand property will persist.

  • Round Off Your HSBs

    This doesn’t have much importance other than satisfying one’s obsessive-compulsivity.

    We all take the hexadecimal values of colors to put as background-color or color of elements on our webpages.

    If you could see the HSB (hue, saturation, brightness) values of your color, they are in degree, percentage, percentage, respectively. Round them off to the nearest multiple of 5.

    For example, I get these values for a shade of yellow:

    H: 45°
    S: 57%
    B: 99%
    Hex: #fdda6d

    Transform it to:

    H: 45°
    S: 55%
    B: 100%
    Hex: #ffdc73

    This way, you put some meaning behind your colors.

  • Break It Down: Breaking a line thru CSS and HTML

    Let’s say you have this line on your webpage:

    Hey guys, you may email me at yoyo@whatsup.heh or call me at 14344.

    and you want to break the line right after the word “or”.

    Do you do this:

    [code lang=”html” title=”HTML”]
    <p>Hey guys, you may email me at <a href="mailto:yoyo@whatsup.heh">yoyo@whatsup.heh</a> or<br>
    call me at <a href="tel:14344">14344</a>.</p>
    [/code]

    or this?

    [code lang=”html” title=”HTML”]
    <p>Hey guys, you may email me at <a href="mailto:yoyo@whatsup.heh">yoyo@whatsup.heh</a> or
    <span class="break">call me at <a href="tel:14344">14344</a></span>.</p>
    [/code]

    [code lang=”css” title=”CSS”]
    span.break {display:block;}
    [/code]

    The latter? You’re doing a great start!

    Rule of thumb: Write the HTML, forget the CSS

    What I mean by this is, as you are writing the HTML markup, you should check your webpage in the browser as it is — without heavy consideration on how big the fonts should be or which color would be preettyy… Just imagine you’re a visually-impaired person “reading” a webpage.

    The same way with sentences, it should run continously without consideration on the width of its container or the length of its line.

    If we want a break in the line, it is purely for presentational purposes so do it thru CSS.

  • HTML5 Boilerplate & WordPress: Day 3 – Module Block

    Module block

    [code lang=”html”]
    <div class="mod">
    <div class="mod-cr">
    <div class="mod-hd"><h3 class="mod-heading">Heading label</h3></div>
    <div class="mod-ct"></div>
    </div>
    </div><!–.mod–>
    [/code]

    This is the basic structure of every content block in your webpage. This way, it would be modular, meaning, you could move it anywhere in the page without too much dependency on other elements.

    Update – Nov 12, 2012:

    • I added mod-hd as header for the module block
  • HTML5 Boilerplate & WordPress: Day 2 – CSS

    ::selection

    [code lang=”css” highlight=”2,3,8,9″]
    ::-moz-selection {
    color:#fff;
    background: #00b6f2;
    text-shadow: none;
    }

    ::selection {
    color:#fff;
    background: #00b6f2;
    text-shadow: none;
    }
    [/code]

    • Hex color value #00b6f2 is a nice shade of cyan
    • Font color is white

    Image replacement

    [code lang=”css” highlight=”6″]
    /*
    * Image replacement
    */

    .ir {
    display:block;
    background-color: transparent;
    border: 0;
    overflow: hidden;
    /* IE 6/7 fallback */
    *text-indent: -9999px;
    }

    .ir:before {
    content: "";
    display: block;
    width: 0;
    height: 100%;
    }
    [/code]

    • Moved up above the /* Author’s custom styles */ – so that styles of the main selector will be cascaded
    • Added display:block since most of my selectors are intentionally diplayed as a block element

    Set and reset

    [code lang=”css”]
    /*=========================Reset=========================*/
    h1, h2, h3, h4, h5, h6, p, ul, ol, li {margin:0; padding:0;}

    ul {list-style:none;}

    /*=========================Set=========================*/
    p {margin-bottom:1em;}
    p:last-child {margin-bottom:0;}
    [/code]

    Resetting all basic text tags and setting the margin for <p> to bottom.

    Clearfix inside a wide viewport media query

    [code lang=”css” highlight=”1,17-34″]
    @media only screen and (min-width: 1024px) {
    /* Style adjustments for viewports that meet the condition */

    /*
    * Clearfix: contain floats
    *
    * For modern browsers
    * 1. The space content is one way to avoid an Opera bug when the
    * `contenteditable` attribute is included anywhere else in the document.
    * Otherwise it causes space to appear at the top and bottom of elements
    * that receive the `clearfix` class.
    * 2. The use of `table` rather than `block` is only necessary if using
    * `:before` to contain the top-margins of child elements.
    */

    .clearfix:before,
    .clearfix:after {
    content: " "; /* 1 */
    display: table; /* 2 */
    }

    .clearfix:after {
    clear: both;
    }

    /*
    * For IE 6/7 only
    * Include this rule to trigger hasLayout and contain floats.
    */

    .clearfix {
    *zoom: 1;
    }
    }
    [/code]

    I changed the media query from em to px because I am targeting viewports with exact dimensions.

    Clearfix which solves floating problems are placed inside this media query because for narrow viewports, I don’t plan to use floats.

    Show .assistive-text only to screenreaders

    [code lang=”css”]
    /*
    * Hide only visually, but have it available for screenreaders: h5bp.com/v
    */

    .visuallyhidden,
    legend,
    .assistive-text {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    }

    /*
    * Extends the .visuallyhidden class to allow the element to be focusable
    * when navigated to via the keyboard: h5bp.com/p
    */

    .visuallyhidden.focusable:active,
    .visuallyhidden.focusable:focus,
    .assistive-text:active,
    .assistive-text:focus {
    clip: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    position: static;
    width: auto;
    }
    [/code]

    Update – Nov 13, 2012:

    • I added legend to .visuallyhidden class selector since I don’t need that label much

    Update – Nov 14, 2012:

    • Removed list-style of <ul>
  • Site-Building: Day Six

    Site-building: Day 6

    Polishing up some spacing by putting some margins and paddings.

  • HTML5 Boilerplate & WordPress: Day 1 – HTML

    I’ve mashed up the HTML code of HTML5 Boilerplate and WordPress to come up with something useful for my projects at International Red.

    Take a look if this will suit yours.

    Inside the <head>

    [code lang=”html” highlight=”6,10,11,14-20″]
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/main.css">
    <link rel="shortcut icon" href="img/favicon.ico">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <script src="js/vendor/modernizr-2.6.2.min.js"></script>

    <!–Facebook Open Graph–>
    <meta property="og:title" content="">
    <meta property="og:type" content="website">
    <meta property="og:url" content="">
    <meta property="og:image" content="">
    <meta property="fb:admins" content="">
    <meta property="og:description" content="">
    </head>
    [/code]

    Significant additions include:

    • initial-scale=1.0 in <meta name=”viewport”> – fixes some background image bugs
    • favicon.ico in <link rel=”shortcut icon”> – the default in H5BP does not appear in browsers
    • <link rel=”profile”> from WordPress
    • Facebook Open Graph <meta> tags – it could be removed upon integration with WordPress

    Inside the <body>

    [code lang=”html” highlight=”6,7-75″]
    <body>
    <!–[if lt IE 7]>
    <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
    <![endif]–>

    <div id="page" class="home-page hfeed">
    <header id="branding" role="banner">
    <div id="header-cr">
    <div id="header-ct">
    <hgroup>
    <h1 id="site-title"><a href="#">Site title</a></h1>
    <h2 id="site-desc">Site description</h2>
    </hgroup>
    <nav id="access" role="navigation">
    <h3 class="assistive-text">Main Menu</h3>
    <div class="skip-link"><a class="assistive-text" href="#primary" title="Skip to primary content">Skip to primary content</a></div>
    <div class="skip-link"><a class="assistive-text" href="#secondary" title="Skip to secondary content">Skip to secondary content</a></div>
    <ul id="main-nav" class="nav">
    <li id="home-nav current"><a href="#">Home</a></li>
    <li id="about-nav"><a href="#">About</a></li>
    </ul>
    <ul id="secondary-nav" class="nav">
    <li id="contact-nav"><a href="#">Contact</a></li>
    <li id="fb-nav"><a href="#">Facebook</a></li>
    </ul>
    </nav>
    </div><!–content–>
    </div><!–container–>
    </header><!–#branding–>
    <div id="main" role="banner">
    <div id="main-cr">
    <div id="main-ct">
    <div id="primary">
    <div id="primary-cr">
    <div id="primary-ct">
    <div id="content" role="main">
    Main content
    </div>
    </div><!–content–>
    </div><!–container–>
    </div><!–#primary–>
    <div id="secondary">
    <div id="secondary-cr">
    <div id="secondary-ct">
    <div id="aside" role="complementary">
    Complementary content
    </div>
    </div><!–content–>
    </div><!–container–>
    </div><!–#secondary–>
    </div><!–content–>
    <div id="primary">
    <div id="primary-cr">
    <div id="primary-ct">
    <div id="content" role="main">
    </div>
    </div><!–content–>
    </div><!–container–>
    </div><!–content–>
    </div><!–#primary–>
    </div><!–container–>
    </div><!–#branding–>
    <footer id="colophon" role="contentinfo">
    <div id="header-cr">
    <div id="header-ct">
    <nav id="footer-access">
    <ul id="footer-links" class="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    </ul>
    </nav>
    <div class="credits">
    <p id="copyright">&copy; 2012 Site title. All rights reserved.</p>
    <p id="intl-red">Site by <a href="http://international-red.com/" target="_blank">International Red</a></p>
    </div>
    </div><!–content–>
    </div><!–container–>
    </footer><!–#colophon–>
    </div><!–#page–>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>window.jQuery || document.write(‘<script src="js/vendor/jquery-1.8.2.min.js"><\/script>’)</script>
    <script src="js/plugins.js"></script>
    <script src="js/main.js"></script>

    <!– Google Analytics: change UA-XXXXX-X to be your site’s ID. –>
    <script>
    var _gaq=[[‘_setAccount’,’UA-XXXXX-X’],[‘_trackPageview’]];
    (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
    g.src=(‘https:’==location.protocol?’//ssl’:’//www’)+’.google-analytics.com/ga.js’;
    s.parentNode.insertBefore(g,s)}(document,’script’));
    </script>
    </body>
    [/code]

    Significant additions include:

    • Header – Content – Footer structure
    • -cr suffix is “container” – should contain the width of the block
    • -ct suffix is “content” – should contain the padding of the block

    If you would notice the structure of inner modules, it is Module – Container – Content.

    For example, a search box. You would style it this way:

    [code lang=”html”]
    <div id="search-module" class="module">
    <div class="module-cr">
    <div class="module-ct">Search content</div>
    </div>
    </div>
    [/code]

    In the stylesheet:
    [code lang=”css”]
    .module {float:left;}
    .module-cr {
    margin:0 auto;
    width:50%;
    background-color:white;
    }
    .module-ct {padding:1em;}
    [/code]

    In this way, the width of the block is not dependent on its padding and vice versa. The block becomes more modular and you should be able to plaster it anywhere in your site.

  • CSS Parts

    Here are the basic parts of a CSS:

    [code lang=”css”]
    p {font-size:1em;}
    [/code]

    Which translates to:

    [code lang=”css”]
    selector {property:value;}
    [/code]

    Selectors

    Selectors are the ones you target in the HTML document to apply the styles to. Basically, selectors can be:

    • HTML tags: html, body, h1, ul, li, p, etc.
    • Classes: .main-nav, .footer, etc.
    • IDs: #branding, #content, etc.

    And many more: http://www.w3.org/TR/CSS2/selector.html

    Properties

    Properties are attributes of the selector you want to control. For example, you want to control a paragraph’s font size and color, the properties are:

    • Font size = font-size
    • Font color = color

    The Full property table: http://www.w3.org/TR/CSS21/propidx.html

    Values

    Values are the values of the properties. How big or small will be the font size and which color? Say you want to make a paragraph’s font size 24 pixels and colored red, the answers are the values.

    [code lang=”css”]
    p {
    font-size:24px;
    color:red;
    }
    [/code]

    Tweak some CSS here: http://cssdesk.com/uGcKH