I would like to know what is the difference, if any, between left
and margin left
or right
and margin right
in CSS
.
Could it be that the difference is that one is CSS
and the other is CSS3
?
I would like to know what is the difference, if any, between left
and margin left
or right
and margin right
in CSS
.
Could it be that the difference is that one is CSS
and the other is CSS3
?
Yes .
One is for positioning elements and the other is for setting margins to the element.
Practical example:
For the properties to work
left, right, top, bottom
you have to declare the property firstposition
, in the example you will see that it does not work in the andcaja-margen
properties .top
left
With the properties
margin-*
|-top -right -bottom -left
is used to specify a space around a box and can be specified independently.Property shorthands
margin
:margin: [top, right, bottom, y left]
egmargin: 10px;
margin: [top y bottom] [left y right]
egmargin: 10px 10px;
margin: [top] [right y left] [bottom]
egmargin: 10px 10px 10px;
margin: [top] [right] [bottom] [left]
egmargin: 10px 10px 10px 10px;
Short answer
Yes, there is.
long answer
The property
left
is used to position an element, that is, to indicate that the element is positioned with a valuex
to the left with respect to the element it is referencing. This property can only be done if the element is positioned (with positionrelative
,absolute
orfixed
).On the other hand, the property
margin-left
does not take into account the positioning reference of the object, but rather the margin that we are going to establish for the element. That is, it will not position the element with respect to another, but it will place a left (or right) margin regardless of where it is positioned.If you have doubts about what each type of positioning performs, you can see the answer I gave in this other question: What is the difference between position: relative, position: absolute and position: fixed?