Is it possible to vertical align in a div?
|
|
Thread rating:  |
Dave Rado - 17 Mar 2008 17:46 GMT Hi
See my mock-up at http://tinyurl.com/35tv29. The three icons are supposed to be vertically aligned on their bottoms (using "vertical- align: bottom"), but they aren't, they're vertically aligned on their tops. Is there any way to align them vertically on their bottoms (or middle for that matter) short of resorting to using a table (where "vertical-align: bottom" does work)?
Dave
Ben C - 17 Mar 2008 18:09 GMT > Hi > [quoted text clipped - 4 lines] > middle for that matter) short of resorting to using a table (where > "vertical-align: bottom" does work)? Vertical-align doesn't apply to blocks (like divs).
But you can set it on the imgs inside the divs if you want. Or set img to display: block which I think is more appropriate here.
Dave Rado - 18 Mar 2008 15:32 GMT Hi Ben
> Vertical-align doesn't apply to blocks (like divs). > > But you can set it on the imgs inside the divs if you want. I tried your suggestion but must be doing something wrong. See my mock- up at http://tinyurl.com/2qh2vy. Can you see what I'm doing wrong?
> Or set img > to display: block which I think is more appropriate here. I tried this suggestion as well but again, I must be doing something wrong. See my mock-up at http://tinyurl.com/2rzobt. Can you see what I'm doing wrong?
Perhaps I should explain that I am trying hard to understand the more complex parts of css but am finding it a real culture shock, having learnt my html in the early 90x, when everyone used tables, and then moved away from web development for several years, and I am now having to build a complex website and as I say am finding the change from using tables for layout to using css a real culture shock and a huge learning curve. I don't need convincing of the benefits of the change, but I need lots of hand holding.
Dave
Ben C - 18 Mar 2008 19:32 GMT > Hi Ben > [quoted text clipped - 11 lines] > wrong. See my mock-up at http://tinyurl.com/2rzobt. Can you see what > I'm doing wrong? You've got three different divs, two of which are absolutely positioned.
Vertical-align on the images is only going to align them if they're on the same line, which means (at least) all in the same block box.
> Perhaps I should explain that I am trying hard to understand the more > complex parts of css but am finding it a real culture shock, having [quoted text clipped - 4 lines] > learning curve. I don't need convincing of the benefits of the change, > but I need lots of hand holding. Best to say exactly what you are trying to do with the three images in the first place from the top.
Dave Rado - 18 Mar 2008 23:41 GMT HI Ben
> Best to say exactly what you are trying to do with the three images in > the first place from the top. I'm not sure what information you're asking for. I need to create a div 607px wide that is horizontally centred on the page, which I've managed to do successfully. Within this div I need to place three icons, one at the left edge of the div, one at the right edge of the div, and one centred within the div. I've also managed to do this successfully, and I' posted a mock-up (which is at http://tinyurl.com/35tv29) showing my code which did this. However, the three icons are top- aligned within the div and top-aligned relative to each other, whereas I need them to be bottom-aligned - something that is a breeze to do if one uses tables for layout, but I can't work out how to do it if one uses divs instead of tables. I was hoping someone would look at the code in my mock-up and tell me what modifications to make to my code in order that the three icons would appear in exactly the same horizontal position as before, but bottom-aligned relative to each other. I'm not sure what other information I could provide that is relevant. Can you help?
Dave
Bergamot - 18 Mar 2008 23:59 GMT > I need to create a > div 607px wide that is horizontally centred on the page, which I've [quoted text clipped - 5 lines] > aligned within the div and top-aligned relative to each other, whereas > I need them to be bottom-aligned They really only appear to be top aligned because the line heights are stretched as needed to fit the inline image. Baseline is the default alignment for images. If the line heights were equal, the baseline would be the same for all and they'd be aligned as you want.
Except maybe in IE. It doesn't do well with changing line-height of replaced elements.
 Signature Berg
Dave Rado - 19 Mar 2008 00:20 GMT HI Berg
> They really only appear to be top aligned because the line heights are > stretched as needed to fit the inline image. Baseline is the default [quoted text clipped - 3 lines] > Except maybe in IE. It doesn't do well with changing line-height of > replaced elements. It sounds like I should go back to using tables?
Dave
Ben C - 19 Mar 2008 00:22 GMT > HI Ben > [quoted text clipped - 17 lines] > other. I'm not sure what other information I could provide that is > relevant. Can you help? The simplest modification to the code you have is just replace "vertical-align: bottom" on both div.TopOfPageIcons div.right and on div.TopOfPageIcons div.left with "bottom: 0".
Bottom is used to position an absolutely positioned element relative to the bottom content edge of its container.
Also add img { display: block } and use a strict mode doctype, this is the best one to use to be sure of not getting quirks mode or some kind of almost-strict mode:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Then remove text-align and vertical-align from everywhere-- there are now no inline-level elements in the page at all, so neither of them will be doing anything.
Then when you've done that, get rid of the divs around the imgs altogether and transfer the position: absolute and bottom rules to the imgs. You can position them directly-- they don't need to be wrapped in divs.
If the imgs are position: absolute they don't need to be set to display: block since position: absolute implies display: block (although there's no harm in setting it).
HTH. Probably you should read a tutorial somewhere explaining the basics. You've got (in roughly ascending order of how often you probably need to use each one):
1. Normal flow (inline things breaking across lines, blocks stacking up one under the other, greedy auto width, conservative auto height). 2. Normal flow complicated by floats getting in the way. 3. Tables (which you know). 4. Absolute positioning (things go exactly where you tell them but be clear on what the containing block is)
Text-align and vertical-align belong mainly to strategy 1 and aren't really involved in strategy 4 which is what you're mostly using here.
Dave Rado - 19 Mar 2008 03:31 GMT Hi Ben
> The simplest modification to the code you have is just replace > "vertical-align: bottom" on both div.TopOfPageIcons div.right and on > div.TopOfPageIcons div.left with "bottom: 0". > > Bottom is used to position an absolutely positioned element relative to > the bottom content edge of its container.
> Then remove text-align and vertical-align from everywhere-- there are > now no inline-level elements in the page at all, so neither of them will [quoted text clipped - 4 lines] > imgs. You can position them directly-- they don't need to be wrapped in > divs. Thanks Ben, it's working beautifully now, and applying the positioning rules directly to the images instead of giving each image its own div is much simpler than the way I was trying to do it.
> Probably you should read a tutorial somewhere explaining the > basics. Once I've built my current website, which has a tight deadline (and which I'm not being paid for, but it's in an extremely good cause), I promise I'll read a css textbook cover to cover, but I'm on a very tight deadline at present and really appreciate any help you can give me. I frequently look at short web tutorials on the specific aspects of css that I'm working with at the time, but my deadline won't allow me to study a textbook in the way I'd like to yet. In any case I doubt whether any tutorial would have led me to come up with your suggestion, as I suspect that sort of suggestion comes from experience rather than from reading tutorials.
I have another related but different problem. I have a header in a simulated "document page", consisting of one or multiple paragraphs on the left-hand side and a page-number graphic on the right - see my mock-ups using a table to do this at http://tinyurl.com/2vql5q and http://tinyurl.com/3yqf5t . The text on the left (which may consist of one or multiple paragraphs) is vertically centred in its table cell and the number graphic on the right is top-aligned in its table cell.
I tried to use divs instead of a table to achieve the same effect and made a complete mess of it - see my mock-up at http://tinyurl.com/32xotl .
Can you see what I need to change in the code of my third mock-up in order to make it look identical to the first one (and to the second one if there is only one line of text in the header)? Or do you think that as dorayme suggests I should continue to use tables for this?
Dave
Dave Rado - 19 Mar 2008 03:38 GMT Hi Ben
> The simplest modification to the code you have is just replace > "vertical-align: bottom" on both div.TopOfPageIcons div.right and on > div.TopOfPageIcons div.left with "bottom: 0". > > Bottom is used to position an absolutely positioned element relative to > the bottom content edge of its container.
> Then remove text-align and vertical-align from everywhere-- there are > now no inline-level elements in the page at all, so neither of them will [quoted text clipped - 4 lines] > imgs. You can position them directly-- they don't need to be wrapped in > divs. Thanks Ben, it's working beautifully now, and applying the positioning rules directly to the images instead of giving each image its own div is much simpler than the way I was trying to do it.
> Probably you should read a tutorial somewhere explaining the > basics. Once I've built my current website, which has a tight deadline (and which I'm not being paid for, but it's in an extremely good cause), I promise I'll read a css textbook cover to cover, but I'm on a very tight deadline at present and really appreciate any help you can give me. I frequently look at short web tutorials on the specific aspects of css that I'm working with at the time, but my deadline won't allow me to study a textbook in the way I'd like to yet. In any case I doubt whether any tutorial would have led me to come up with your suggestion, as I suspect that sort of suggestion comes from experience rather than from reading tutorials.
I have another related but different problem. I have a header in a simulated "document page", consisting of one or multiple paragraphs on the left-hand side and a page-number graphic on the right - see my mock-ups using a table to do this at http://tinyurl.com/2vql5q and http://tinyurl.com/3yqf5t . The text on the left (which may consist of one or multiple paragraphs) is vertically centred in its table cell and the number graphic on the right is top-aligned in its table cell.
I tried to use divs instead of a table to achieve the same effect and made a complete mess of it - see my mock-up at http://tinyurl.com/32xotl .
Can you see what I need to change in the code of my third mock-up in order to make it look identical to the first one (and to the second one if there is only one line of text in the header)? Or do you think that as dorayme suggests I should continue to use tables for this?
Dave
John Hosking - 19 Mar 2008 05:53 GMT > I have another related but different problem. I have a header in a > simulated "document page", consisting of one or multiple paragraphs on [quoted text clipped - 12 lines] > one if there is only one line of text in the header)? Or do you think > that as dorayme suggests I should continue to use tables for this? You might try div.Header {width: 601px; position:relative; } and see if it gets you started. You'll want to look at margin or padding next, but you have a coding error in <p class="Header1> which is slowing down the testing process. Validate, fix the markup, provide some spacing, adjust.
HTH
 Signature John Read about the UIP: http://improve-usenet.org/
Ben C - 19 Mar 2008 09:38 GMT [...]
> I have another related but different problem. I have a header in a > simulated "document page", consisting of one or multiple paragraphs on [quoted text clipped - 12 lines] > one if there is only one line of text in the header)? Or do you think > that as dorayme suggests I should continue to use tables for this? It's up to you.
In this case, you could give HeaderLeft margin-right: 50px (and don't set width on it), move the page number image in the HTML source to above HeaderLeft (so it's the first child of <div class="Header"> and give it float: right.
You won't get anything vertically centered though. The only way to do vertical centering of a shrink-to-fit block is with tables. But the vertical centering isn't having much effect in your table version anyway since the height of the row is limited by the page number unless the contents of HeaderLeft are very short and the user has a very small font size.
Not using tables is easier if you cheat and allow your design to change a bit :) In particular vertical centering, some cases of horizontal centering, setting heights on things, makings columns the same height as each other, spacing things out evenly: all these things are often easier with tables. With no-tables CSS you tend to see a simpler kind of layout-- some decoration at the top and perhaps down the left side and not too much else.
Dave Rado - 27 Mar 2008 21:44 GMT Hi Ben and John
Apologies for the delay in replying, but I've been experimenting and creating more mock-ups.
> John wrote: > you have a coding error in <p class="Header1> Sorry about that - there was a missing quotation mark ...
****
I've *sort of* got it working in non-IE browsers, albeit without the vertical centring (which I do need, however, for reasons discussed below) - see my "mock-up 3" at http://tinyurl.com/32xotl .
"Mock-up 3" is meant to look identical to "mock-up 2" (the one at http://tinyurl.com/3yqf5t , which I posted earlier in this thread, and which uses a table for the page header).
Apart from the lack of vertical centring, mock-ups 2 and 3 do look almost identical to each other in *non*-Microsoft browsers, but they don't in IE. In IE 6 and 7, in "mock-up 3", an unwanted 3px gap has appeared between the article title/page no. div and the orange line below it, for some reason that I can't fathom; and in IE 5.5, in addition to this problem, the right-hand edge of the page no. graphic is hidden, again for some reason that I can't fathom. Do you understand why, and how to fix this? I didn't get the latter (IE 5.5) problem with the three icons that you helped me position earlier in the thread.
In order to try to fix the IE 5.5 problem of the right-hand edge of the page no. graphic being hidden, I then tried using: img.PgNo {position: absolute; right: 0} (instead of using {float: right}), which was the method that you had suggested and which worked well for the rightmost of the three icons (img.TopOfPageIconsRight) above the document page earlier in this thread; but instead of aligning the image to the right of its parent div, (div.Header), it aligned it to the right of that div's parent div (div.DocumentPage) - in all browsers - and I don't understand why - see my "mock-up 4" at http://tinyurl.com/3dfm37 . Again, do you understand why, and how to fix this?
****
> Ben wrote: > You won't get anything vertically centered though. The only way to do vertical centering of a shrink-to-fit block is with tables. I've found several web tutorials that claim it is possible to do this (e.g. see http://tinyurl.com/2jhlbp), but I can't get their methods to work in any version of IE, in my scenario.
It works quite well if there is a one-line header (as in my "mock-up 5" at http://tinyurl.com/38umww (in which I've used IE conditional comments instead of the # hack used at http://tinyurl.com/2jhlbp, as the former seems more correct to me). Apart from the problem (described above) that using {right: 0} positions the image with respect to the wrong div for some reason, it looks fine in Firefox; although (again, as described above), in IE there is an unwanted gap between the header and the orange line below it. But when there is a multi-line header, as in my "mock-up 6" at http://tinyurl.com/3xhgl6 , then while it still looks okay in Firefox (apart from the mis- positioned page number), it looks completely wrong in IE - the top of the text block is moved up above the top of the graphic, which I don't want it to be. Is there a fix for this? I tried adding the setting: div.HeaderLeft {top: 0} in the IE conditional code section, but it made no difference.
I'm starting to think that you're right and that those web tutorials that imply thyat one can have cross-browser table-like vertical centring using css are misleading, in that while it is possible to get a sort of vertical centring in IE with css, it only seems to work properly if one can guarantee that the height of the contents of the div will never exceed the height of the div - which I can't guarantee. So I think this is probably a case where I'll have to stick with using a table. But I'd still be grateful for answers to my other questions above.
The reason I need vertically centred text for this, by the way, is that when the header only contains one line of text, which it frequently does, it looks much more pleasing on the eye if it is vertically centred relative to the page number graphic, as in "mock-up 2" (http://tinyurl.com/3yqf5t) than it does if it is not, as in "mock- up 3" (http://tinyurl.com/32xotl) - even in Firefox (and the difference is much more stark in IE).
****
I have some other layout tables that I had been hoping to convert to divs but in which the text also need to be vertically centred, although unlike the above table, I think I *can* guarantee that the height of the content of the other tables or divs will never be greater than the height of the divs themselves, so I guess I *could* use the vertical centring workaround method described at http://tinyurl.com/2jhlbp to replace those tables with divs, but I'm wondering whether it's really justified, given that this workaround seems quite clunky to me (in order for it to work in IE). See my mock-up of a menu at http://tinyurl.com/36pscl , and of a footer at http://tinyurl.com/33fej9 , which currently both use simple css-based tables. (Or you can see both of them in full context at http://tinyurl.com/28mcte, but the othetr mock-ups are much simpler and easier to make sense of).
In your opinion, would it be advisable to convert these tables to divs using the above workaround? The reason I'm not sure is that most of the normal reasons for using divs rather than tables don't seem to me to apply in either case, mainly because the workaround to get the vertical centring in IE seems quite clunky to me - it doesn't seem to reduce the amount of code required - on the contrary, I suspect in the case of the footer it would actually increase it - and - correct me if I'm wrong, but I doubt it would make the html any easier for a screen reader to navigate, because it requires several additional divs to make it work. But I would be grateful for your thoughts on this.
Dave
Ben C - 27 Mar 2008 23:25 GMT [...]
> Apart from the lack of vertical centring, mock-ups 2 and 3 do look > almost identical to each other in *non*-Microsoft browsers, but they [quoted text clipped - 4 lines] > is hidden, again for some reason that I can't fathom. Do you > understand why, and how to fix this? I don't know anything about IE.
> I didn't get the latter (IE 5.5) > problem with the three icons that you helped me position earlier in [quoted text clipped - 11 lines] > see my "mock-up 4" at http://tinyurl.com/3dfm37 . Again, do you > understand why, and how to fix this? Position: absolute; right: 0 puts the box 0px from the right edge of its container, which is the nearest ancestor with position: relative, fixed or absolute.
In your case that's DocumentPage. If you make div.Header position: relative then it will become the container for the PgNo which is what you want.
> **** > [quoted text clipped - 3 lines] > I've found several web tutorials that claim it is possible to do this > (e.g. see http://tinyurl.com/2jhlbp) That is using tables (display: table-cell is tables, but in a good way, but it won't work in IE).
Position: absolute and top: 50% does sort of work. This is a useful page about vertical centering:
http://www.student.oulu.fi/~laurirai/www/css/middle/
[...]
> I'm starting to think that you're right and that those web tutorials > that imply thyat one can have cross-browser table-like vertical > centring using css are misleading, in that while it is possible to get > a sort of vertical centring in IE with css, it only seems to work > properly if one can guarantee that the height of the contents of the > div will never exceed the height of the div That's basically the problem with position: absolute and top: 50%.
> - which I can't guarantee. So I think this is probably a case where > I'll have to stick with using a table. That is the best course of action, unless you can compromise on wanting vertical centering.
[...]
> The reason I need vertically centred text for this, by the way, is > that when the header only contains one line of text, which it [quoted text clipped - 3 lines] > up 3" (http://tinyurl.com/32xotl) - even in Firefox (and the > difference is much more stark in IE). To my eye the one that isn't vertically centered looks just fine :)
> I have some other layout tables that I had been hoping to convert to > divs but in which the text also need to be vertically centred, [quoted text clipped - 13 lines] > In your opinion, would it be advisable to convert these tables to divs > using the above workaround? In my opinion stick with the tables if you must have vertical centering.
> The reason I'm not sure is that most of the normal reasons for using > divs rather than tables don't seem to me to apply in either case, > mainly because the workaround to get the vertical centring in IE seems > quite clunky to me I agree.
[...]
> - and - correct me if > I'm wrong, but I doubt it would make the html any easier for a screen > reader to navigate, because it requires several additional divs to > make it work. I don't know much about screen readers but someone here I think once pointed out that his screen reader just reads what's actually _displayed_ in the browser window-- in other words it grabs text off the page like a clipboard copy operation, and doesn't look at the HTML source at all.
Dave Rado - 28 Mar 2008 17:56 GMT Hi Ben
> Position: absolute; right: 0 puts the box 0px from the right edge of its > container, which is the nearest ancestor with position: relative, fixed [quoted text clipped - 3 lines] > relative then it will become the container for the PgNo which is what > you want. That fixed the IE5.5 problem, thanks. For some reason IE5.5 can cope with Position: absolute; right: 0 but seems not to be able to cope with float: right.
> In my opinion stick with the tables if you must have vertical centring. Thanks, that's one decision made, anyway.
> I don't know much about screen readers but someone here I think once > pointed out that his screen reader just reads what's actually > _displayed_ in the browser window-- in other words it grabs text off the > page like a clipboard copy operation, and doesn't look at the HTML > source at all. Okay thanks, that's a relief to know. Given this, it's odd, though, that screen reader accessibility is often given in tutorials as a primary reason not to use tables for layout.
Dave
Ben C - 28 Mar 2008 18:25 GMT [...]
>> I don't know much about screen readers but someone here I think once >> pointed out that his screen reader just reads what's actually [quoted text clipped - 5 lines] > that screen reader accessibility is often given in tutorials as a > primary reason not to use tables for layout. Well you can't believe everything you read in tutorials :)
There may be other screen readers that do use the HTML, or it may just be one of those myths that gets around.
In principle you'd think a screen reader _should_ read the HTML, not the screen. But, they may be designed to read text off any application, not just a browser, and since lot of websites don't follow accessiblity guidelines it may also work better in practice just to read the screen.
Bergamot - 28 Mar 2008 19:08 GMT > There may be other screen readers that do use the HTML, or it may just > be one of those myths that gets around. I imagine that, like anything else, not all screen readers are created equally. Note that there is also a difference between an aural browser and screen reader. An aural browser would more likely be looking at the HTML or DOM tree rather than whatever ends up on screen.
IBM's Home Page Reader (now defunct, I think) did read the HTML top down, but applied styles like visibility:hidden as well.
> In principle you'd think a screen reader _should_ read the HTML, not the > screen. But, they may be designed to read text off any application, That is generally what a screen reader is - a multi-purpose app, not just for web stuff.
 Signature Berg
David Stone - 28 Mar 2008 22:20 GMT > [...] > >> I don't know much about screen readers but someone here I think once [quoted text clipped - 11 lines] > There may be other screen readers that do use the HTML, or it may just > be one of those myths that gets around. IIRC, the issue is with tables nested several layers deep in order to achieve a certain layout, rather than reading the content of a single table that is being used to present tabular data.
dorayme - 17 Mar 2008 23:14 GMT In article <0e88b9f9-4edc-4cf9-81bc-ac1b31978754@s37g2000prg.googlegroups.co m>,
> Hi > [quoted text clipped - 6 lines] > > Dave Perhaps you can develop from this idea, instead of your html:
<div><img src="../images/Icons/AcrobatSmall.gif" border="0" height="100" width="21"></div>
<div><img src="../images/Icons/Bookmark.gif" border="0" height="50" width="28"></div>
<div><img src="../images/Icons/Key.jpg" border="0" height="250" width="26"></div>
(I have exaggerated your img heights for demo purposes)
And for css, nothing complicated at all, like:
div {display: inline; margin:5%}
 Signature dorayme
Dave Rado - 18 Mar 2008 15:36 GMT Hi dorayme
> Perhaps you can develop from this idea, instead of your html: > [quoted text clipped - 12 lines] > > div {display: inline; margin:5%} I tried your suggestion but must be doing something wrong - see my mock-up at http://tinyurl.com/2pjwwy. Can you see what I'm doing wrong? Also, I can't see anything in your code that specifies the horizontal postions of the three icons. They need to have the exact horizontal positions that were specified in my original mock-up at http://tinyurl.com/35tv29.
See also my note to Ben C about my relative lack of expertise and need for hand-holding.
Dave
dorayme - 18 Mar 2008 23:59 GMT In article <d0de5bbf-f017-49fe-98b8-8b3fd7012c0f@i29g2000prf.googlegroups.co m>,
> Hi dorayme > [quoted text clipped - 26 lines] > > Dave What made you think your http://tinyurl.com/2pjwwy was a mockup of my suggestion above?
 Signature dorayme
Dave Rado - 19 Mar 2008 00:22 GMT Hi dorayme
> What made you think your http://tinyurl.com/2pjwwy was a mockup > of my suggestion above? > > -- > dorayme Obviously I haven't understood your suggestion.
Dave
dorayme - 19 Mar 2008 02:49 GMT In article <848847b1-b4e7-41a3-9db9-94f10867373b@i12g2000prf.googlegroups.co m>,
> Hi dorayme > [quoted text clipped - 7 lines] > > Dave It's ok Rado.
But forget about this for now and let us go through an even simpler tactic. You want a 607px wide line for the images to go on.
I do not know quite how you want the images to be evenly spaced on this line because your left and right images have different widths and so this is open to at least two different interpretations. If you don't follow this, ask me.
Let's assume you want the middle image's left side to be the same distance from the right side of the left image as the distance from its right side to the left side of the right image.
I have made up a page for you that may help you understand the ideas here:
<http://netweaver.com.au/alt/inlineImages/rado_imagesOnALine.html>
or
<http://tinyurl.com/3bybh4>
Follow some or all the links for further information.
(I think I did say to you ages ago that unless you are super keen on a course of study in this business, you should just use tables for where you are fussy with exact layouts. But I made the above in case it helps you or anyone else)
 Signature dorayme
Dave Rado - 19 Mar 2008 03:37 GMT Hi dorayme
> I have made up a page for you that may help you understand the > ideas here: > > <http://netweaver.com.au/alt/inlineImages/rado_imagesOnALine.html> Many thanks, I'll study that page soon. However, Ben's suggestion worked for me, so although I'm sure yours would work just as well, I'll go with what is already working.
> (I think I did say to you ages ago that unless you are super keen > on a course of study in this business, you should just use tables > for where you are fussy with exact layouts. But I made the above > in case it helps you or anyone else) I thought you only said it's okay to use tables for numbering, including for heading numbering, and I've gone with your suggestion on that. But for layout I thought tables were considered a no-no these days? In any case with respect to my original query, Ben's suggestion works great (and I'm sure yours does too, and I will study yours shortly), and it does simplify the code compared with using a table. But I have a similar but different problem which I've just posted about in reply to Ben.
Dave
dorayme - 19 Mar 2008 04:12 GMT In article <fa0836f3-4e1d-4648-81bf-7828ef466cf4@n77g2000hse.googlegroups.co m>,
> I thought you only said it's okay to use tables for numbering, > including for heading numbering, and I've gone with your suggestion on > that. But for layout I thought tables were considered a no-no these > days? I was suggesting to be a bit naughty to ease the pressure on yourself, that's all.
 Signature dorayme
Dave Rado - 27 Mar 2008 21:55 GMT Hi dorayme
> > But for layout I thought tables were considered a no-no these > > days? > > I was suggesting to be a bit naughty to ease the pressure on > yourself, that's all. I'm trying to find the right balance between good practice (it's going to be a public site viewed by a large number of people) and yet not being so fanatical about avoiding tables that it ends up defeating the object. So I went with your suggestion to use tables for numbering, including for heading numbering; and (see my most recent reply to Ben C) it looks as if I may end up keeping some of my layout tables after all; but in the case of the three icons that I posted about at the start of this thread, I've managed to replace my table with a div, and I'd like to replace as many of my tables as divs as I can, but subject to the above qualifications.
Dave
dorayme - 19 Mar 2008 04:30 GMT In article <fa0836f3-4e1d-4648-81bf-7828ef466cf4@n77g2000hse.googlegroups.co m>,
> Hi dorayme > [quoted text clipped - 6 lines] > worked for me, so although I'm sure yours would work just as well, > I'll go with what is already working. I have little doubt that Ben's suggestion would work. My concerns were twofold. One, if something goes wrong with absolute positioning, you will have to ask Ben again how to fix it. In other words, it is a trickier business. What is your final code looking like?
inline img route for the specific thing you wanted is likely easier for you to understand or adapt for different widths etc. And the code is simple:
<div class="container"> <img src="../pics/crimson.png" height="200" width="21" alt=""><img id="centre" src="../pics/crimson.png" height="70" width="26" alt=""><img src="../pics/crimson.png" height="150" width="28" alt=""> </div>
That's it for the html and the css is, essentially just:
div.container {width: 607px} #centre { margin-left:266px; margin-right: 266px; }
My other concern was, I was infuriated by the pixels not adding up till I realised about the white space. Fixed when there was none between the tags in the img markup. In other words, it is just an interesting matter. <g>
 Signature dorayme
Dave Rado - 27 Mar 2008 21:45 GMT Hi dorayme
Apologies for the delay in replying, but I've been experimenting and creating more mock-ups.
> I have little doubt that Ben's suggestion would work. My concerns > were twofold. One, if something goes wrong with absolute > positioning, you will have to ask Ben again how to fix it. In > other words, it is a trickier business. What is your final code > looking like? The code for just positioning the three icons is at http://tinyurl.com/34j9ws . However, to see the icons in some context, see the mock-up at http://tinyurl.com/3yqf5t . (Or to see it in much fuller context, but with external stylesheets and much more code, and therefore harder to follow, see http://tinyurl.com/28mcte).
You'll notice that I have given the leftmost icon a Left value of 10px, so it isn't at the far left of the div. The reason for this is that the right-most icon of the three is supposed to look as if it is centred on the same point that the page number graphic below it is centred on (which is the same point that the text below that is justified to), and in order for this to be possible and yet for the div itself to be centred, and for the left icon to line up with the text below it, as it's meant to, the left edge of the div had to be wider than it would otherwise have been, necessitating the left value of 10px. I found this relatively easy to get my head around using absolute positioning of the icons, but more complicated using the inline method.
Another reason for my preferring the absolute positioning method is that the gap between the bottoms of the icons and the "document page" below them (see the second two mock-ups linked to above) needs to be the same regardless of the height of the icons (some pages don't contain all three icons, and therefore the maximum height varies). This is automatic using absolute positioning of the images, but not if the images are inline.
A third reason is that if you look at the source of the third mock-up above, you'll see that the icons contain a lot of javascript (roll- overs and tooltip-like hover text), so they're a lot more than just images; and having to put all three images on one line would therefore make the code less readable and maintainable, in my opinion.
***
But you're right that I did immediately hit a snag with the absolute positioning method, which I have solved with some offline help from a friend, but neither he nor I fully understand the solution.
In order to push the "document page" (div.DocumentPage) below the icons, I had to make its position relative and specify a value for Top, which was fine and dandy except that I wanted there to be a space below the "document page" (as in the second mock-up above - or in the case of the third mock-up, I wanted a space between the document page and the "Next/Previous" footer below it. To achieve this, I had to add a spacer div below the document page, as in:
div.BelowDocSpacer {height: 95px}
<div class="BelowDocSpacer"> </div>
What confuses me is that the height I had to specify of 95px is 44px larger than the actual height of the space created below the "document page" by it, which is 51px, not 95px. Do you know why one has to specify a height for the spacer div of 44px greater than the space one actually wants to create?
Dave
Ben C - 27 Mar 2008 23:43 GMT > Hi dorayme > [quoted text clipped - 12 lines] > with external stylesheets and much more code, and therefore harder to > follow, see http://tinyurl.com/28mcte). [...]
> But you're right that I did immediately hit a snag with the absolute > positioning method, which I have solved with some offline help from a [quoted text clipped - 3 lines] > icons, I had to make its position relative and specify a value for > Top, which was fine and dandy Moving things with position: relative is a bit risky, because in a sense they don't really move, they just get rendered offset from their real position as it were at the last minute. The space they occupy and their effect on the positions and sizes of sibling and parent boxes is just the same as if you didn't offset them.
In this case, it might have been better to give body margin-top: 80px or something instead, because that moves everything down properly.
> except that I wanted there to be a space > below the "document page" (as in the second mock-up above - or in the [quoted text clipped - 11 lines] > specify a height for the spacer div of 44px greater than the space one > actually wants to create? It's because your DocumentPage is "really" 84px higher up than it looks. You've also got a 40px bottom margin on DocumentPage which is the extra 40px. 40 + 44 = 84.
Think of relative positioning like this: the whole page is first laid out as if all relatively positioned boxes had top: 0 and left: 0. Then, afterwards, each relatively postioned box is translated by whatever you set for top, left, bottom or right. It takes its descendents with it when it moves, but that's all, nothing else is affected. The page isn't laid out again.
A simple example:
<div id="container" style="border: 1px solid black"> <div style="height: 100px" id="A"></div> <div style="height: 200px" id="B"></div> </div>
Normally, B's top edge will start 100px from the top of the container.
Now make A position: relative; top: 150px. *B doesn't move*. Its top is aligned with where the bottom of A was before A was offset.
But if you give A instead a top margin of 150px, it moves down properly, and B flows underneath it like it should.
Dave Rado - 28 Mar 2008 17:57 GMT Hi Ben
> Moving things with position: relative is a bit risky, because in a sense > they don't really move, they just get rendered offset from their real [quoted text clipped - 4 lines] > In this case, it might have been better to give body margin-top: 80px or > something instead, because that moves everything down properly. Except that doing that also moves the three icons above the document page down to below the top of the document page, when I try it - see my mock-up at http://tinyurl.com/2j68p3 (the mock-up showing how I want it to look is at http://tinyurl.com/3yqf5t). This was my original reason for setting the DocumentPage div to have a relative position.
If I make div.TopOfPageIcons have an absolute position instead of a relative one (which does fix the above problem), it stops being centred.
What do I need to change to my code at http://tinyurl.com/2j68p3 to make it look like http://tinyurl.com/3yqf5t ?
> Think of relative positioning like this: the whole page is first laid > out as if all relatively positioned boxes had top: 0 and left: 0. Then, [quoted text clipped - 17 lines] > But if you give A instead a top margin of 150px, it moves down properly, > and B flows underneath it like it should. A very clear and helpful explanation, thanks.
Dave
Ben C - 28 Mar 2008 21:21 GMT > Hi Ben > [quoted text clipped - 19 lines] > What do I need to change to my code at http://tinyurl.com/2j68p3 to > make it look like http://tinyurl.com/3yqf5t ? Just remove top: 76px from div.TopOfPageIcons.
Dave Rado - 28 Mar 2008 22:26 GMT > Just remove top: 76px from div.TopOfPageIcons. Or better still (because that made the icons touch the top of "document page" instead of being slightly above it), replace it with top: -8px.
Many thanks, Ben, you've been a huge help.
Dave
dorayme - 28 Mar 2008 00:02 GMT In article <790bb335-75d5-4564-8950-4f5d946b4772@s8g2000prg.googlegroups.com>,
> Hi dorayme > [quoted text clipped - 21 lines] > div itself to be centred, and for the left icon to line up with the > text below it, as it's meant to, the left edge of the div had to be ...
Well good luck on all this... I have lost for the moment my grasp of what you were doing and all this looks daunting! My feeling, I hope you don't mind me saying this, is that you are taking on a lot of work for yourself for possible gains that are not worth the effort. If you can *easily* meet most of your layout requirements in tables, I would not condemn you!
You might consider it revelatory to *not* require such complicated and exact layout. Have you really taken your head out of the considerable details you are involved with and really thought how you might deliver your material in a much simple way without compromising what the end user will truly benefit from?
 Signature dorayme
Dave Rado - 28 Mar 2008 18:01 GMT Hi dorayme
> You might consider it revelatory to *not* require such complicated and > exact layout. Have you really taken your head out of the considerable > details you are involved with and really thought how you might deliver > your material in a much simple way without compromising what the end > user will truly benefit from? I believe so. I hope that if you disagree, you will still be willing to help me find solutions to specific problems that I post about.
Dave
|
|
|