4
Important: I’m using Twitter Bootstrap, so everything is with box-sizing: border-box
.
The difficulty is this: I have an element with absolute positioning. I want its width to be equal to that of the parent element:
div.elemento-filho {
position: absolute;
width: 100%;
}
That almost works. My problem is that the element is getting wider than the father, because the width
included the margins (margin
) of the parent element.
div.elemento-pai {
width: 180px;
margin: 0px 15px;
}
In this case, I would like the width of the child element not to consider the margins, that is, to stay measuring 150px instead of 180px.
I can’t fix the width
of the child element, as it has to work for parents of different widths.
Is there any way to achieve this? In what way?
Without the
position: absolute
, seems to work. With theposition: absolute
, is much more than the margin difference. http://jsfiddle.net/ypdtY/– luiscubal