Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Tuesday, October 9, 2012

Web Platform Docs

If you guys didn't know, the W3C has started a project called Web Platform Docs ( currently in alpha release ) aimed at being the centralized resources for web developer.  This project has been and will continue be contributed by the main (and big) players in the web development industry.

http://docs.webplatform.org/wiki/Main_Page

If you haven't heard of that before, you can visit their "Getting Started" link,

http://docs.webplatform.org/wiki/WPD:Getting_Started

Thursday, October 6, 2011

Dump Your "clear:both", an Alternative to Clearing Floats

One of the traditional ways to solve the clearing floats problem is by adding an extra element and make it "clear:both".

<div style="clear:both" />

However this method has some draw backs :-
  1. The clear both contributes nothing meaningful to the markup besides it's used to fix a floating issue.
  2. It adds extra bits to your html code.
...
Let me show you another way of solving this problem without using an extra markup, the only thing you need to do is :-
  1. In your css where your container that contained the float elements, add
    • min-width ( or width or height )
    • overflow:hidden
That's all you need.  Well, I know if is not very intuitive, and if you still don't understand what I'm talking about,  here is the example, http://cssdesk.com/ZwJ7x.

Let me know your thoughts!

Note: Oh, btw, I believe everyone is using "clearfix" nowadays, it seems to be a standard method in the industry.  And I brought it up in this post is just in case someone out there is still using <div style="clear:both"> .


Tuesday, August 23, 2011

Another Approach to Box Model and Responsive UI (CSS)

Recently came across a "new" approach to create box in html.  Honestly, it is not a new thing, but just not many people have used it or talk about it so far.

After doing a little research and testing on it, I can think of there are quite a number of practical use cases  by using this "new" approach.  Let me show you that and let's later discuss it a little bit.

Traditional Box Model
The traditional box model is created by defining the box width, margin, padding and border ... etc.   Please read it again, "width, margin, padding and border", I'm not crazy, it is related.

If you give it a second thought, the box is created from the inside out.. First by drawing one or two line(s) (width / height ), you created a space. And then you use the padding, margin as "fillers" to expand the space.

Well, I'm not saying the box model is not good.  Honestly, I think the current box model is the correct approach to your problems.  However, what I'm mentioning here is a potential theoretical alternative.


New Approach to Box Model (CSS)
The new method I'm talking about is something very similar to coordinate system in your photoshop.  A box is being drawn by providing 2 coordinates, for example,

pointA  ( 100px, 200px )
pointB  ( 150px, 250px )

With 2 points, you can define a rectangular shape.  But how do you create 2 points in css?  Well, it is easy, position attribute has 'top, left, right, bottom', and the 2 points is just (top, left) and (bottom, right).

But the points we are going to define, instead of exact coordinates, are offset.  What does that mean??  Well, glad that you ask!  Offset is the distance from your browser window.

It also means that your box do not need a width at all, because it is drawing from outside (or defined by the offset in other words ).  Plus, you don't need to put IE hacks for this box, since the padding won't affect the box in this case. Yep, it works on even IE 5.5, cool, huh?

And for the Responsive UI part, you can mix and match the @media query, and I believe you can achieve certain degree of  Responsive UI even without much help from javascript side, since this model is using offset to calculate the box.  Try to view the demo from your smartphone and change the viewport.  Imagine what you can do with @media query in the demo.

Well, I'm talking too much, let's do a demo then :)

Note: This demo is a simple demo for drawing box model using offset.  There are so many use cases on that, and it is only limited by your imagination!!

Note: This new approach by no means is better, it is just a different approach to solve the same problem, used it as you will.




  

Monday, June 13, 2011

CSS Hacks Mix and Match

Still remember the old days CSS hacks?  No problem if you don't remember, here is a super short syntax for you to review.

Different browsers will respond to the following css differently.

#content p { color:blue; }  // older browser
html>body #content p { color:red; } // modern browser
* html #content p{color:green;}  // IE6   ( star hacks )
*+html #content p { color:#bada55; } // IE7 (star+ hacks )
*:first-child + html #content p { color:pink; }  // IE7 ( star+ hacks variation )
html>body #content p { *color:black; }  // IE7 ( star attribute hacks ) 
#content p { color:blue\0/; } // IE8


Since developer nowadays are talking more about conditional statement, and those hacks are pretty much long gone.  However, is it possible to do a mix and match with old hacks and new methods, and is there any benefit of doing so??

If you use a conditional statement ( I'm not talking about the separate css files method ), you will have something like the followings,

.ielt9 .myClass {
   ...
}

.ie8 .myClass {
  ...
}

.ie7 .myClass {
  ...
}

Do you see that when using the conditional statement, you may end up having bunch of lines that look likes the above.  And through mix and match old css hacks with this modern method, you could take advantage of the benefits of conditional statement, but it could also save you more than several lines.  For example,

.ielt9 .myClass {
    color:orange;
    *color:green;
     color:red\0/;
}

The above one will target browser less than ie9, and it is also taking care of ie8, ie7 and ie6 just in one shot. So in this way, you will save at least 2 definitions by using this mix and match hacks.