my objective is to put a 5px height green strip at the bottom of a div.
Hi,
If it’s just a green strip you are wanting that could be done with a bottom border. Since you have placed text in that div I assume you are wanting content in it which would warrant the need for a box.
There are two ways you can get it at the bottom.
Place that bottom div outside of that .box2 div and drag it back in with a negative top margin.
Absolute position the bottom div in the .box2 div. You will need to set position:relative on the parent so it becomes the Containing Block.
Using either one of those methods you will need to set a bottom padding on the parent to keep the list items away from the content in the bottom div.
Did you actually tried Rayurs example. The only things I see different to the original box2 are the position relative, which can never be bad and a padding? So the question is what is it that will mess up the css when using it
No, I can not use your code because you are changing css .box2 .
All I did was add position:relative and a bottom padding, how can that break your existing page? If it has to be a fixed height then just allow for the padding as it will be included in the height.
height:270px; /300px total w/ 30px bottom padding/
The relative position might cause some layering changes but that could be fixed with z-index.
please suggest what changes I can do only in .box2tab to get a green strip(of height say 5px) at the bottom as shown in the figure.
I already explained the only two ways it can be done with CSS.
If I drag the bottom div up with a negative margin I will have to alter your html.
If your asking me to put the div at the bottom without changing your code then I can’t help you.
If we did not do that the AP element would be positioning from the viewport or the nearest positioned ancestor.
If the value of the position property is absolute, the containing block is the nearest positioned ancestor—in other words, the nearest ancestor whose position property has one of the values absolute, fixed, or relative. The containing block is formed by the padding edge of that ancestor.
The relative positioning on the parent should not cause any problems for you. If it does then you would need to control your stacking orders with z-index.
It means that if you want an AP child to position within it’s parent that parent must have positioning (other than the default of static) applied to it. It can be position:fixed; position:absolute; or position:relative;
But in this case, we only had the parent <div> …so AP element should be from the nearest parent <div> … is not it ?
If that parent div was the only div on the page and you do not use position:relative on it then the AP element would position from the viewport (the html element) if you try to set any offset properties on it (left:0; etc.).
Did you read the links I gave in my previous post? Once you understand how positioning works you will see why you need to define the containing block.