How can I avoid div overflowing my container without using overflow:hidden? - html

In my new design, I'm using a wrapper div. My problem was that elements inside my wrapper was floating outside my div and I got the problem described in the Float Clearing section over at css-tricks.com.
I solved this by adding overflow:hidden and everything works fine. There is just one problem. Inside my header wrapper, I have a drop down menu that is no longer visible.
My drop down menu is inside my settings container.
I have tried setting settings to position: absolute; z-index: 800;, but that didn't help.
How can I solve my wrapper issue and still be able to show specific items outside my wrapper?
Her is my fiddle: http://jsfiddle.net/sXVbT/3/
Update
I just had peek at bootstrap css and they are using display:table. This works just as good as overflow:hidden. Is there any cavities using display:table? If not, why haven't people been using this instead of all the other different solutions?
They also have additional CSS
.wrapper:before, .wrapper:after {
content: "";
display: table;
line-height: 0;
}
.wrapper:after {
clear: both;
}
.wrapper:before, .wrapper:after {
content: "";
display: table;
line-height: 0;
}
Do I need this? I don't see any benefits in my fiddle: http://jsfiddle.net/sXVbT/5/.

It will (mostly) work fine with display: block instead of table in .wrapper:after.
In general, people tend to avoid display: table and its cohorts in css, because they (undeservedly) bear the stigma of the old "layout with tables" hell. I say "undeservedly", but I must admit that I rarely if ever use them either. display: table-cell does have various side effects, but I haven't used display: table enough to tell if it has any.
But I'm quite sure display: table on the parent element doesn't do much (in terms of clearing floats) - and Chrome seems to confirm it when removing the :after part of the css on your jsFiddle.
It's actually the .wrapper:after that does the job (although you don't need two identical css rules):
.wrapper:before, /* You can leave this out. It prevents top
margin-collapse, and isn't part of the clear
solution itself */
.wrapper:after
{
content: ""; /* Adds content, so you don't have to.
An Opera bug means you may need a space: " " */
display: table; /* May be 'block', but if you use
:before, it must be 'table' */
line-height: 0; /* Not sure why it would be needed */
}
.wrapper:after {
clear: both; /* Does the actual clearing for you */
}
So the short version is:
.wrapper:after {
content: "";
display: block;
clear: both;
}
Unless top margins of your child elements collapse. In that case, use the bootstrap version (although I still don't see the need for the line-height):
.wrapper:before, .wrapper:after {
content: "";
display: table;
line-height: 0;
}
.wrapper:after {
clear: both;
}
To be clear, what the :before part does is make this solution work exactly like overflow: hidden (except for the unwanted part where overflowing content becomes, well, hidden). overflow: hidden had the advantage of letting any contained elements that weren't floated keep their top and bottom margins. Some other solutions collapsed those margins, and you had to use padding on the container instead, if you needed space between the container and non-float children.
The :before trick lets the contained non-float elements keep their top margin. The :after part already takes care of their bottom margin, in addition to actually doing the clearing of the floats.

Related

How to make the main div tag get a higher height if content is added in the two floating divs (#content and #sidebar)?

Please look here to see the problem I've got:
http://jsfiddle.net/M8aV5/
#main {
width: 940px;
padding: 20px;
background-color: #ffffff;
}
(you do best by looking at the jsfiddle as I'm not completely sure which code is affecting this problem)
As you can see when more content is added to sidebar the #main div tag doesn't stretch down which makes everything look bad.
For quite a while I have just put a standard height on the #main div tag but right now it feels like I want the content to be able to stretch out how much it want to without it being ugly.
I'd really appreciate some help on this since I've got absolutely no idea where to look for an answer on this.
You need to clear the floats. There are a number of different ways to achieve this. The method I would recommend is called a clearfix. See it in action on your code here: http://jsfiddle.net/M8aV5/1/
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
Then just add the .cf class to your container #main. Details about this can be found here: http://nicolasgallagher.com/micro-clearfix-hack/
Another option would be to add overflow:auto property to the #main. See http://jsfiddle.net/M8aV5/2/ for a working example.
This a fairly popular option as well. There is a pretty good discussion between the two options here: ClearFix vs Overflow

How to add a border to only percentage of width of element, CSS Trick

The Issue...
Once again I am searching for a cool CSS trick to help me to achieve an effect whilst preventing the use of untidy HTML...
The following image shows what I am trying to achieve, notice the top and bottom borders only stretching around 70% of the width...
A Starting Point
As a starting point I have created the above using what I would call 'untidy HTML' to add these dividers to the list.
Here is my jsFiddle: http://jsfiddle.net/E93UE/
You will see I have <li class="divider><!-- Divider --></li>, this is what I want to get rid of if possible
My Question
So, if the above has not explained well enough, I would like to apply a border to a block element, but only show the border for a specific width of the whole element.
Obviously this cannot be achieved using just border:XXX, it is likely to need some :before and :after selectors...
Possible Solutions...
I have had two thoughts of how this could be achieved, one is not too practical, and the other I am not too sure how to implement (these are just ideas):
Set the width of the list element and give it overflow:visible, all elements within have position:absolute and then just apply margins to bring the elements out of the list box... (not a good fix, prefer my original)
The other solution, which I am not too sure how to implement, may be the way to go. By apply two :before elements with position:absolute you could overlay the edges of each border (I think)
Give a border to :after pseudo-element (demo):
.separated:after {
content: "";
display: block;
width: 70%;
margin: 1em auto 0;
border-bottom: solid;
}
I recreated your divider using :before/:after pseudo-elements:
http://jsfiddle.net/thirtydot/E93UE/1/
#staff_list li:first-child:before, #staff_list li:after {
content: '';
display: block;
margin: auto;
position: relative;
bottom: -26px;
width: 500px;
height: 2px;
background: #b9b7b6;
}
#staff_list li:first-child:before {
top: -14px;
bottom: auto;
}
The numbers need tweaking, and you need to test it when you have more text, but it's probably close enough. I made other changes to help this solution work, compare your original demo to mine.

Issue with Sidebar positioning

I have created my first template but my sidebar is not working as expected. Please take a look at this: http://neo4evr.com/templates/torque/
As you can see, the sidebar has gone down to the footer position and not at the side of #content div, as I wanted. Can anyone help me to bring it beside the content div?
You need to properly clear your #container div and float your content to the left to fix your issue. Try this:
#container:after {
clear: both;
}
#container:before, #container:after {
content: "";
display: table;
zoom:1; /* ie fix */
}
#content {
float:left;
}
This should be pretty easy. Just add display: inline-block to the div#content. The sidebar will then goes up and sits next to the div#content. One thing you might notice though, the sidebar might be a little bit higher than the content. If you want to take it down a little bit just so that it aligns with the content, just add the same amount of padding to the top of the sidebar like the one with the content. Which in this case, it's 20px.

IE7 Absolute Position starts at top of line as opposed to other browsers

I created a fiddle that exemplifies the problem:
http://jsfiddle.net/vZtBb/
This is working exactly as I want it, but the problem is that in IE7 the absolutely positioned span (hover-tooltip-container) starts at the top of the line instead of at the bottom like it does in the other browsers. If you add a border to hover-tooltip-container, you can see this.
This is a problem because I want the tooltip to go up, but the anchor to still be exposed. You should be able to mouse over the tooltip as well, but the gap in IE7 makes this impossible.
If there is any way to get the hover-tooltip-container span to start in the same place on the line in IE7, IE8, and FFX, that would be perfect.
Javascript is not a solution.
The most simple thing you could do with the code you already have, is add a star hack to adjust the bottom rule within .hover-tooltip, for IE7.
.hover-tooltip {
display: block;
padding: 15px;
position: absolute;
margin: 0 auto;
bottom: 1em;
*bottom: 0;
width: 100%;
border: 2px outset #c0c0c0;
background-color: #f0f0f0;
text-align: center;
}
However, the double, nested absolute positions of .hover-tooltip-container and .hover-tooltip seem unnecessary.
I did something quite different (also renamed your classes, to much of a hassle to play with those looooooooooong name).
http://jsfiddle.net/vZtBb/16/
I removed the nested absolute positionning : They are the one causing the issue, since element in absolute position are taken out of context. So, 2 solo, nested absolute positionned element means that one element is in nothing (glitchy and really not wanted).
Instead of that, I placed your tooltip box in absolute, but made it start higher than the anchor by use of a negative position (top:-70px). It's sketchy a bit, but you should get my point.
Trying putting this after the .hover-tooltip div:
<div class="clear fix"></div>
and this css:
.clearfix:after {content: ".";display: block;clear: both;visibility: hidden;line-height: 0;height: 0;}
.clearfix {display: inline-block; }
html[xmlns] .clearfix {display: block; }* html .clearfix {height: 1%; }
I was able to solve the problem by having the "container" element float left and have relative position. This achieves the appearance of breaking out of containers but still provides a reference for the tooltip to go up from.

Clearing floats without extra markup

I was reading this page here: http://robertnyman.com/2007/04/12/how-to-clear-css-floats-without-extra-markup-different-techniques-explained/ about clearing floats without extra markup but it didn't mention something I thought you could do.
Am I right in my thinking that you can also clear a float by just not floating the last element?
So if you wanted to float 3 elements, you float the first two and don't float the last one.... the last one will still float but anything after won't?
If elements in a container are set to float they will screw up.
Because the parent doesn't know the height of the floated element in it (because it isn't in the flow of the document anymore)
http://jsfiddle.net/CkdY6/
The best you can do is set the parent element to overflow: hidden
http://jsfiddle.net/CkdY6/1/
But as someone recently pointed out to me it will screw up when you want to use CSS3 stuff like a drop shadow.
http://fordinteractive.com/2009/12/goodbye-overflow-clearing-hack/
Most CSS "reset" stylesheets will have a class for auto-clearing after an element.
E.g. these rules from html5reset.org allow you to write <div class="clearfix">your floats in here</div>:
.clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }