Center a <div> using percent

[css] Center a <div> using percent

O06cAqH.png


Code:
-----------------------------
|                           |
|                           |
|                           |
divide it by 3

-----------------------------
|  33%   |  33%    |   33%  |

^
Code:
div.center{margin-left: 33%; width: 33%}
viola you have a centered div.

Code:
-----------------------------
|20%  |       60%      |20% |
^
Code:
div.sidebar-left {width: 20%; }
div.center{width: 60%}

warning: padding will destroy this. be careful of using them.

Code:
div.center{ margin-left: 20%; padding: 5%; width: 50%;}

"padding:" will add padding left and right so 5 + 5 = 10, 60 - 10 = 50.
 
Thread starter Similar threads Forum Replies Date
ESofty Newcomers Introductions 1
M iPhone 0

Similar threads


Top Bottom