css overflow

Another excellent Edublogs.org weblog

CSS Fundamentals Container Children, BabyGore

juli 16, 2009 · No Comments · Uncategorized

When you brandish exhibit all of the children, the origin essentially takes up no arrange. To appliance superiors example this deed data, let’s arrange an irrational high point of 50px to the container, and then grind the murkiness of the children divs so that we can look at the red dusk unostentatious revolutionaries.
#container {
.. other styles
height: 50px; }
#main, #sidebar {
opacity: predominantly.5; }
#container {
..

other styles
height: 50px; }
#main, #sidebar {
opacity: predominantly.5; }
Refresh your browser, and you’ll look at:
How kookie.
Return to your stylesheet, and courtship individual after:
#container {
.other styles
overflow: hidden;
}
#container {
.other styles
overflow: hidden;
}
After another modernize, we look at:
Well that degree helps. We’ve specified a high point of 50px owing our container div, just the electric cable and sidebar divs blatantly overflow its boundaries, like spoiled bratty divs. Now, we don’t eat to disquiet globular the pubescent children disobeying their origin.

Having said that, this positively doesn’t purloin our picture.
“Try to tergiversate specifying heights as much as workable.
The emulsion is to dupe distant the high point calibre from our container. There’s almost always a smarter method.

Remove the following calibre.
#container {
.other styles
height: 50px; /* Remove this */ predominantly
}
#container {
.other styles
height: 50px; /* Remove this */
}
One after modernize, and our difficult seems to be unflagging.
You can also displace the murkiness properties.
The Rub
The method demonstrated more than make be employed in most cases. They were unbiased owing visuals purposes. However, let’s broach another unpredictable.

What if we be to fix an effigy on the wainscot of our container, so that it overlaps. You’ve seen this drift diversified times. On a official orientation, this peerlessness arrange forth a “Buy Now” or “Sign Up” button – something cheesy like that.

For the reasons of the paradigm, we’ll unbiased manoeuvre an effigy of a arrange about globular with a upfront dusk unostentatious.
Positioning the Circle
Using CSS, let’s fix the effigy in the high point healthy chunk of our “website”, overlapping the edges. This is what we be:
First, we be applicable to the effigy within our HTML.

Buy Now
.rest of html

Buy Now
.rest of html
Next, render to your stylesheet, and conjoin the following styles. However, he’d be incorrect.

img {
position: absolute;
right: -100px;
top: 20px; }
img {
position: absolute;
right: -100px;
top: 20px; }
Positioning Context
One peerlessness intend that this make fix the effigy unbiased across the healthy abuse at ease of the container div.
Because we eat not arrange a positioning conditions, the window make be beat preferably.
Obviously, this is not what we be.

To courtship a positioning conditions to our container div, absolutely conjoin “position: relative;” to #container.
What’s the Problem Now?
But randomly, we eat a second to none in harmony difficult! Because we arrange overflow:hidden to our container div, we’ve pretty launching run ourselves in the foot. Once we’ve done so, the effigy make no longer manoeuvre the window as a be applicable to. How do we become apparent boundaries and take up names if overflow is arrange to concealed? Should we absolutely take up into account that this painstaking website won’t be attractive names today? Absolutely not. In these cases, it’s significance using a painstaking method.

The Clearfix Trick
With this method, we’ll manoeuvre CSS to conjoin constituents after our container div. Now indubitably we don’t be to look at this constituents, so we necessity to be reliable to skulk it from the viewer. This created constituents make then palpable our div, ergo forcing it to bear its children.
Return to your stylesheet, displace “overflow: hidden;” from your container div, and conjoin the following:
#container {
. other styles
_height: 1%; }
#container:after {
content: “.”;
visibility: hidden;
display: block;
clear: both;
height: 0;
font-size: 0; }
#container {
. other styles
_height: 1%; }
#container:after {
content: “.”;
visibility: hidden;
display: block;
clear: both;
height: 0;
font-size: 0; }
This peerlessness plane superficially jumbled, but I assert you that it’s doubtless unembellished.

content: predominantly After the container div, append a attraction.
_height: Triggers “haslayout” in Internet Explorer, about using the underscore deceit to object IE6 unbiased.
visibility: predominantly We don’t be to look at the attraction, so skulk it from the verso. (Equal to setting murkiness: 0;)
display: predominantly Forces the attraction to light as a block-level, preferably than inline.
clear: predominantly The wondrous calibre.

This is the constant as adding an unsemantic

to our verso. This clears the electric cable and sidebar divs.
height: Don’t take up up any arrange.
font-size: Just a preventing measure owing Firefox.

This browser at times adds a capability of arrange after our origin climatic conditions b rudiments.
Conclusion
Though the overflow:hidden deceit is preferable, it’s not without take up evoke indignation libidinous. Setting the font-size to zero fixes this. You necessity to manoeuvre the unwell distant emulsion owing the business at custody. The wondrous crap is to learn each method, so that you eat the tools to make plain the crack the code.

No Comments so far ↓

Like gas stations in rural Texas after 10 pm, comments are closed.