/    Sign up×
Community /Pin to ProfileBookmark

How would you code this with divs?

I know how to do this with tables, but I’m trying to convert my old ways and start using divs. The attached image is a menu box of sorts where the height and width is variable and all the colors are images. The top bottom left and right all have a repeating background. I’m not quite sure how you would do this with divs. Would it be 3 divs? 5?

With tables I would have 3 columns and 3 rows.

Thanks!

[upl-file uuid=aae6a139-75ca-43e1-9a06-aa860e9baf8c size=41kB]menu_example.jpg[/upl-file]

to post a comment
CSS

11 Comments(s)

Copy linkTweet thisAlerts:
@drhowarddrfineJul 25.2007 — Perhaps no divs at all. Divs are just an element like anything else. Sometimes you need them and sometimes you don't. You are looking at the layout as a table. I would want to know what the content was first. Divs might be the last thing I would think about after all that. Divs are for structural purposes, to contain related items. So some pages I create have no divs at all. Divs do not exist to replace tables.
Copy linkTweet thisAlerts:
@sticks464Jul 25.2007 — I would use 5 div's or a three column layout. Take a look here.

http://www.cssplay.co.uk/layouts/3cols.html#
Copy linkTweet thisAlerts:
@jtownauthorJul 25.2007 — Ok one thing I forgot to mention is that there is a different image at each of the 4 corners as well. Basically I want to create a frame around my text using images for the repeating background on the 4 sides along with 4 different corner images.

I see what you mean about not using divs for some things and maybe you're right. I'm still learning about divs and their advantages/disadvantages.

For instance ... check the attached. Assume it's all images .... would it be better to use divs (or even possible) or tables (which I currently use)?

[upl-file uuid=2ae65d6b-f07f-4575-8e0b-66ba8697cdb7 size=45kB]rounded_box_register.jpg[/upl-file]
Copy linkTweet thisAlerts:
@NogDogJul 25.2007 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang='en'&gt;
&lt;head&gt;
&lt;meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'&gt;
&lt;title&gt;Test&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
body {
background-color: white;
color: black;
font: 90% arial, sans-serif;
margin: 0;
padding: 10px;
}
#test {
background: white url(sides.png) repeat-y 0 0;
width: 476px;
margin: 0 auto;
padding: 0 35px 0 45px;
}
#test h2 {
padding: 0;
margin: 0 -35px 0 -45px;
}
#bottom {
margin: 0 -35px 0 -45px;
width: 556px;
padding: 0;
height: 21px;
background: white url(bottom.png) no-repeat 0 0;
}
--&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="test"&gt;
&lt;h2&gt;&lt;img src='top.png' alt='Registration'&gt;&lt;/h2&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.&lt;/p&gt;
&lt;p&gt;Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.&lt;/p&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.&lt;/p&gt;
&lt;div id="bottom"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


[upl-file uuid=88ded4e0-7e25-4cf0-a277-19b61f362af2 size=9kB]top.png[/upl-file]

[upl-file uuid=ba05eaf5-b813-46ea-a90e-7ad129568779 size=431B]bottom.png[/upl-file]

[upl-file uuid=bbd9a37f-f5b8-44f5-8323-2f3e1d10ee62 size=186B]sides.png[/upl-file]
Copy linkTweet thisAlerts:
@jtownauthorJul 25.2007 — Thanks Nog!

But what if I want to be able to specify the width without having to create a new header/footer/sides for each different width? What I would do with table is have 4 corner images and a repeating bg image for the sides, top and bottom allowing me to specify the width of the table and it would work for any size.
Copy linkTweet thisAlerts:
@NogDogJul 25.2007 — Here's my attempt using a percentage width (zip file contains test.html plus 8 .png graphic files):

[upl-file uuid=365b25fb-f89a-46e1-9711-31df3b67efa9 size=12kB]test.zip[/upl-file]
Copy linkTweet thisAlerts:
@jtownauthorJul 25.2007 — Thanks again Nog! I guess within a div I can align images differently unlike tables. Nifty.

One thing though, why do you use the H2 tag around the top images?
Copy linkTweet thisAlerts:
@NogDogJul 26.2007 — Thanks again Nog! I guess within a div I can align images differently unlike tables. Nifty.

One thing though, why do you use the H2 tag around the top images?[/QUOTE]

Because it seems to be some sort of heading ("Registration"), and it gives more semantic meaning to the document to use a tag with a relevant meaning as opposed to a more generic tag such as DIV.
Copy linkTweet thisAlerts:
@jtownauthorJul 26.2007 — Because it seems to be some sort of heading ("Registration"), and it gives more semantic meaning to the document to use a tag with a relevant meaning as opposed to a more generic tag such as DIV.[/QUOTE]

Ah I see ... so could I lump that into the parent div or if I wanted it as all divs would I need to create a new id?
Copy linkTweet thisAlerts:
@NogDogJul 26.2007 — If you make it a DIV, then you'll need to either give it an ID and reference that ID in the CSS, or give it a class and reference that class as a descendant of the containing DIV's ID.

Ultimately, you can use whatever tag you want, as long as it's some sort of block-level element. What you want to keep in mind are two things: how will it display in non-graphical browsers, and how will search engines interpret and weight the various elements?

If you use Firefox with the web developer extension, you can get an idea how it will appear in a non-graphic browser and what the logical and semantic flow of the document is. Simply open the page then select "CSS -> Disable Styles -> All Styles" and "Images -> Disable Images -> All Images". If the page still makes logical sense, then your HTML markup probably is reasonable.
Copy linkTweet thisAlerts:
@jtownauthorJul 26.2007 — Thanks Nog. Much appreciated. Hopefully I get the hang of this soon.
×

Success!

Help @jtown spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...