CSS Float does not stretch Div Height - html

I have had this problem for a long time when working with HTML/CSS and Floats.
In the image you can see I have a Box Div that is Floated left as there is many of these Boxes. Inside the Box I have a <UL> List. The List items <li> are also Floated left.
As you can see in the image, the List items do not make the Box Div that they are inside of Expand. I have tried several thing without much luck and was hoping someone with more experience could help? I cannot set a fixed height on the Box Div as the number of icons is always different and it needs to expand to fix them.
Live demo: http://jsfiddle.net/jasondavis/u5HXu/
<div class="module-box">
<div class="module-box-title">
<h4><i class="icon-cogs"></i>Admin Settings</h4>
<div class="tools">
-
</div>
</div>
<div class="module-box-body" style="display: block;">
<ul>
<li>
<a href="#">
<img src="http://cp.codedevelopr.com/modules/password_assistant/assets/icon.png" border="0">
<span class="module-icon password_assistant"></span>
</a><br>
Change<br>Password
</li>
<li>
<a href="#">
<img src="http://cp.codedevelopr.com/modules/password_assistant/assets/icon.png" border="0">
<span class="module-icon password_assistant"></span>
</a><br>
Change<br>Password
</li>
<li>
<a href="#">
<img src="http://cp.codedevelopr.com/modules/password_assistant/assets/icon.png" border="0">
<span class="module-icon password_assistant"></span>
</a><br>
Change<br>Password
</li>
</ul>
</div>
</div>
CSS
/* Modules homepage */
.module-box {
margin: 0px 0px 25px 25px;
padding: 0px;
float: left;
width: 464px;
}
.module-box-title {
margin-bottom: 0px;
padding: 8px 10px 2px 10px;
border-bottom: 1px solid #eee;
color: #fff !important;
background-color: #333;
height: 51px;
line-height: 45px;
border-radius: 3px 3px 0 0;
}
.module-box-title h4 {
display: inline-block;
font-size: 18px;
font-weight: 400;
margin: 0;
padding: 0;
margin-bottom: 7px;
}
.module-box-title .tools {
display: inline-block;
padding: 0;
margin: 0;
margin-top: 6px;
float: right;
}
.module-box-title .tools a {
font-size: 31px;
color: #fff;
text-decoration: none;
line-height: 29px;
}
.module-box-body {
background-color: #fff;
border: 1px solid #ccc;
border-top: 0;
padding: 10px;
clear: both;
}
.module-box-body a {
font-family: 'Source Sans Pro', sans-serif;
font-size: 11px;
color: #888;
text-decoration: none;
}
.module-box-body li {
float: left;
margin: 0 12px 0 0;
list-style: none;
}

You need to clear your floats using a clearfix or clearing element.
Method #1 clearfix
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
Then you add the class on the containing element
<div class="module-box-body clearfix" style="display: block;">
http://jsfiddle.net/u5HXu/8/
Method #2 Clearing Element
.clear {
clear: both;
}
Then you add the following HTML after your floated elements.
<div class="clear"></div>
http://jsfiddle.net/u5HXu/9/

You can use the overflow: hidden trick on the parent container (..module-box-body) ;) fixes everything.
http://jsfiddle.net/teddyrised/ct6gr/

Change your .module-box-body li to
.module-box-body li {
display: inline-block;
margin: 0 12px 0;
list-style: none;
}
Updated fiddle.

Try applying overflow:auto to the container, the one whose height you want to resize based on the height of its contents (the floated items).
I'd add a jsfiddle link but it's not been working at all for me recently. :/

Related

ul li timetable elements overlapping

Making a responsive timetable which switches to a list format for mobile, with Weekdays acting as headers and relevant sessions being listed below.
I've encountered a problem where li elements overlap. Despite experimenting with position and display values, I can't figure out how to counteract this overlap.
Any help would be appreciated.
.smallTableContainer {
position: relative;
display: none;
height: auto;
overflow: hidden;
}
.weekdayHeader {
background: #bc4b51;
color: #efefef;
font-size: 18pt;
padding: 10px 0px;
}
.sessions {
padding: 0;
}
.className {
float: left;
display: inline-block;
color: #1e1e1e;
font-size: 13pt;
padding-left: 10px;
}
.classTime {
float: right;
display: inline-block;
color: #1e1e1e;
font-size: 12pt;
padding-right: 10px;
}
<div class="smallTableContainer">
<h3 class="weekdayHeader">Monday</h3>
<ul class="sessions">
<li>
<div class="className">
Warrior Cubs Kickboxing
<br>AGES 5-7
<br>[ SPACES AVAILABLE ] </div>
<div class="classTime">
<br> 16.15pm - 17.00pm
</div>
</li>
<li>
<div class="className">
Warrior Cubs Kickboxing
<br>AGES 8-12
<br>[ SPACES AVAILABLE ]
</div>
<div class="classTime">
<br> 17.00pm - 17.45pm
</div>
</li>
</ul>
</div>
If I understand your desired result correctly, you want the events and times to disaply on individual lines. In order to do this, all you're looking for is cleart: both on your .sessions li. In addition to this, you'll probably want to add a bit of spacing between each event, which can be done by adding margin-top to the (rather complex) .sessions li:not(:first-of-type) .className selector. This ensures that the margin will be applied to all of the listings apart from the first one.
This can be seen in the following:
.smallTableContainer {
position: relative;
/*display: none;*/
height: auto;
overflow: hidden;
}
.weekdayHeader {
background: #bc4b51;
color: #efefef;
font-size: 18pt;
padding: 10px 0px;
}
.sessions {
padding: 0;
}
.sessions li {
clear: both;
}
.className {
float: left;
display: inline-block;
color: #1e1e1e;
font-size: 13pt;
padding-left: 10px;
}
.classTime {
float: right;
display: inline-block;
color: #1e1e1e;
font-size: 12pt;
padding-right: 10px;
}
.sessions li:not(:first-of-type) .className {
margin-top: 20px;
}
<div class="smallTableContainer">
<h3 class="weekdayHeader">Monday</h3>
<ul class="sessions">
<li>
<div class="className">
Warrior Cubs Kickboxing
<br>AGES 5-7
<br>[ SPACES AVAILABLE ] </div>
<div class="classTime">
<br> 16.15pm - 17.00pm
</div>
</li>
<li>
<div class="className">
Warrior Cubs Kickboxing
<br>AGES 8-12
<br>[ SPACES AVAILABLE ]
</div>
<div class="classTime">
<br> 17.00pm - 17.45pm
</div>
</li>
</ul>
</div>

css: decorating a div with ::after content without wrapping

I've been playing around for a while to get a list to have the main list text left aligned in a content column with a "+" sign right aligned on the same line. I have this working perfectly in firefox, only to discover that lines which are longer than a single line (and therefore will have an ellipsis overflow) are wrapping the "+" sign in IE and chrome.
The example i have extracted from my project is at https://jsfiddle.net/qo65Lg2n/2/. Since this is an extract some things like the category numbering isn't showing correctly.
Is there another way of approaching this that will work in all three major browsers?
Thanks
html:
<div style="width: 1000px; text-align: center; margin: auto">
<div class="sfexpandableListWrp">
<ol class="sflistList">
<li class="sflistItemTitle">
<a class="sflistItemToggleLnk" href="#">
this is a short list title
</a>
</li>
<li class="sflistItemTitle">
<a class="sflistItemToggleLnk" href="#">
this is a really really really really really really really really really really really really really really long list title
</a>
</li>
<li class="sflistItemTitle">
<a class="sflistItemToggleLnk" href="#">
something
</a>
</li>
</ol>
</div>
</div>
css:
.sfexpandableListWrp
{
max-width: 500px;
text-align: left;
}
.sfexpandableListWrp .sflistList
{
margin-bottom: 23px;
list-style-type: none;
}
.sfexpandableListWrp .sflistItemTitle
{
font-size: 1em;
font-weight: bold;
float: left;
width: 100%;
background-color: #1BB2A0;
border-radius: 8px;
line-height: 3.7em;
margin-bottom: 1em;
}
/* List item toggle link */
.sfexpandableListWrp .sflistItemToggleLnk
{
padding-left: 15px;
color: white;
display: block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
padding-right: 4em;
}
.sfexpandableListWrp .sflistItemToggleLnk::before
{
content: "Category " counter(category-counter) ": ";
color: black;
font-family: "VAGRoundedBT-Regular";
counter-increment: category-counter;
}
.sfexpandableListWrp .sflistItemToggleLnk::after
{
content: "+";
color: white;
float: right;
clear: right;
font-size: 2em;
background-color: #88CEB4;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
padding: 0 0.5em;
margin-right: -2em;
}
Use position absolute may help you.
first,change the ::after element to position:absolute and delete margin-right,float attribute
.sfexpandableListWrp .sflistItemToggleLnk::after
{
position:absolute;
top:0;
right:0;
content: "+";
color: white;
font-family: "VAGRoundedBT-Regular";
font-size: 2em;
background-color: #88CEB4;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
padding: 0 0.5em;
}
second add position:relative to the parent .sflistItemToggleLnk
.sfexpandableListWrp .sflistItemToggleLnk {
padding-left: 15px;
color: white;
display: block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
padding-right: 4em;
position:relative;
}
I hope that is what your want
.sfexpandableListWrp .sflistItemToggleLnk {
padding-left: 15px;
color: white;
display: block;
/* white-space: nowrap; */
text-overflow: ellipsis;
overflow: hidden;
padding-right: 4em;
}
try this . It may helps you..

floated ul collapsing, causing child li to wrap below each other instead appearing in a row

I've a div (.user-band), inside it there is one div (.user-block) floated to left and one UL (.user-stats) floated to right.
Now the issue is when I'm giving width/min-width in percentage to child 'li' items of 'ul' (.user-stats). The 'li' items are not appearing in a row within 'ul', but if i'm giving the same width in pixel (i.e. 250px) they are appearing in a row.
Can anyone please let me know whats going wrong here.
Here is the HTML:
<div class="clearfix user-band">
<div class="clearfix user-block">
<div class="user-pic">
<div class="pic-box">
<img src="images/user-pic.jpg" alt="">
</div> <!--pic-box-->
</div> <!--user-pic-->
<div class="user-info">
<p class="user-id">Martin</p>
<p class="user-location"><span class="fa fa-map-marker ic-location"></span> Los Angeles</p>
</div> <!--user-info-->
</div> <!--user-block-->
<ul class="user-stats">
<li class="stats-title">
Completed Deals
<span class="stats-value">15</span>
</li>
<li class="stats-title">
Pending Deals
<span class="stats-value">7</span>
</li>
<li class="stats-title no-click">
Total Commission
<span class="stats-value">$500</span>
</li>
</ul>
</div> <!--user-band-->
Here is the CSS:
.user-band { border: 1px solid #e26513; background: #F0701B; padding: 10px; }
.user-block { float: left; }
.user-pic, .user-info { float: left; }
.user-info { margin-left: 10px; }
.user-pic { padding: 2px; border-radius: 2px; background: #ffffff; }
.pic-box { overflow: hidden; text-align: center; width: 80px; height: 80px; }
.pic-box > img { max-width: 100%; min-height: 100%; }
.user-id { font-weight: 700; font-size: 18px; color: #ffffff; }
.user-location { color: #ffffff; }
.user-stats { float: right; margin: -10px -10px -10px 0; list-style-type: none; padding-left: 0; }
.user-stats { float: right; margin: -10px -10px -10px 0; list-style-type: none; padding-left: 0; }
.user-stats > li { display: inline-block; min-width: 250px; padding: 24px 10px; text-align: center; font-size: 14px; color: #ffffff; border-left: 1px solid #e26513; margin-left: -4px; cursor: pointer; }
.user-stats > li:hover { box-shadow: 0 0 200px #e26513 inset; }
.stats-value { font-weight: 700; display: block; font-size: 25px; }
.user-stats > li.no-click { cursor: auto; }
.user-stats > li.no-click:hover { box-shadow: none; }
.ic-location { font-size: 20px; }
You need to set a width on the UL - because it is floated.
http://codepen.io/elliz/pen/IeDCd/
15 Apr - Pen updated
See updated pen, what that what you mean?
Note - made code a little more semantic but not perfect.

List Item First Indentation Not Lining Up

In each list item I have a text box within a div element.
<html>
<body>
<!-- Window -->
<div id="sample_container_id">
<div class="bucket" id="defaultBucket">
<h3>Default Bucket</h3>
<input type="button" value="Add" class="button">
<div class="innerBucket">
<ul id="tasks">
<li>
<div class="TaskDiv">
<input type="text" class="TaskTextInput">
</div>
</li>
<li>
<div class="TaskDiv">
<input type="text" class="TaskTextInput">
</div>
</li>
<li>
<div class="TaskDiv">
<input type="text" class="TaskTextInput">
</div>
</li>
</ul>
</div> <!-- innerBucket -->
</div> <!-- defaultBucket -->
</div>
</body>
</html>
This is the result:
body
{
background-color: #F8F8F8;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1.2em;
margin: 15px;
}
h1, p
{
color: #333;
}
#sample_container_id
{
width: 100%;
height: 400px;
position: relative;
border: 1px solid #ccc;
background-color: #fff;
margin: 0px;
}
.innerBucket
{
width: 290px;
height: 355px;
margin-top: 40px;
margin-left: 5px;
position: relative;
background-color: white;
}
.bucket
{
width: 300px;
height: 400px;
background-color: #ddd;
position: absolute;
}
.bucket h3
{
float: left;
padding-left: 10px;
padding-top: -10px;
}
.bucket ul
{
margin: 0;
padding-left: 30px;
position: relavtive;
list-style: none;
}
.bucket ul li
{
margin: 0;
padding: 0;
text-indent: 0.5em;
margin-left: -0.5em;
display: block;
position: relative;
}
.bucket .button
{
background-color:#fbb450;
border:1px solid #c97e1c;
float: right;
margin: 5px;
display:inline-block;
color:#ffffff;
font-family:Trebuchet MS;
font-size:17px;
font-weight:bold;
padding:2px 11px;
text-decoration:none;
text-shadow:0px 1px 0px #8f7f24;
}
Result
As you may notice the first item is indented, and I would like the list items to all be aligned on the left. How do I fix this with the CSS (there probably is a lot of things wrong with my CSS, I was trying everything)?
EDIT
I added some more code. You should be able to replicate the problem now.
I didn't want to post a wall of code :)
Solution
I found the solution to the problem. The problem was actually the <h3> element. The bottom margin was forcing the first element off to the side.
Adding this fixed the problem:
.bucket h3
{
...
margin-bottom: 0;
}
Don't float the divs, if you do make sure to clear them or you get
what FakeRainBrigand got in his pen.
Spell relative right For that
matter take the positioning out of that code, it's pointless.
list items by definition are block elements, you don't need to declare
that either.
Close your input tags.
The float is likely the issue, pushing the divs against some invisible element.
.TaskDiv
{
margin: 0;
padding: 0;
}
ul
{
margin: 0;
padding-left: 30px;
list-style: none;
}
ul li
{
margin: 0;
padding: 0;
text-indent: 0.5em;
margin-left: -0.5em;
}
Example: http://jsfiddle.net/calder12/Yw4tB/
I found the solution to my own problem. The issue was the margin of the header forcing the div over (see the end of my question). The solution was simple once I figured that out.
Simply adding this to the h3 styling fixed my problem:
margin-bottom: 0;

Inner div to scroll if outer div is too small?

I'm trying to make a sidebar which on a website which will have a "panel" in it containing
contact info. The problem is that on smaller screens, the text overflows the background.
Here is the CSS, where #navigation is the outer div and the inner div is called .innerPanel HTML to follow:
#navigation{
position: absolute;
left: 1.5625em;
top: 1.5625em;
bottom: 1.5625em;
display: block;
width: 12.5em;
background: navy;
border-right: 1px solid navy;
text-align: center;
background: #B6D2F0;
padding: 5px;
color: #4A4A49;
overflow: hidden;
}
#navigation .innerPanel{
min-height: 200px; /* supply current height here */
height: auto;
overflow: auto;
}
.titleHead{
display: block;
padding-top: 0.9em;
overflow: auto;
}
/* inverted corners for the links */
#navigation #links {
position: relative;
padding-top: 30px;
}
#navigation #links div div div h3{
border-top: 1px solid navy;
border-bottom: 1px solid navy;
color: navy;
padding: 0px;
margin: 0px;
margin-top: 1px;
line-height: 1.2em;
}
#navigation div div div div ul{
list-style-type: none;
margin: 0px;
padding: 0px;
}
#navigation div div div div ul li{
text-align: center;
}
#navigation div div div div ul li a{
display: block;
text-decoration: none;
font-weight: bold;
color: #B6D2F0;
padding: 0px;
padding-left: 0;
line-height: 2.5em;
background: navy;
border-bottom: #D8F4F2 1px dashed;
}
#navigation div div div div ul li a:hover{
display: block;
text-decoration: none;
font-weight: bold;
color: #D8F4F2;
background: #0000A2;
}
#navigation div div div div ul #last a{
border-bottom: 0px;
}
`
Here is the HTML fragment. The nested div tags were for rounded corners, which were "nixed" by the client
<div id="navigation">
<div id="logo" class="box">
<div>
<div>
<div style="text-align: center;">
<img src="./images/pictures/cbk-logo-sm.gif" alt="Logo" />
</div>
</div>
</div>
</div>
<div id="links" class="box">
<div>
<div>
<div> <ul>
<li id="home">
Home
</li><li>
Applications
</li><li id="last">
About
</li>
</ul><div class="innerPanel"><div class="innerMost"><h4 class="titleHead">
Contact Information</h4>
<h5 style="margin: 0.8em 0 0 0; padding: 0;">City Office (September-June)</h5>
<p style="font-size: 0.75em; margin: 0; padding: 0;">
<em>Phone:</em> 555-555-5555<br />
<em>Fax:</em> 555-555-5555<br />
<em>Email:</em> email#provider.com<br />
<em>Address:</em> 123 Main Avenue Somewhere, IL 11234
</p>
<h5 style="margin: 0.8em 0 0 0; padding: 0;">Camp (July & August)</h5>
<p style="font-size: 0.75em; margin: 0; padding: 0;">
<em>Phone:</em> 987-654-3210<br />
<em>Fax:</em> 123-456-1234<br />
<em>Email:</em> email#provider.com<br />
<em>Address:</em> 456 Centre Road, Nowhere, AL 67891
</p></div></div> </div>
</div>
</div>
</div>
</div>
I need a cross-browser solution to make innerPanel dynamically add a scrollbar to itself so that on smaller screens, the content is clipped but accessible via scroll...
Preferably, the solution should be pure CSS.
Any ideas?
EDIT: I apologize for the ambiguity. I have a sidebar, called #navigation. It contains a logo, the menu and the contact information. I want the contact info to scroll where needed.
Everything else seems to display normally on 800x600 screens and up.
EDIT: As it stands now, innerPanel is a fixed height. I would like it to grow when possible, and if there is enough room, eliminate the scrollbar.
Please note that there is an HTML div not mentioned in the CSS, which is contained inside of innerPanel.
I am a little unclear what you are asking, but it seems to me you either want overflow:auto on the #navigation element, or depending on your content and why it has a fixed height:
#navigation .innerPanel {
max-height: 200px; /* supply current height here */
height: auto;
overflow: auto;
}
DOES NOT WORK IN IE6
IE6 does not support max-height.