Reputation: 47945
I have this code :
<div class="areaButton">
<input type="submit" value="Add">
</div>
.areaButton
{
float:left;
position:relative;
width:200px;
margin-left:18px;
margin-right:18px;
background-color:red;
}
.areaButton input
{
position:absolute;
right:0px;
top:0px;
}
but as you can see, the Input doesnt "feel" the container (where is the background-color:red;
)?
Upvotes: 1
Views: 4216
Reputation: 9821
<div class="areaButton"> <div> THis is the are around the button</div> <input type="submit" value="Add"> </div> .areaButton { float:left; position:relative; width:200px; margin-left:18px; margin-right:18px; background-color:red; } .areaButton input { position:absolute; right:0px; top:0px; background-color:red; border:5px solid yellow; }
Upvotes: 2
Reputation: 8760
put a height to the .areaButton div the same with the height of the input.
.areaButton
{
height: <same height as the input>;
....
}
or put another element inside the div
<div class="areaButton">
<input type="submit" value="Add">
<span> </span>
</div>
Upvotes: 2
Reputation: 102745
Setting position:absolute
removes the element from the document flow, meaning it basically doesn't occupy any space. Since this is the only element in the div, and there is no height width or padding on it, it doesn't take up any space either, so you cannot see the background.
Upvotes: 3
Reputation: 124768
Browsers insert default margin and padding on some elements, that's what CSS resets are for.
As you mark your input element as position: absolute
, it gets taken out of the page flow, and the container won't expand to fit the element. You have to add height to the .areaButton
element to see the background.
See my update:
Upvotes: 4