Floating elements are ignored - html

I have the following elements and css in an html file.
HTML
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<h2>First event</h2>
CSS
#eastern {
text-align:center;
}
#calendar {
width:700px;
margin:auto;
}
#saturday,#sunday {
width:350px;
float:left;
}
For some reason, the <h2> element is floating up along the right side of the #eastern. The browser is acting like the element is completely empty even though it has plenty of content in the #saturdy and #sunday elements. Since #calendar-container isn't being floated I think it should force the <h2> element beneath.
I know I could just fix it using clear:both, but I feel like I'm missing something. Any help? Please? Thanks!!

please don't forget to clear your float inside of "#calendar" by using a simple:
#calendar {
overflow: hidden;
}
Or even better: you use the cleaner version with an additional class "clearfix".
If you do so, you'll get your lost boxmodel of "#calendar" back.
Now you'll be able to position <h2> underneath your calendar.
If you have any further questions feel free to let me know!
Here a full example:
CSS:
#eastern {
text-align:center;
}
#calendar {
width: 700px;
margin: 0 auto;
outline: 1px solid red;
overflow: hidden; /* dirty version if you don't have a
class "clearfix" in your Stylesheet */
}
#saturday,#sunday {
width:350px;
float:left;
}
HTML: (Cleaner Version with class "clearfix")
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar" class="clearfix">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<h2>First event</h2>

Please try below code where i have added clear class with clear both left and right:
HTML
<div id="eastern">All times are Eastern</div>
<div id="calendar-container">
<div id="calendar">
<div id="saturday"> ... </div>
<div id="sunday"> ... </div>
</div>
</div>
<div class="clear"></div>
<h2>First event</h2>
CSS
#eastern {
text-align:center;
}
#calendar {
width:700px;
margin:auto;
}
#saturday,#sunday {
width:350px;
float:left;
}
.clear{
clear:both;
}

Related

How to align both vertically and horizontally in CSS?

I have a box like this:
<section class="notes-list-box">
<div class="nn">
<div class="heading">Notes</div>
<div class="boxdescription">With our complete study notes, your homework is much easier.</div>
</div>
<div class="ttn">
<div class="heading">Things To Know</div>
<div class="boxdescription">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
</div>
<div class="vdos">
<div class="heading">Videos</div>
<div class="boxdescription">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
</div>
<div class="sqaa">
<div class="heading">Solved Question and Answer</div>
<div class="boxdescription">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</section>
Adding little bit of styling make it looks like this:
I have tried using vertical-align like this:
.notes-list-box > div {
vertical-align: top;
}
and it works. But I don't know how to align vertical at bottom so that all the white space also comes to bottom.
So the white space below notes and solved question and answer white background comes till bottom.
I want to fill those gaps with white space:
Use flexbox.
I used this CSS:
.notes-list-box {
display: flex;
font-family: sans-serif;
}
.notes-list-box > div {
margin: 0 5px;
background-color: white;
}
.heading {
color: white;
font-weight: bold;
padding: 10px 2px;
text-align: center;
}
.boxdescription {
padding: 5px;
}
.nn .heading {
background-color: #61B5DF;
}
.ttn .heading {
background-color: #41AF43;
}
.vdos .heading {
background-color: #FF8A00;
}
.sqaa .heading {
background-color: #FF1F2D;
}
See the result on JSfiddle.
The easiest way to do what you are trying to do is by using the display: table CSS properties.
JS Fiddle Here
HTML
<div class="table">
<div class="table-row">
<div class="heading table-cell">Notes</div>
<div class="heading table-cell">Things To Know</div>
<div class="heading table-cell">Videos</div>
<div class="heading table-cell">Solved Question and Answer</div>
</div>
<div class="table-row">
<div class="table-cell">With our complete study notes, your homework is much easier.</div>
<div class="table-cell">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
<div class="table-cell">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
<div class="table-cell">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</div>
CSS
.table {
display: table;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
border: 1px solid;
}
.heading {
vertical-align: middle;
text-align: center;
}
Here is an update with styling similar to yours.
Another alternative using jquery. Here is the fiddle.
JQUERY
$('.parentheight').each(function(){
var maxdivheight = 0;
$('.childheight',this).each(function(){
var divheight = $(this).height();
// compare height
if ( divheight > maxdivheight ) {
maxdivheight = divheight;
} else { }
});
// set all divs to max height
$('.childheight',this).height(maxdivheight);
});
HTML
<section class="notes-list-box parentheight">
<div class="alignbox nn childheight">
<div class="heading">Notes</div>
<div class="boxdescription">With our complete study notes, your homework is much easier.</div>
</div>
<div class="alignbox ttn childheight">
<div class="heading">Things To Know</div>
<div class="boxdescription">Things to know provides additional information on every topic which enhance the knowledge of the students.</div>
</div>
<div class="alignbox vdos childheight">
<div class="heading">Videos</div>
<div class="boxdescription">Reference videos on each topic provides experimental ideas and develops interactive learning technique.</div>
</div>
<div class="alignbox sqaa childheight">
<div class="heading">Solved Question and Answer</div>
<div class="boxdescription">With 100's of solved questions solved, now you can easily prepare your exam for free.</div>
</div>
</section>
CSS
.alignbox {
float: left;
width: 24%;
border: 1px solid red;
}
I got it working by setting everything to 100% height like so: http://jsfiddle.net/sur38w6e/
Your html was untouched.
.notes-list-box>div{
float:left;
width:120px;
background-color:yellow;
margin: 5px;
height:100%;
overflow:auto;
}
.heading{
background-color:red;
}
.notes-list-box{
background-color:green;
overflow:auto;
height:100%;
}
body,html{
height:100%;
}

CSS positioning

I know this is amateur stuff but I've been trying and trying to get this right and i can't seem to get a fix.
Please take a look at the website screenshot. I'm attempting to make the "call..." text to be inline and to the right of the best#flooring logo.
Here's the code HTML:
<div class="level0">
<div class="topbar">
<h1><% title_content %></h1> <div class="facebookbutton"></div>
<div class="phonetop">Customer services: <strong>0844 209 1560</strong></div>
</div>
</div>
<div class="header">
<div class="level0">
<div class="logonumber">
<img src="<% secure_url %>images/logo.png?r=1" alt="<% title_content %>" />
<div class="headernumber">
<h2>Call <br /> 01132 186 212 <br />for the best prices</h2></div>
</div>
<div class="headfloat">This contains all of the content located on the right hand side </div>
CSS
.level0{
width:970px;
margin:0px auto;
clear:both;
}
.topbar{
height:41px;
color:#747474;
/*text-shadow: 1px 1px 2px #000;*/
}
.header{
background:#fff;
height:166px;/*was 126*/
}
.logonumber {
float:left;
display:inline-block;
}
.logo{
display:block;
}
.headernumber{}
contains the nav, the card images, basket and search.
Any help would be much appreciated.
You need
.headernumber {
float: left;
}
and you also need to decrease the size of the .headfloat element because its width does not allow all three elements in the same line
so change the .headfloat rule to
.headfloat {
float: right;
padding-top: 13px;
text-align: right;
width: 350px; /*was 460px*/
}

How can I make more than one square using html and css?

I currently have a <div> square but don't know how to make another square with a different style. When ever I use <div> to make another square in css, the style would be the same as the first square.
CSS:
div{
height:100px;
width:95px;
background-color:#B80000;
border-radius:4px;
text-align:center;
margin-left:132px;
}
html:
<div>
<span>M</span>i'm lovin' it<l>™</l></div>
try like this
CSS:
#squareA{
height:100px;
width:95px;
background-color:#B80000;
border-radius:4px;
text-align:center;
margin-left:132px;
}
#squareB{
height:100px;
width:95px;
background-color:#B8FFFF;
border-radius:4px;
text-align:center;
margin-left:132px;
}
html:
<div id="squareA">
<span>M</span>i'm lovin' it<l>™</l></div>
<div id="squareB">
<span>M</span>i'm lovin' it<l>™</l></div>
Explanation:
you were styling all the divs in your css. the same style will apply to all the divs that you have in your markup. if you need to apply separate styles to separate elements, for e.g. two divs, one way is to give them both different ids and apply styles to particular ids.
P.S : there are a loads of other ways too. try to read more on CSS styling.
Use a different id for each one.
Then for your css
Div#first {
}
div#second {
}
Use classes instead of ids or the literal div selector in your CSS. Create a class that represents your square and two classes that represent your colors.
HTML:
<div class="square a">
<a href="http://www.mcdonalds.com/us/en/home.html">
<span>M</span>i'm lovin' it<l>™</l>
</a>
</div>
<div class="square b">
<a href="#">
<span>B</span>bee<l>™</l>
</a>
</div>
CSS:
.square {
border-radius:4px;
height:100px;
width:95px;
border-radius:4px;
text-align:center;
margin-left:132px;
}
.a {
background-color:#B80000;
}
.b {
background-color:#00ff00;
}
http://jsfiddle.net/mSA6E/
You can use the html "id" attribute. See this jsfiddle:
div {
width: 100px;
height: 100px;
}
#red {
background-color: red;
}
#green {
background-color: green;
}
<div id="red"></div>
<div id="green"></div>
You can put as much css classes as you like to an html tag. For example:
.square { display:block; width:100px; height:100px; }
.red { background:#f00; }
.green { background:#0f0; }
.blue { background:#00f; }
Then
<div class="square red">Red square</div>
<div class="square green">Green square</div>
<div class="square blue">Blue square</div>
This approach is also more verbose than having multiple repetitions of the same instructions.

How to properly add divs inside another div so the original design doesn't break?

I have a this basic HTML:
<div id="views-container">
<div id="html-container"></div>
<div id="original-page-container"></div>
<div id="result-page-container"></div>
</div>
This is the css for those divs:
#views-container > div{
height:90%;
width:33%;
display:inline-block;
}
#html-container{
background-color: pink;
}
#original-page-container{
background-color: yellow;
}
#result-page-container{
background-color: gray;
}
This is the final output:
But then I want to add two divs inside
html-container
, like this:
<div id="views-container">
<div id="html-container">
<div id="html-content-area">
<textarea id="OutputHTML"></textarea>
</div>
<div id="html-info-area">
bla bla bla
</div>
</div>
</div>
when I do this, this is how the page is rendered.
I want the textarea inside html-content-area
to use all width and heigth from html-container.
Later, i will need to hide html-content-area in order
to show something in html-info-area.
How could I add those divs inside html-content-area
so they don't break the original design?
I pasted the code in fiddle:
http://fiddle.jshell.net/eyCbB/
Thanks in advance!
Hope you were looking for this
I have made some changes in your fiddle.
#views-container > div{
height:90%;
width:32%;
display:inline-block;
vertical-align:top;
}
html,body {
width:100%;
height:100%;
}
#views-container {
height:100%;
}
Have a look http://fiddle.jshell.net/eyCbB/1/

css/html necessary to create forum style message

can anyone tell me any guides/hints for the css/html necessary to create a layout similar to the
message part of a forum:
------------------------
[8] User1
Some msg
------------------------
[8] User2
Another message
------------------------
Is this 1 main div and several child divs or something simpler like a css styled listitems or table, etc?
Please let me know the "correct" way to achieve this layout without newest css3/html5/beta code
An Example:
<style>
.message {margin-bottom: 15px; }
.image {float:left; margin-right: 10px; }
.user {float:left; font-weight:bold; color:#009; margin-bottom: 5px; }
.content { margin-left: 30px;font-style:italic; color:#; }
</style>
<div>
<div class="message">
<div class="image"><img src="http://www.gravatar.com/avatar/df125f7b89730a39163bb17c1c18c1d9?s=18&d=identicon&r=PG" /></div>
<div class="user">Silvertiger</div>
<div style="clear:both;"></div>
<div class="content">Does this work as expected?</div>
</div>
<div class="message">
<div class="image"><img src="http://www.gravatar.com/avatar/98d247dcb9453a0d5adc70cd6b3acde9?s=18&d=identicon&r=PG" /></div>
<div class="user">user2309722</div>
<div style="clear:both;"></div>
<div class="content">Indeed sir it appears to, Thank you</div>
</div>
</div>
Something like this would work:
<div id="thread">
<div class="thread-post">
Post #1 contents
</div>
<div class="thread-post">
Post #2 contents
</div>
<div class="thread-post">
Post #3 contents
</div>
</div>
And for CSS, you would do something like:
.thread-post {
padding: 10px
border-bottom: 1px solid #ddd
}
.thread-post:nth-child(even) {
background-color: #eee /* For distinguishing every other post */
}
Modify as needed.
I would go with one div for each couple author info + message, then, inside of each it would be some kind of floating left div for the box containing author info (username, avatar, etc) (as it is usually seen on forums but the style is up to you) along with another div to contain the linked message.
I did it like this : DEMO
<div class="box">
<div class="list">AAAAAAAAAAAAAAA</div>
<div class="list">BBBBBBBBBBBBBBB</div>
<div class="list">CCCCCCCCCCCCCCC</div>
<div class="list">DDDDDDDDDDDDDDD</div>
</div>
With css as :
.box {
position: absolute;
border: 2px solid grey;
}
.list {
line-height: 30px;
}
.list:not(:last-child) {
border-bottom: 1px solid red;
}