why are my divs not stacking correctly? - html

I am working on a site and for some reason, my Divs are acting very strangely.
link
Im not sure why this is happening.
HTML
<div class="row" id="information">
<div id="informationContent" class="large-12 columns noSlideshow">
<div id="pressReleaseCenter">
<h2>Press Release</h2>
<div class="pressImages"><img src="images/voip_vid_logo.png" height="200" width="200"></div>
<div class="pressText" id="press1">December 04, 2013<br />VoIP Innovations is now accepting requests for the new Toll-Free area code<br />Due to the popular demand of Toll-Free numbers, the FCC<br />will introduce 844 as the newest area code on Saturday, December 7.<br />Starting on Saturday, December 7, everyone will have the opportunity to select 844 as more</div>
<br />
<div class="hrBreak"></div>
</div>
</div>
</div><!--End Row-->
CSS
/*Float press release images*/
#pressReleaseCenter{
width:960px;
margin: 0 auto;
/* background-color:green;*/
height:initial;
}
.pressImages{
/* background-color:yellow;*/
height:auto;
width:30%;
float:left;
height:91px;
}
.pressText{
/* background-color:orange;*/
text-align:left;
width:70%;
float:left;
height:91px;
bottom:0;
}
.hrBreak{
width:100%;
height:3px;
background-color:white;
position:relative;
}
#press1{
padding-top:10px;
}
Also, is there a better way to do this? Im considering using a table. Would that work in this situation? I want to continue with more information in the same format.

Don't use a table for layout. That is very much not the done thing any more. You haven't actually specified how it's supposed to look but it looks like you need to add clear: both; to .hrBreak in order to get the line to sit below your content as I imagine it should be doing.
See here as to why

SIMPLE SOLUTION:
This is a common problem when using float property for divisions. I had the same problem once.
Do the following code addition in both the HTML file and CSS file:
HTML:
<div class="row" id="information">
<div id="informationContent" class="large-12 columns noSlideshow">
<div id="pressReleaseCenter">
<h2>Press Release</h2>
<div class="pressImages"><img src="images/voip_vid_logo.png" height="200" width="200"></div>
<div class="pressText" id="press1">December 04, 2013<br />VoIP Innovations is now accepting requests for the new Toll-Free area code<br />Due to the popular demand of Toll-Free numbers, the FCC<br />will introduce 844 as the newest area code on Saturday, December 7.<br />Starting on Saturday, December 7, everyone will have the opportunity to select 844 as more</div>
<br />
<!-- ADD THE BELOW LINE -->
<div class = "clear"></div>
<div class="hrBreak"></div>
</div>
</div>
</div><!--End Row-->
Add the following code to CSS:
.clear{
clear: both;
}
Here is why that happens:
Link-1
Link-2
Hope it helps you.

Consider wrapping each press release in an element so that you can style the group of elements that make up a press release. You could wrap them in additional div tags, or ul li. You can then get rid of the extra <br> tags and the <div class="hrBreak"></div> entirely.
http://jsfiddle.net/h7GpT/ is an example that uses an unordered list.

I'm assuming that your main problem is with the hrBreak div overlapping with the first two DIVs.
Short version: Adding clear: left; to .hrBreak should give you a quick fix. This makes that DIV appear beneath any left-floated elements before it. clear: both; would also work, though some older browsers sometimes struggle with that particular option (so use clear: left; if that's all you need).
Long(er) version: When you use float, your element ceases to be a part of the regular document order - and unfloated elements that share the same space (in this case, anything within div#pressReleaseCenter) will operate separately.
If you have some content that follows after a floated element (or elements), you can most easily use the clear: left; or clear: right; CSS to ensure a clean divide between the content (or clear: both;, as mentioned before, with the caveat that a minority of browsers may struggle).
You shouldn't require the <br /> tag at all. In your example above. Use the clear on your hrBreak DIV and affect any desired spacing with margin or padding (for example, div.hrBreak { margin-top: 2em; } or whatever.
One thing to be aware of - if you have an unfloated DIV (or any other element) that contains floated elements, you may want to use overflow: auto; if you require that container to exhibit any styling of its own. For example, if you wanted div#pressReleaseCenter to have a border or background colour, using overflow: auto; will force it to acknowldege the proportions of its floated content. If you don't do this, you may find that your DIV only appears as large as its unfloated content (unless you've manually defined a width and height).

Related

Making HTML <div> tag not take the entire length of the page

I am in the process of making my own website, and I am making it out of pure HTML. I encountered in the making of the page, as I will describe below.
Here's my code for reference :-
<head>
<style>
img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<style>
.sideDiv {
border: 1px outset black;
background-color: white;
text-align: center;
width: 120;
height: 400;
}
</style>
<style>
.mainDiv {
border: 1px outset black;
background-color: white;
text-align: left;
width: 400;
height: 300;
}
</style>
<img src="AyushLogo.png" alt="logo" height="9.2%" width="9.2%" style="float:left">
<br>
<a><button>About Me</button></a>
<a><button>Games</button></a>
<a><button>My Blog</button></a> <br><br>
<hr>
</head>
<body>
<div class="sideDiv">
</div>
<div class="mainDiv">
<p>Hi,<br>My name is Ayush Bhatt.<br><br>I love to code and remake old games. You can view some of my games by clicking on the 'Games' button on the top bar.</p>
</div>
</body>
</html>
The output looks like this :-
I wanted the tag with the "mainDiv" properties to appear at the side of the one with the "sideDiv" properties, but it just doesn't want to.
PS : I want to use only HTML as long as possible
An important thing about <div> tags is that they are known as "block-level" elements, which in particular means that they always start on a new line and take up the full width available, regardless. With this in mind,
writing
<div class="sideDiv"></div>
<div class="mainDiv">
...
</div>
should result in a div with class sideDiv and width as defined in the class, and then a new div with class mainDiv started on a new line, as block-level elements do by default, though note that this is simultaneously also because the div with class sideDiv takes up the remaining width on the page as a block-level element (though its content width is as described in the class, it being a block-level element is a bit like it "reserving" the rest of the width even though its content only uses the amount defined), so the next element (block level or inline) can only start on at least the next line.
If you want to circumvent this behavior, there are many ways to do it. One is by using an external tool like bootstrap, as pointed out by another answer, but my favorite is to simply use flex box. This can be done for your code in this way
<div style="display: flex; flex-direction: row;">
<div class="sideDiv"></div>
<div class="mainDiv">
...
</div>
</div>
A method that directly overwrites the block-level property would be to set the style display: inline-block; for both divs, to prevent either from starting on a new line or taking up the whole available width by default. (Just one isn't enough, if you only set it on the first one, the second still starts on a new line by default, and if you only set it for the second one, the first still takes up all available width by default). However, this causes the element to be treated completely as an inline element besides the fact that block-level height and width can be applied, and can be strange/difficult to maneuver as a result. It is often easier to just use a flex box. Code for this would be
<div class="sideDiv" style="display: inline-block;"></div>
<div class="mainDiv" style="display: inline-block;">
...
</div>
However, note that <p> is also a block-level element, so directly substituting in your original code in the mainDiv div would still cause it to skip a line before displaying. Again, it is usually easier, more modern, and better looking to just use a flex box.
Edit: Added the detail about block-level elements taking up all available width, and fixed the incorrect initial method that changed the display property to overwrite the block-level property by setting display: inline;. This can work, but it will ignore the heights and widths of the <div>s.
try using bootstrap , it deals with layout perfectly , here is an example :
<div class="container">
<div class="row">
<div class="col-md-6">
this is the left section
</div>
<div class="col-md-6">
this is the right section
</div>
</div>
</div>
for more details check :
https://getbootstrap.com/docs/5.0/layout/grid/
NOTE : you will need to include bootstrap and jQuery libs , check for online tutorial to start using bootstrap

HTML Error w/ Document Formatting

I'm typing up a document for a nonprofit I'm involved in, and I'm currently working on the headers at the very top of the first page.
It's supposed to be two headers on the same line, one left-aligned and the other right-aligned, and both 13px bold text. It's also supposed to be directly above the title of the document, which is centred in <h1> text style.
Everything is going swimmingly except for the fact that the headers are both left-aligned, and I cannot for the life of me figure out what I'm doing wrong. I know it's not my browser because both StackEdit and WordPress fail to recognise it. And I asked 2 friends to take a look at it, and they can't figure out what's wrong either.
I recognise I probably screwed something up since I'm still learning HTML (I also haven't learned CSS yet), but it has thus far escaped me.
This is what I have:
<span style="text-align:left; font-size:13px"><b>Project Name</b></span>
<span style="text-align:right; font-size:13px"><b>Branch Name, Org
Name</b></span>
<div style=text-align:center><h1>Document Name 1-PubDate</h1></div>
Is this what you are trying to do? Use float css property
<span style="float:left; font-size:13px"><b>Project Name</b></span>
<span style="float:right; font-size:13px"><b>Branch Name, Org Name</b></span>
<div style="text-align:center;clear:both"><h1>Document Name 1-PubDate</h1></div>
Try to use div instead of span like in the following example:
<div style="float:left; text-align:left; font-size:13px; display:inline-block;"><b>Project Name</b></div>
<div style="float:right; text-align:right; font-size:13px; display:inline-block;"><b>Branch Name, Org
Name</b></div>
<div style="clear:both;"></div>
<div style="text-align:center;"><h1>Document Name 1-PubDate</h1></div>
Hope this may help. Best regards,
Because <span> defaults to display:inline, which means it will only grows as wide as its content's width. Try display:inline-block. Also use float to eliminate the white space between them:
span.header
{
display:inline-block;
width:50%;
font-size:13px;
font-weight:bold;
}
span.header.left
{
float:left;
text-align:left;
}
span.header.right
{
float:right;
text-align:right;
}
div.document
{
clear:both;
}
<span class="header left">Project Name</span>
<span class="header right">Branch Name, Org Name</span>
<div class="document"><h1>Document Name 1-PubDate</h1></div>
You are aligning the text of inline elements rather than aligning the elements themselves. If you inspect and look at the spans they are only as large as the text inside them. You can set the width's if you set them to display: inline-block and then the width to 50% and align the text however you want: http://plnkr.co/edit/hQKymbtYp5iBealcEkr3
<span style="display: inline-block; width: 50%; text-align:left; font-size:13px">
<b>Project Name</b>
</span>
<span style="display: inline-block; width: 49%; text-align:right; font-size:13px">
<b>Branch Name, Org Name</b>
</span>
<div style=text-align:center>
<h1>Document Name 1-PubDate</h1>
</div>
I'm going to change things up a bit and make it a bit more semantic (i.e. meaningful)
h1 {text-align:center; /*Center the H1 text*/
clear:both; /*Remove the affects of loats*/}
.preHeader {font-size:13px; font-weight:bold;} /*Set font size and bold pre-head elements*/
.project, .org {width:50%} /*Set common details*/
.project {float:left; } /*Set the project elemetn to the left*/
.org {float:right; text-align:right; } /*Text align the Right side elelment and set it to the right*/
<!-- A Container for your project and organisation elelments -->
<!-- You don't actually need the container, but it seperates it nicely -->
<div class="preHeader">
<div class="project">Project Name</div>
<div class="org">Branch Name, Org Name</div>
</div>
<h1>Title</h1><!-- Already is the width of its parent so don't need to wrap it -->
Learn more about how different elements display. You have block level elements, inline and (inline block) elements, and replaced elements (images and form elements).
Read more about floats here: https://developer.mozilla.org/en-US/docs/Web/CSS/float
And to see a discussion of the merits of floats (and their drawbacks) and the inline-block alternative see: http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/
On a side note, get to know some of the handy tools. Pressing f12 in Chrome and Internet Explorer give you the developemt tools for those browsers enabling you to inspect element on a web page and see what styles are affecting it and how they are affecting it as well as giving you the ability to experiment with the styles in place. Firebug for Firefox provides the same functionality.

Right Align Text at end of line without table

I spent a little while trying to figure out how to achieve the following effect without using a table but couldn't figure it out: http://jsfiddle.net/sKFzA/
CSS :
.header{width:100%;font:25px Arial,Helvetica,sans-serif;}
.titleCol{width:99%;}
.dateCol{vertical-align:bottom;white-space:nowrap;}
.dateText{font-size:12px;}
HTML :
<table class="header">
<tr>
<td class="titleCol">This is the blog title</td>
<td class="dateCol"> <span> </span><span class="dateText">1/23/2012</span>
</td>
</tr>
</table>
To explain it, I have a blog title and a blog date. The title could be long and wrap. At the end of the last line, wrapped or not, I want the blog date to be aligned to the right.
So I have two questions. Is there any reason not to use a table for this? If so, how would you achieve it without assuming static font sizes?
CSS has properties that allow any element to behave like specific components of a table.
http://cssdeck.com/labs/rjiesryc
<header>
<h1>This is the blog title</h1>
<time datetime="2012-01-23">1/23/2012</time>
</header>
CSS
header {
display: table;
width: 100%;
}
header h1, header time {
display: table-cell;
}
header time {
/*vertical-align: bottom;*/
}
With the help of cimmanon and the others, I've gathered that:
The only reason's not to use a table here is because layout is not technically a table's intended purpose and also by not using a table you can separate your layout (CSS) from your markup (HTML). However, if I were to use a table, I am not aware of of any negative effects.
There doesn't seem to be a good solution to this exact layout without the concept of table, but my table solution can be achieved without using an HTML table by applying styles to display other elements as the table. So I replaced my table elements with divs. The span with the space before the date allows the smaller sized date to stay aligned to the title's baseline without having to hard-code line height's or font sizes. So if the font sizes change, I don't have to worry about updating any other magic numbers hard-coded around them.
http://jsfiddle.net/K35gT/
HTML
<div class="header">
<div class="titleCol">This is the blog title</div>
<div class="dateCol">
<span> </span><span class="dateText">1/23/2012</span>
</div>
</div>
Styles:
.header{display:table;width:100%;font:25px Arial,Helvetica,sans-serif;}
.titleCol{display:table-cell;width:99%;}
.dateCol{display:table-cell;vertical-align:bottom;white-space:nowrap;}
.dateText{font-size:12px;}
You do not need tables at all, simply block elements with the right styles.
If it was my website, I would do this:
<header>
<h1>This is the blog title</h1>
<time datetime="2012-01-23">1/23/2012</time>
</header>
Combined with this CSS:
header {position:relative; width:100%; font:25px Arial,Helvetica,sans-serif;}
header > h1 {margin:0px;}
header > time {display:block; font-size:12px; text-align:right;}
You can decide if you want to use HTML5 elements, or general elements and if you want to hook in class names or not. Here's the jsFiddle for above: http://jsfiddle.net/sKFzA/13/
Something like this? I hope i got you right.
HTML:
<div id="titleRow">This is the blog title</div>
<div id="dateText"><span id="spandate">1/23/2012</span></div>
CSS:
#titleRow{width:80%; height: 25px; font:25px Arial,Helvetica,sans-serif;
float:left;text-align: left;}
#dateText{width:20%; height: 25px; font-size:12px;float:left; text-align: right; position: relative;}
#spandate { position: absolute; bottom: 0; right: 0;}
See here: http://jsfiddle.net/sKFzA/31/

How NOT to wrap text around DIV?

I think I searched thoroughly this site, but could not find answer to my issue; I also think it's pretty simple, but after several hours of puzzling with this, I have given up and decided to look for help...
Here is my issue; I have a DIV, and two DIVs within it; first DIV, "snapshot" contains script that returns website snapshpt, using websnapr.com; snapshot size is 202 x 150, so I defined width of that DIV to 230 px. Second DIV, "description", is supposed to be displayed on the right side of that snapshot, and it contains some text. My issue is that text at the end flows around "snapshot", i.e., beneath it, and I want it to stay in line, always on the right side of DIV "snapshot", not below him.
So, you see lines 1 through 10 are fine; I want lines 11 and 12, and rest of the text, to be aligned below lines 1-10, not below snapshot!
Here is the code:
<div class="entry">
<h2 align="center">Some title here...</h2>
<div id="snapshot"><script type="text/javascript">wsr_snapshot('some link here', 'some pass here', 's');</script></div>
<div id="description"><p>Line 1<br>Line 2<br>Line 3<br>Line 4<br>Line 5<br>Line 6<br>Line 7<br>Line 8<br>Line 9<br>Line 10<br>Line 11<br>Line 12<br></p>
<p align="left">Link:<br>
some link here</p></div>
</div>
and here is CSS for these IDs and classes:
.entry {margin:0 0 20px 0; border:2px solid #fff; background:#e6e6e6 url(images/bg.png) repeat-x; color:#333; padding:10px 10px 0 10px; min-height:200px; height:auto !important; height:200px; }
#snapshot {float:left; width:230px;}
#description {display: block; margin-left:240 px;}
I've tried with various properties for these two DIVs - display, clear, overflow, etc., to no avail; hope someone can shed light on what I'm missing here...
Aha: you’ve got an extra space between 240 and px in your margin-left rule for #description.
The following works:
#description {display: block; margin-left:240px;}

How do I fix my footer and the bottom of this page?

I'm trying to fix a table and make it look better (I describe the issue better in the screen shot below).
this is a screen shot of what's going on and what I would like to happen:
What do I change in my style sheet?
the css file is located at rankingclimber.com/css/style.css (the footer part is clearly marked) and the signup part is clearly marked
The sign up page is located at www.rankingclimber.com/signup.php
here's the code for the footer file: rankingclimber.com/footer.php and the footer is called on the main page: rankingclimber.com/signup.php
To fix the placement of the line, move <div class="form_bt"></div> to just after the closing tag of <div class="form_tp">.
To fix the "Create Account" button not being inside the form, from <div class="chkp3">, remove float: left and margin-bottom: 20px. Then, to <a class="btn1">, add margin-top: 20px.
To fix the footer, move <div id="footer"> to just after the closing tag for <div id="wrapper">.
Tested in Firefox only, with Firebug.
Another answer pointed out you have missing close tags. In that case, my answer might not be very useful as the problems could have been caused purely by those missing tags.
Fix the missing close tags, and then see what your page is like before following any of the steps I posted.
I think, add margin:0; !important to the .form_bt style. Safari Web Inspector shows it currently has a margin-right of -60px. And in your HTML, put the div.form_bt outside of the <form> element, it's currently inside it.
try these fixes, I can't validate since I don't have all of your files, but you are missing closing tags for:
Missing </li> after the code: <li>What is Ranking Climber?
Missing </div> before the code: </form>
use this css
clear: both;
<div id="container">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
CSS for these DIV's
#container{
width:950px;
min-height:500px; // This will helps you to stick to footer to bottom about 500px below
}
.left{ width: 50%;}
.right { width:50%;}
.footer{
widht: 950px;
clear: both; // This will helps you to avoid footer to overlap. Use this when Some elements is overlapping
}