Making an 8 * 8 grid

Hi
I’m quite new to CSS. I figured that if I could make an 8 by 8 grid then I should be able to position anything on any website.

I thought it would be easy but I was mistaken. I’ve managed to place 8 blocks. For some reason, I’m having trouble position the ninth block.

Maybe I’m going about it wrong. I’m trying to keep it basic by using absolute and relative positioning please.

Can anyone help me position the next nine blocks and then I should be fine; please.

Kind Regards
Matt

This is my .html :-


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
<link href="8by8gridstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<div id="outerbox">
	  <div id="innerbox">
		<div id="one"></div>
		<div id="two"></div>
		<div id="three"></div>
		<div id="four"></div>
		<div id="five"></div>
		<div id="six"></div>
		<div id="seven"></div>
		<div id="eight"></div>
		<div id="nine"></div>
		<div id="ten"></div>
		<div id="eleven"></div>
		<div id="twelve"></div>
		<div id="thirteen></div>"
		<div id="fourteen"></div>
		<div id="fifteen"></div>
		<div id="sixteen"></div>
		<div id="seventeen"></div>
		<div id="eighteen"></div>
		<div id="nineteen"></div>
		<div id="twenty"></div>
		<div id="twentyone"></div>
		<div id="twentytwo"></div>
		<div id="twentythree"></div>
		<div id="twentyfour"></div>
		<div id="twentyfive"></div>
		<div id="twentysix"></div>
		<div id="twentyseven"></div>
		<div id="twentyeight"></div>
		<div id="twentynine"></div>
		<div id="thirty"></div>
		<div id="thirtyone"></div>
		<div id="thirtytwo"></div>
		<div id="thirtythree"></div>
		<div id="thirtyfour"></div>
		<div id="thirtyfive"></div>
		<div id="thirtysix"></div>
		<div id="thirtyseven"></div>
		<div id="thirtyeight"></div>
		<div id="thirtynine"></div>	
		<div id="forty"></div>
		<div id="fortyone"></div>
		<div id="fortytwo"></div>
		<div id="fortythree"></div>
		<div id="fortyfour"></div>
		<div id="fortyfive"></div>
		<div id="fortysix"></div>
		<div id="fortyseven"></div>
		<div id="fortyeight"></div>
		<div id="fortynine"></div>
		<div id="fifty"></div>
		<div id="fiftyone"></div>
		<div id="fiftytwo"></div>
		<div id="fiftythree"></div>
		<div id="fiftyfour"></div>
		<div id="fiftyfive"></div>
		<div id="fiftysix"></div>
		<div id="fiftyseven"></div>
		<div id="fiftyeight"></div>
		<div id="fiftynine"></div>
		<div id="sixtyone"></div>
		<div id="sixtytwo"></div>
		<div id="sixtythree"></div>
		<div id="sixtyfour"></div>
		<div id="sixtyfive"></div>
	  </div> <!--end div of inner-box-->
	</div> <!--end div of box-->
</body>
</html>

and this is my css so far :-


#outerbox{
	width: 100%;
	height: 100%;
	
	border: 1px solid red;
	padding: 2px;
	margin-bottom: 2px;
	
	position: absolute;
	top:50px;
}

#one, #two, #three,#four,#five,#six,#seven,#eight{
	width:10%;
	height: 25px;
	
	border: 1px solid red;
	padding: 2px;
	margin-bottom: 2px;	
	
	position: relative;
	top:100px;
	left: 10%;
	
}

##nine, #ten, #eleven, #twelve, #thirteen, #fourteen,#fifteen, #sixteen{
	width:10%;
	height: 25px;
	
	border: 1px solid red;
	padding: 2px;
	margin-bottom: 2px;	
	
	
	top:200px;
	left: 10%;
}

Hi,

for your ninth element you have a style that matches nothing.


##nine

You have two hashes instead of one :slight_smile:

However, a bigger problem is that this is not the way that sites are built and you will never use relative positioning for structural layout. It is used for more advanced and subtle overlapping effects but never for a structural layout as any element moved with relative positioning is only moved visually and not physically. It always occupies the same space in the page it had before it was moved but just appears to be somewhere else. Suffice to say that you can go years without the needs to move anything relatively :slight_smile:

Neither is absolute positioning really any use here either because absolute elements are islands to themselves and care nothing about anything that is in the way. If at some time you need to increase the height of one element then you have to adjust every single element on the page after it. Absolute positioning is fine in small doses in a controlled situation but again is never really used for structural layout unless it;s something like a 2 column layout with no footer and even then floats would be a better choice.

Also note that if you give something a 100% height then that’s as large as it can be and if your content grows then your layout does not. So once again you will rarely use height:100% in a layout apart from html and body to gain an initial height. You have also added padding to the 100% width and the 100% height which immediately makes them too big for their containers.

Pages should be laid out with the flow of the document in mind so that one element flows to the next. You don’t need fancy positioning and millions of ids to lay the page out but just a few well chosen classes here and there and let the flow of the document create successive elements. Margins can be used to space things apart and the whole thing will begin to breathe rather than being stifled by absolute positioning techniques.

If your boxes were meant to be a menu of sorts then you could create them easily by floating the menu as a ul (width a width) and letting the list elements stack vertically. No need for any positioning.

Page wrappers don’t need height as content will dictate the height and the page can grow and shrink with content as required. If you need horizontal alignment then things can be floated (or display:inline-block or display table-cell depending on situation) and then regain the flow by clearing the floats (or containing them).

No pages will ever be useful if constructed with millions of absolute elements so throw that concept away before you start. First of all go and get some dummy content of the type you are going to use so that you can style content rather than boxes as a website isn’t about boxes its about content and until you put some sort of real content in place then designing for it won’t make much sense.

If you can explain roughly what type of layout you were trying to create then we may be able to give you a better starting point but the page you have so far is of no use to you I’m afraid apart from an exercise in absolute positioning.

Also note that you should use a current doctype as the one you have above is from the dark ages and trips quirks mode in some versions of IE8 and under.

Use this doctype at least:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Or for html5:


<!DOCTYPE HTML>

You need to think of your page more of sections that are moved into place and then content inside those sections are in-flow and follow each other logically without much positioning needed at all. Usually for a 2 column layout this will involve floating one column and letting another column fill the available width naturally. Here’s a very basic 3 column example (it’s a very old example) but useful for showing the concept of floated columns. These days it may be better to use display:table and table-cell for some columns or indeed display:inline-block where appropriate.

It all depends on the content and what you intend to achieve.

Hi Paul
Thank you so much for your advise.

The reason that I’m attemping to do an 8 by 8 grid is to become better at css positioning because I started learning Drupal CMS. When I had the Drupal basics covered I found that I had to become an expert in CSS and know the basics of PHP in order to make a website look really good.

So I thought that I would set myself an awquard challenge in the hope that it would give me enough experience to get by with CSS at least.

An idea of mine, is to develop a Theme that has lots of raindrops (perhaps in the shape of a grid, with rain-drops inside, which acts as links to other websites or to somewhere else within my website). I was hoping to do something fairly original that makes a website look less rectangular.

If you have any more advice - even by recommending a good book or maybe advise me how you learned I would be very grateful also.:slight_smile:

Kind Regards
Matt

Hi Matt,

The best way to learn is to do what you have already started and try things out yourself first and then ask questions why it doesn’t work or how to do it properly. It’s through our mistakes that we learn the most.:slight_smile:

The next step is then to improve your understanding of the various css properties and what they can do. After that you should look at how [URL=“http://mobile.smashingmagazine.com/2011/07/22/responsive-web-design-techniques-tools-and-design-strategies/”]responsive web design techniques as implemented as they are the only way forward these days with the proliferation of devices that are about.

The main thing to think about though is your content!

Websites are no longer a drawing in photoshop (although they might start as such) but sites must be adaptable to devices and work in small or large windows so throw out your fixed width designs. Create something that works with the content that you have in front of you and works for the millions of devices that we need to support these days. This means being creative and not compromising the content just to fit the design.

There is a lot to learn at first and so many things that can go wrong that in the end it is a matter of trial and error and practice and seeking out the best advice.

We see the same questions in the forums over and over again and the first thing that beginners latch on to is absolute positioning because it is something that they can understand but unfortunately websites are not built specifically with absolute positioning (although it has its part to play). Websites are built with a broader context of how content is maintained within the flow of the document and is not a concept that beginners easily understand at first as I can’t just say put that there and this over here. The whole page works as a whole depending on the sum of its elements so you can’t really take one element in isolation and place it somewhere expecting the rest of the page to still behave properly.

An idea of mine, is to develop a Theme that has lots of raindrops (perhaps in the shape of a grid, with rain-drops inside, which acts as links to other websites or to somewhere else within my website). I was hoping to do something fairly original that makes a website look less rectangular.

If you just want a 8 x 8 grid of links you could simply float them using percentage widths and they will adapt within reason to the viewport but it does depend on what content will be inside them as floats will snag if they are not a uniform height.

If you have a rough drawing of what you envisage then perhaps we could offer some actual code to get you started?

Hi Paul
Having learn’t some CSS basics this week, I’m going to back to doing Drupal CMS again now to see how crucial positioning is and to see if I find Drupal any easier to add in more CSS, as well as considating what I’ve learn’t about CSS already.
Thanks very much for your advice again and I will take it all on board. I may have to veer off now and learn some PHP and JScript now but I will be back!!
Thanks so much.
Kind Regards
Matt