473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CSS Layouts - Is there an easier way?

Greetings,

I have been developing websites in CSS for a couple years; I claim to
be no expert, but certain things could definitely be easier.

Consider the box model and it's different implementations:

http://tantek.com/CSS/Examples/boxmodelhack.html

Microsoft's way and the web standards way. Ironically, though
Microsoft implemented the box model incorrectly, I consider it
superior.

One of the biggest issues that comes about when attempting to create
CSS web designs is fitting a bunch of boxes within a containing box
where the width unit specified on inner boxes may vary. I'm sure many
of you have run into this common problem -- some inner boxes are
measured in ems, some in pixels, some in percentages, etc. I'm not
advocating that a designer use inconsistent units of width without
reason; sometimes, however, certain designs do warrant differing
units.

Microsoft's way makes the calculations for fitting boxes across the
entire width of a containing box much easier. Today, using the
correct box model, some designers will nest their <div> tags inside of
an outer containing <div> tag (having no margin, no padding) in order
to mimic Microsoft's way inside the context of a standard's compliant
browser.

This lead me in my thinking to trying to come up with a better way to
solve old problems. I was thinking about a new way of laying out
pages where designers could eliminate the headache of trying to
specify all the right calculations for getting all their boxes fitted
properly together.

Here it is:

The "pushpin" property.

Imagine the following box.
<div id='example'></div>

tl t tr
+----------------------------+
| |
| |
| 'example' |
| div |
l | | r
| |
| |
| |
+----------------------------+
bl b br

Each box has named sides and corners necessary for use with the
pushpin property.

sides: t = top, r = right, b = bottom, l = left
corners: tl = topleft, tr = topright, bl = bottom left, br =
bottomright

Now for the purpose and the implementation of the pushpin...

Take the following 3 boxes contained inside the body.

<body>
...
...
<div id='menu'></div>
<div id='content'></div>
<div id='sidebar'></div>
...
...
</body>

+--------+ +-----------------+ +--------+
| | | | | |
| | | | | |
| | | | | |
| menu | | content | | sidebar|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+--------+ +-----------------+ +--------+

....and the accompanying CSS:

#menu {
width: 150px;
}
#content {
pushpin: left right menu;
width: auto; /* shrink-to-fit */
}
#sidebar {
pushpin: left right content;
width: 150px;
}

Here's the definition of pushpin:

pushpin {[side or corner name of this element] [side or corner name of
attached element] [attached block element id] ... }

Therefore...

#content {
pushpin: left right menu;
}

.... reads ...

join the "left" side of the the "content" block to the "right" side of
the "menu" block. The shorthand reads...

#content {
pushpin: left right;
}

join the "left" side of the #content block to the "right" side of the
preceding block (regardless of its ID, if any) present in the markup.

So what? Does this solve anything?

Lots of things:

1. Consider that a common fixed-width layout uses a background image
that includes sidebar coloring so that the sidebar will have the
"appearance" of extending all the way down the page.

http://www.alistapart.com/articles/fauxcolumns/

Using a "pushpin" tells the CSS rendering logic to join two
block-level elements entirely along their opposing sides (or corners
if desired). Using a pushpin would allow the actual sidebar to extend
fully down the page (not only by appearance).

In this way, designers wouldn't have to specify special margins or
padding to prevent the actual content from spilling into the area
immediately below the sidebar. Thus markup is greatly reduced. And
the background images assigned to the parts would actually contain
only the images required by each specific element.

2. Consider tables. How difficult is it to mimic complex table
layouts with CSS only and without tables? It can be done, but there
are a host of problems.

Consider...

+-------------------------------------+
| ele1 |
+-------+--------+------------+-------+
| ele2 | ele3 | ele4 | ele5 |
| | | | |
+-------+--------+------------+ |
| ele6 | ele7 | |
| | | |
+-------+---------------------+-------+

Looks like a table right? Designating a purpose for each of the 7
elements is irrelevant. The point is it's a mock layout that somebody
somewhere might use, and as far as tables go, it's nothing that
complex. Tables can be so much more complex than this.

Imagine how difficult it would normally be to lay this out using
tableless methods. Sure it could be done. But let me add a few
restrictions. You must do it using the following markup.

<div id='ele1'></div>
<div id='ele2'></div>
<div id='ele3'></div>
<div id='ele4'></div>
<div id='ele5'></div>
<div id='ele6'></div>
<div id='ele7'></div>

Notice there is nothing more and nothing less that the semantic markup
for the elements required by our hypothetical page. (Isn't that the
goal -- to avoid unnecessary markup?) There is no need for containing
elements to group elements together. Our markup contains nothing but
what is required semantically. (We didn't even need to specify
rowspan or colspan!)

Next restriction. Do it without "absolute" positioning.
Unfortunately, we want to maintain this layout regardless of whether
or not one element stretches to fit its content. Absolute positioning
will most likely create overlaps when this happens.

Here's our CSS:

#ele1 {width: 100%}
#ele2 {pushpin: topleft bottomleft ele1;}
#ele3 {pushpin: topleft topright ele2;}
#ele4 {pushpin: topleft topright ele3;}
#ele5 {pushpin: topleft topright ele4;}
#ele6 {pushpin: top bottom ele2;}
#ele7 {pushpin: topleft bottomleft ele3 left right ele6 topright
bottomright ele4 bottomright bottomleft ele5;}

Notice that "ele7" has multiple pushpins. Think of pushpins as the
metaphor they are. You can add as many as needed to join all the
corners and edges you like.

Notice that width was only specified on the top element (ele1).
Widths could have been specified on certain elements if they had a
desired width (regarless of unit). The remaining widths will be
evenly distributed; however, the pushpins must always perform their
duty. No element may ever accidentally spill over into the region of
some other element.

Futhermore, pushpinned elements could still speficy margins in order
to create visual gaps between the boxes.

One of the best features of the pushpin metaphor is that it is easy to
define layout in a way that is much easier to get our brains to
understand (my brain anyway) than to have to constantly play with
units of measurement. The unit measurements may still be specified on
the blocks whose width must be a certain size, but they may often be
omitted. Consider the three panel layout in the first example --
specifying the width on the content area was completely unnecessary.

I can offer many more examples of the benefits of the pushpin
metaphor, but I'm hoping you can begin to envision them for yourself.
I hesitate to go on and on with examples without first receiving some
feedback. Oftentimes, it's easy to imagine better ways, only to find
that more experienced persons can offer equally valid ways for
accomplishing the same within the context of what already exists.

As I said, for me the concept of telling the browser to join things
together based on common corners and edges seems far superior to
having to calculate widths. The visions I have for page designs
almost always involve a layout that in every respect looks like a
complex table (or many creative newspaper layouts). Yet I know that
for the sake of semantic markup tables are undesirable (they are meant
to markup tabular data!). Futhermore, think about the way that our
content (contained within tables) displays in text-only browsers.
Don't get me wrong, I'll use a table if it makes sense or it makes my
job a lot easier, but I try to avoid them because of my desire to have
good semantic markup.

I haven't worked out all the syntax, just the general concept. What
do you guys think about the "pushpin" metaphor? Am I on to something?
Or am I missing something completely?

Mario T. Lanza
Clarity Information Architecture, Inc.
2004.10
Jul 20 '05 #1
2 1824
Mario T. Lanza wrote:
Consider the box model and it's different implementations:

http://tantek.com/CSS/Examples/boxmodelhack.html

Microsoft's way and the web standards way.
Not quite. On the one hand, the box model for MSIE 5.x/Win, which is
also the model for MSIE 6.0/Win, but for the latter, only when it's in
quirks mode.[1]

On the other hand, the web standards way.
Ironically, though Microsoft implemented the box model incorrectly,
....in certain versions of their browser...
I consider it superior. Microsoft's way makes the calculations for fitting boxes across the
entire width of a containing box much easier. Today, using the
correct box model, some designers will nest their <div> tags inside
of an outer containing <div> tag (having no margin, no padding) in
order to mimic Microsoft's way inside the context of a standard's
compliant browser.
That's what I'd do, since it's a pretty easy solution.

I'd much rather have a solution to the sidebard width: 14em; content
width: 100%-14em, which would make floats more useful. But this isn't
really related to the broken box model.
#menu { width: 150px;


Why are you suggesting px for a text content width? Better rethink your
proposal, and come back when you've thought throught the issues a bit more.
[1] I've never tried to figure out the box model of NN4, IE4, etc.

--
Brian (remove "invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #2
"Mario T. Lanza" <ml****@lycos.com> wrote in message
news:bd*************************@posting.google.co m...
Greetings,

I have been developing websites in CSS for a couple years; I claim to
be no expert, but certain things could definitely be easier.

Consider the box model and it's different implementations:

http://tantek.com/CSS/Examples/boxmodelhack.html

Microsoft's way and the web standards way. Ironically, though
Microsoft implemented the box model incorrectly, I consider it
superior.

One of the biggest issues that comes about when attempting to create
CSS web designs is fitting a bunch of boxes within a containing box
where the width unit specified on inner boxes may vary. I'm sure many
of you have run into this common problem -- some inner boxes are
measured in ems, some in pixels, some in percentages, etc. I'm not
advocating that a designer use inconsistent units of width without
reason; sometimes, however, certain designs do warrant differing
units.

Microsoft's way makes the calculations for fitting boxes across the
entire width of a containing box much easier. Today, using the
correct box model, some designers will nest their <div> tags inside of
an outer containing <div> tag (having no margin, no padding) in order
to mimic Microsoft's way inside the context of a standard's compliant
browser.


Maybe the best way to deal with this is not to be so picky about dimensions
of boxes, and to leave the details up to the browser. E.g. not to specify
dimensions in pixels except when a box contains something (like an image)
with dimensions inherently specified in pixels. You won't get identical
results with all browsers, but then you never can anyway.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dario de Judicibus | last post by:
I wish to create two simple layouts by using only HTML, CSS and the minimum JavaScript as possible. Layouts should be "elastic" (no fixed widths and heights) and cross-browser enabled. The first...
6
by: Tristan Miller | last post by:
Greetings. Can someone point me to a good source of nice, simple stylesheets, similar to the W3C Core Styles provided at http://www.w3.org/StyleSheets/Core/? I don't need anything fancy like...
0
by: John Bradley | last post by:
I've read and understood the w3 specs on css1 and css2. I've done some positioned layouts on my own system that worked as expected. But - I'm concerned about letting anything on to the live system...
7
by: Alan J. Flavell | last post by:
A colleague recently breezed in with a new web page design. He didn't tell me where he got the ideas from, but ... Looking at his stylesheets, I noticed they identified themselves as...
16
by: Michael Rozdoba | last post by:
I'm far from a CSS expert, but what I see of it I really like & I love keeping content & style separate. I also hate the way table layout produces convoluted bulky code. However when asked why...
6
by: glakk | last post by:
I got on the tableless layout bandwagon early on, and thought it was a really cool way to lay out a page. I don't know why I thought it was so cool, except I guess I fell for the "oh, cool" talk. ...
5
by: Stan R. | last post by:
Greetings. I have a couple of questions concerning CSS layouts, as apposed to the old <tablemethod for creating layouts . Even after spending the last few days searching all over Google Groups, I...
13
by: Justin.Voelker | last post by:
Hello Everyone: I am in search of an easier way to develop pages. My most current website, www.Base2WebDesign.com, has the exact same layout throughout the entire site. Right now I use a...
3
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, Below is sample output in x12 EDI format. I'm using vb.net to create this output file but i'm not sure if .NET has any tools to make the coding more organized and/or efficient. Right now the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.