Ok, another newbie question.
I'm doing much better with understanding positioning, and can, more or less, get exactly what I want.
One thing I've found is that if I:
a. take an "element" (table, text, picture, <div>, etc) and put it in a <div>
b. adjust the size of the <div> to the "element",
c. adjust the class of the <div> in the <style> section
it is much easier to move things around on a page.
A little survey:
1. Is this the way you do it?
2. Are there particular elements you ALWAYS put in a <div>?
3. Are there certain elements you NEVER put in a <div>?
4. Are there other ways to "control" elements and their placement?
Again, I thank you very much for your time.
I just control the placement of elements by using margin or padding css and very very ocassionally absolute positioning.
Its not necessary to always use a <div> to control the placement of an element. I wouldn't insert a heading tag or the content or an image in their own <divs> like this example just to position them:
<div id="leftCol">
<div><h1>header</h1></div><!-- close h1 -->
<div id="content">
<p>Some text goes here</p>
</div><!-- close content -->
<div id="leftColimage">
<img src="images/myImage.jpg" width="200" height="200" alt="" />
</div><!-- close leftColimage -->
</div><!-- close leftCol -->
When you can do this:
<div id="leftCol">
<h1>header</h1></div>
<p>Some text goes here</p>
<img src="images/myImage.jpg" width="200" height="200" alt="" />
</div><!-- close leftCol -->
Elements can be moved into position using css without the necessity to have a <div> wrapped around them.
An HTML element is everything from the start tag to the end tag.
With that knowledge, a division (DIV) is an element as is HTML and BODY with HEAD being a special type of element.
All elements can be styled using CSS, block elements can be made inline, inline elements can be made into block elements.
Hence, if you want to centre an image (image is an inline element) within its container (another element), we change it into a block element and add automatic margins as in
img {display:block; margin:auto;}
I can hear you say, "But an IMG has no end tag. This is true, HR, BR and IMG elements (amongst others), are empty elements and do not have ending tags in HTML. In XHTML, HR, BR and IMG elements must be properly closed using the forward slash as in
<br />
Sorry, just realised that I went off on a tangent. Just ignore my ramblings.
@osgood_ - Ok, good to know. So for for headings and pictures, I don't have to enclose them in a <div>. Your upper example looks like stuff I've done, and I'll start leaving out <div>s based on your lower example. I didn't realize that you could control a picture size "alone".
Thanks very much!
@Ben - good to know about converting and image to a block element - I'll try it today and see how it works.
@MurraySummers - Yes, I'm stuck with absolute positioning.
The pages I'm making are very complex - there are a series of four "constants" -
An upper left <div> with a background image (100x100px).
An upper rectangular <div> (100x100%) into which I put a variable title.
A left hand <div> (with links and a background image) that serves as a standard series of links.
There is then a <div> below the upper rectangle that is a <table> (3 col, 2 row) with data.
That leaves one large <div> below and to the right of all that stuff - that I put in a whole series of information - usually in tables (it's a data-rich environment)
I thank you all for your answers!
Basic grid. No APDivs required:
http://alt-web.com/TEMPLATES/HTML5Layout.html (View source to see the code)
How to Develop with CSS? (A Must Read)
http://phrogz.net/css/HowToDevelopWithCSS.html
Nancy O.
Here is something as simple as they come:
3 boxes that I want arranged like this:
maroonlightbluelightbluelightbluelightbluelightbluelightbluelightbluel ightbluelightbluelightbluelightbluelightbluelightbluelightblue
maroonlightbluelightbluelightbluelightbluelightbluelightbluelightbluel ightbluelightbluelightbluelightbluelightbluelightbluelightblue
maroonlightbluelightbluelightbluelightbluelightbluelightbluelightbluel ightbluelightbluelightbluelightbluelightbluelightbluelightblue
maroonlightbluelightbluelightbluelightbluelightbluelightbluelightbluel ightbluelightbluelightbluelightbluelightbluelightbluelightblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
dkblue
Here's the code - without absolute positioning, I can't get them lined up the way I want.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
.topleftbox {
float: left;
width: 100px;
height: 100px;
background-color: maroon;}
.topbar {
float:left;
height: 100px;
width: 100%;
background-color: gray;}
.leftbar {
float:left;
height: 100%;
width: 100px;
background-color: navy;}
.subcontainer {
float:left;
height: 100%;
width: 100%;
background-color: #D2FFFF;}
</style>
</head>
<body>
<div class="topleftbox"></div>
<div class="topbar"></div>
<div class="leftbar"></div>
</body>
</html>
I think I figured it out.
To use "boxes" outside of the normal "stack order" you must use absolute or relative positioning.
So I made three "boxes", all using "float: left" for positioning.
The heights are 100px (the "header") 100% (the "large container) and 30px for the "footer".
In the "header" I inserted a smaller box -- 100px -- and floated it to the left.
In the "large container" I put a tall column 100%x100px and floated it to the left.
So I get the EXACT layout I want, and didn't have to use "relative" or "absolute positioning.
To me, the take home message is:
Stack your "big picture stuff" using "float:left/right"
then insert your smaller items inside the "big picture stuff"
using "float:left/right".
So with this, I was able to construct a page EXACTLY the way I wanted it,
and did not use ANY "position:".
I still used all <div>s for the boxes, but I can work on that later.
Thanks very much to all of you for all of your help!
Mantra:
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
No "position"
Use "float"
No <div>s
![]()
North America
Europe, Middle East and Africa
Asia Pacific