When to use PX or% in placements?

0

In internal elements of the layout, to position in margin or coordinate, when to use PX and%?

    
asked by anonymous 28.11.2014 / 14:05

1 answer

4

It depends on your need and the layout context. If it is a responsive layout use % to determine the placement. If it's a static layout, use PX .

Remembering that % is a dynamic unit of measure, that is, the element with percentage placement will vary according to its parent element, for example:

<div id="elemento_pai">
   <div id="elemento_filho"></div>
</div>

#elemento_pai {width:100%; height:100%}
#elemento_filho {width:50%; height:100%; margin-left:50%}

This example will cause the child element to change size and positioning according to parent element, always keeping the left base of the child element aligned to the center of the parent element.

And the unit of measurement in PX , is a static unit of measure, that is, it does not change according to some parent element, it alone defines the positioning and size of the element without depending on another element, so a placement with PX will be static exactly where it is defined.

    
28.11.2014 / 14:20