Results 1 to 12 of 12

Thread: Relatively Absolute or Absolutely Relative?

  1. #1
    HEXUS.social member Allen's Avatar
    Join Date
    Nov 2003
    Location
    Brighton
    Posts
    8,536
    Thanks
    363
    Thanked
    262 times in 168 posts
    • Allen's system
      • Motherboard:
      • ASUS Maximus VIII Gene
      • CPU:
      • Intel Core i5 6600K
      • Memory:
      • 2 x 8GB Kingston HyperX Predator DDR4-3000
      • Storage:
      • 256GB Samsung 950 PRO NVMe M.2 (OS) + 2 x 512GB Samsung 960 EVO in RAID 0 (Games)
      • Graphics card(s):
      • ASUS ROG Strix GeForce GTX 1080 Ti OC
      • PSU:
      • XFX P1-650X-NLG9 XXX 650W Modular
      • Case:
      • Fractal Design Node 804
      • Operating System:
      • Windows 10 Home 64-bit
      • Monitor(s):
      • 27" BenQ XL2730Z + 23" Dell U2311H
      • Internet:
      • Virgin Media 200Mbps

    Relatively Absolute or Absolutely Relative?

    This is probably gonna be an easy one for someone on here, but I need a quick bit of help with my CSS...

    I have used CSS before to layout websites, but I can't figure this one out and Google isn't being much help. However, it's gonna be a bit difficult describing what I want.

    OK, I have a main div that's centered within the page with a width of say 800 pixels and an auto height (this may be the problem). This is positioned relatively. Inside that is a header div with a height of say 100px positioned absolutely at 0px left and top. Below that I have two more divs, one on the left positioned absolutely at 100px top and 0px left with a width of say 100px and another div on the right with a width of 700px position absolutely 100px top and 100px left. So it looks a bit like this:



    This works to a degree, if I give the left and right divs the same height, everything is OK, if I give them an auto height then it will obviously only show the content and nothing after it.

    However, I need to add another div to the bottom so it looks like this:



    If I try and do this by giving it a width of 800px and a height of 100px and position it absolutely at 0px left and 0px bottom, it doesn't show (i'm presuming it's hiding behind the left and right divs as I didn't give the main div a height).

    So, what I ideally want is a header, a left and main section and a footer underneath. However, I need the left and main div to have the same height as eachother depending on which one is longer due to the content and the footer to stick to the bottom. But I would prefer not to set a height to any of the divs except for the header and footer. Is this possible?

    I'm probably making a right arse out of myself in the way I've described this, but I don't know how else to put it. Apologies in advance to all you uber developers who actually have a clue about coding () if I've made any mistakes or haven't made it clear enough what I need.

    If you want an example of my coding just ask. But don't laught at it!

    I guess I could do this easier with tables, but I want to get used to using CSS correctly and I since I will have multiple pages with this same layout, I would like to be able to edit any content necessary without having to worry about editing heights to match the amount of content.

    Cheers in advance!

  2. #2
    HEXUS.social member Allen's Avatar
    Join Date
    Nov 2003
    Location
    Brighton
    Posts
    8,536
    Thanks
    363
    Thanked
    262 times in 168 posts
    • Allen's system
      • Motherboard:
      • ASUS Maximus VIII Gene
      • CPU:
      • Intel Core i5 6600K
      • Memory:
      • 2 x 8GB Kingston HyperX Predator DDR4-3000
      • Storage:
      • 256GB Samsung 950 PRO NVMe M.2 (OS) + 2 x 512GB Samsung 960 EVO in RAID 0 (Games)
      • Graphics card(s):
      • ASUS ROG Strix GeForce GTX 1080 Ti OC
      • PSU:
      • XFX P1-650X-NLG9 XXX 650W Modular
      • Case:
      • Fractal Design Node 804
      • Operating System:
      • Windows 10 Home 64-bit
      • Monitor(s):
      • 27" BenQ XL2730Z + 23" Dell U2311H
      • Internet:
      • Virgin Media 200Mbps

    Re: Relatively Absolute or Absolutely Relative?

    I guess I'm talking a load of old codswallop then?



    Since asking this question, I have for the time being, settled for a much simpler design of everything down the middle, a header at the top, followed by a navigation pane, followed by the main content section and lastly, the footer. I would've prefered the menu on the left though as I have already built it...

    I guess there must be an easier way of doing it? Maybe looking at a few templates if there's any around. Anyone know of any decent free templates (I hate googling for free stuff, it almost always isn't or it's something dodgy)?

  3. #3
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Relatively Absolute or Absolutely Relative?

    hmmm,

    it's a tricky thing to do, this. What *might* work, is doing a three "stripe" layout with a header, "main" and footer, then splitting the main into a left "menu" and a right "content".

    But it'd take me more time than I have to test it for you...

  4. #4
    HEXUS.social member Allen's Avatar
    Join Date
    Nov 2003
    Location
    Brighton
    Posts
    8,536
    Thanks
    363
    Thanked
    262 times in 168 posts
    • Allen's system
      • Motherboard:
      • ASUS Maximus VIII Gene
      • CPU:
      • Intel Core i5 6600K
      • Memory:
      • 2 x 8GB Kingston HyperX Predator DDR4-3000
      • Storage:
      • 256GB Samsung 950 PRO NVMe M.2 (OS) + 2 x 512GB Samsung 960 EVO in RAID 0 (Games)
      • Graphics card(s):
      • ASUS ROG Strix GeForce GTX 1080 Ti OC
      • PSU:
      • XFX P1-650X-NLG9 XXX 650W Modular
      • Case:
      • Fractal Design Node 804
      • Operating System:
      • Windows 10 Home 64-bit
      • Monitor(s):
      • 27" BenQ XL2730Z + 23" Dell U2311H
      • Internet:
      • Virgin Media 200Mbps

    Re: Relatively Absolute or Absolutely Relative?

    Cheers, I will give that a go. Although, now I'm liking the simplicity of what I'm currently using, a header, a horizontal menu, content and lastly a footer.

    Still would be good to try and get this done though, purely for giving myself more practice with CSS.

  5. #5
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Relatively Absolute or Absolutely Relative?

    Ahhh sticky columns - they can't be done in pure CSS (or there are some nasty hacks to get round them). As are footers that stick to the bottom...

    it also depends on the layout markup... can we have a sniffle of that??? (just the header/maincontent/footer will be fine) I wanna see what you're up to!

  6. #6
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Relatively Absolute or Absolutely Relative?

    Quote Originally Posted by tiggerai View Post
    ... As are footers that stick to the bottom...
    That's what { position: fixed; bottom: 0; } is for, surely But not quite the layout that the OP was looking for, I admit.

    I use a splash + horizontal menu + content + footer a lot, and think it looks good, and also a little distinctive compared to the plethora of header + left menu sites out there. See http://www.animal-ed.co.uk/ for an example of how I do it (that one includes fake tabs ). Using { position: fixed; } you can do some very nice CSS frame effects, but I don't think that's exactly what you're after: it'd make the header, menu and footer stay in the same place on the screen while the page content scrolls within the frames...

    Quote Originally Posted by tiggerai View Post
    it also depends on the layout markup... can we have a sniffle of that??? (just the header/maincontent/footer will be fine) I wanna see what you're up to!
    Nosy!

  7. #7
    Don't feed the trolls... tiggerai's Avatar
    Join Date
    Aug 2003
    Location
    Milk & Beans
    Posts
    9,286
    Thanks
    271
    Thanked
    480 times in 313 posts
    • tiggerai's system
      • Motherboard:
      • Gigabyte MA770T-UD3P
      • CPU:
      • AMD PhenomII 955BE
      • Memory:
      • 4Gb Corsair XMS DDR3
      • Storage:
      • Lots
      • Graphics card(s):
      • Sapphire X1950XT
      • PSU:
      • Hiper Type-R 550w
      • Case:
      • Antec lovely black thing
      • Operating System:
      • Windows 7
      • Monitor(s):
      • 2x 20" widescreen
      • Internet:
      • Pipexpants

    Re: Relatively Absolute or Absolutely Relative?

    What I meant was, it's difficult to answer a positioning question when you don't know what the layout heirachy is! Not actually what his content was!

    { position: fixed; bottom: 0; } - and when your content extends past the bottom of the browser...

    http://matthewjamestaylor.com/blog/k...om-of-the-page

  8. #8
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Relatively Absolute or Absolutely Relative?

    I knew you weren't really being nosy - it was just the way you phrased it
    Quote Originally Posted by tiggerai View Post
    ... when your content extends past the bottom of the browser...
    I set a suitable margin-bottom on the content container - iirc this works on pretty much every browser that supports position: fixed; In fact, I always tend to control my content position by setting margins on the main content container rather than trying to position it absolutely / relatively: it seems to be the most reliable way to keep the content clear of the surrounding elements...

  9. #9
    HEXUS.social member Allen's Avatar
    Join Date
    Nov 2003
    Location
    Brighton
    Posts
    8,536
    Thanks
    363
    Thanked
    262 times in 168 posts
    • Allen's system
      • Motherboard:
      • ASUS Maximus VIII Gene
      • CPU:
      • Intel Core i5 6600K
      • Memory:
      • 2 x 8GB Kingston HyperX Predator DDR4-3000
      • Storage:
      • 256GB Samsung 950 PRO NVMe M.2 (OS) + 2 x 512GB Samsung 960 EVO in RAID 0 (Games)
      • Graphics card(s):
      • ASUS ROG Strix GeForce GTX 1080 Ti OC
      • PSU:
      • XFX P1-650X-NLG9 XXX 650W Modular
      • Case:
      • Fractal Design Node 804
      • Operating System:
      • Windows 10 Home 64-bit
      • Monitor(s):
      • 27" BenQ XL2730Z + 23" Dell U2311H
      • Internet:
      • Virgin Media 200Mbps

    Re: Relatively Absolute or Absolutely Relative?

    Quote Originally Posted by tiggerai View Post
    it also depends on the layout markup... can we have a sniffle of that??? (just the header/maincontent/footer will be fine) I wanna see what you're up to!
    Sorry, I presume by that you wanna see the code to see what I'm doing? If so, see the below.

    Sadly I had completely changed the layout after making this post, but still want to know if it's possible, so just chucked this together. Only took a couple of mins, so please excuse lack of "making it pretty". The god awful colours are used to easily point out the different sections.

    index.html:

    Code:
    <html>
    <head>
    <title>Example</title>
    <link href="main.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <div id="wrapper">
    <div id="header">Header</div>
    <div id="left">Menu<br /><br />Option 1<br />Option 2<br />Option 3<br />Option 4<br /></div>
    <div id="main">Main Section<br /><br />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porta, massa condimentum gravida ornare, lacus justo egestas tortor, et adipiscing justo odio vitae magna. Quisque nec urna a tortor eleifend sagittis non a augue. Fusce eget quam non mauris sollicitudin volutpat. Aenean vel erat et metus rutrum rutrum. Sed diam sapien, mollis vel mollis eget, auctor nec turpis. Donec mattis dui nec odio fermentum ultricies pretium ante viverra. Etiam interdum nunc ac augue blandit dapibus suscipit justo ornare. Nullam ut tortor enim, et varius ligula. Vestibulum felis quam, porttitor in pulvinar at, venenatis at mi. Phasellus hendrerit, nisl luctus pretium semper, nulla urna aliquam magna, in scelerisque erat enim a arcu.</p>
    <p>Curabitur bibendum vehicula sollicitudin. Nam eget leo volutpat elit congue ullamcorper. Fusce ultricies convallis metus eget condimentum. Praesent vel leo vitae magna volutpat placerat et sed lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean condimentum tellus id quam consectetur accumsan. Aenean nisi turpis, ultricies et molestie at, hendrerit ac metus. Quisque adipiscing metus vel nibh condimentum eget sollicitudin leo feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas hendrerit, odio non semper posuere, lorem nibh iaculis urna, et mollis tortor lectus ut arcu. In hac habitasse platea dictumst. Vestibulum sollicitudin, dolor nec malesuada pharetra, enim purus faucibus sapien, id placerat neque massa quis augue. Integer odio mi, pellentesque sed congue sit amet, rhoncus eget lorem. Donec aliquet iaculis scelerisque. Integer pulvinar est a est pretium tristique. Vivamus placerat, erat et scelerisque luctus, ante nibh sagittis lorem, sit amet mollis ante dolor et massa. Morbi et augue vitae mauris vulputate rutrum et quis urna. Suspendisse aliquam pulvinar nisl, sed dapibus eros fringilla non. Nulla consequat tristique urna nec pretium. Integer eu est eu orci fringilla iaculis ut in eros.</p>
    <p>Proin non porttitor sem. Mauris sit amet risus arcu. Vestibulum nec auctor urna. Nulla facilisi. Etiam in neque non augue tempor sodales sed in mi. Maecenas vestibulum urna vitae nunc facilisis vitae aliquet elit sodales. Phasellus pharetra nunc vel enim pulvinar id luctus quam convallis. Vivamus enim urna, placerat ac congue id, vestibulum nec dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam erat volutpat. Suspendisse porttitor dictum fermentum. Nullam congue nibh eget nisi aliquam mollis. Vivamus accumsan sem id sapien molestie ultricies. Phasellus eleifend elementum nulla, quis vulputate sapien commodo a. Mauris et sagittis ipsum.</p>
    <p>Proin ac urna ut tortor eleifend cursus. Curabitur varius vulputate lacus vitae vehicula. Curabitur pharetra varius rhoncus. Duis ante enim, fringilla id fringilla cursus, vulputate sit amet odio. Duis tortor elit, pellentesque tempor porttitor in, imperdiet eu ligula. Morbi consectetur tortor vel libero gravida facilisis. Sed dapibus mi et felis aliquet tristique lobortis metus consectetur. Sed commodo egestas hendrerit. Praesent egestas imperdiet consectetur. Proin ligula neque, suscipit quis ullamcorper eget, facilisis eu tortor. Cras nec neque et nulla sodales vestibulum et sit amet nisl. Sed congue sem sed est ornare laoreet sodales elit luctus.</p>
    <p>Phasellus suscipit fermentum justo id congue. Nullam vitae felis purus, et placerat nisi. Etiam tempor facilisis elementum. Phasellus ullamcorper nunc sit amet sapien dictum congue. Suspendisse porttitor turpis ut elit sagittis ut feugiat tortor aliquam. Suspendisse malesuada lorem eu lorem aliquet dapibus. Sed vestibulum dolor ut risus pharetra tincidunt. Curabitur dolor massa, vehicula non adipiscing ac, bibendum sed mi. Praesent vel leo diam. Proin ut ante quam, at cursus lectus. Mauris tincidunt tempus arcu, vitae lobortis mauris rhoncus sed. Aenean at ante ipsum. Donec sed leo nunc. Praesent sollicitudin faucibus imperdiet. Nullam libero orci, blandit sed sagittis eu, ultricies ut orci. </p>
    </div>
    <div id="footer">Footer</div>
    </div>
    </body>
    </html>
    main.css:

    Code:
    html, body {
    	background:#333333;
    	border:0;
    	padding:0;
    	font-family:Verdana;
    	font-size:12px;
    }
    
    div#wrapper {
    	position:relative;
    	width:900px;
    	height:1000px;
    	margin:0 auto;
    	background-color:#ffffff;
    }
    
    div#header {
    	width:900px;
    	height:100px;
    	top:0px;
    	background-color:#000000;
    	color:#ffffff;
    }
    
    div#left {
    	width:200px;
    	position:absolute;
    	top:100px;
    	left:0px;
    	background-color:#00ff00;
    	color:#000000;
    }
    
    div#main {
    	width:700px;
    	position:absolute;
    	top:100px;
    	left:200px;
    	background-color:#0000ff;
    	color:#000000;
    }
    
    div#footer {
    	width:900px;
    	height:100px;
    	position:absolute;
    	left:0px;
    	bottom:0px;
    	background-color:#ff0000;
    	margin:0 auto;
    }
    As you can see, by giving the wrapper div a height longer than the main div i can stick the footer at the bottom fine, but as I said in a previous post I don't want to have to change the wrapper div height for each page I make.

    So, is there any way of making the left div and the main div the same length and to stick the footer at the bottom?

    Hopefully my coding isn't too rubbish and at least half understandable, but please point out any errors I may have made.

  10. #10
    HEXUS.social member Allen's Avatar
    Join Date
    Nov 2003
    Location
    Brighton
    Posts
    8,536
    Thanks
    363
    Thanked
    262 times in 168 posts
    • Allen's system
      • Motherboard:
      • ASUS Maximus VIII Gene
      • CPU:
      • Intel Core i5 6600K
      • Memory:
      • 2 x 8GB Kingston HyperX Predator DDR4-3000
      • Storage:
      • 256GB Samsung 950 PRO NVMe M.2 (OS) + 2 x 512GB Samsung 960 EVO in RAID 0 (Games)
      • Graphics card(s):
      • ASUS ROG Strix GeForce GTX 1080 Ti OC
      • PSU:
      • XFX P1-650X-NLG9 XXX 650W Modular
      • Case:
      • Fractal Design Node 804
      • Operating System:
      • Windows 10 Home 64-bit
      • Monitor(s):
      • 27" BenQ XL2730Z + 23" Dell U2311H
      • Internet:
      • Virgin Media 200Mbps

    Re: Relatively Absolute or Absolutely Relative?

    Oh, and what's causing the border at the top and the bottom when I set "border:0;" and "padding:0;" in the CSS? Cheers!

  11. #11
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,231
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: Relatively Absolute or Absolutely Relative?

    As tig's said, there is no pure CSS way to ensure that the left and main will always be the height of the largest one, because the heights will depend on the content. CSS isn't really the best way to do columnar layouts - tables can do it but they're considered bad practice and they're not very accessible. I still think the best way would be to have
    Code:
    <div id="wrapper">
      <div id="header"></div>
      <div id="middle">
        <div id="left"></div><div id="main"></div>
      </div>
      <div id="footer"></div>
    </div>
    then play with left and main to put them next to each other (floats / display: inline-block / etc.), but it's certainly not straight-forward and it'll be trickier to get good cross-browser compatibility with that layout...

    As to what's causing your borders: could be borders on #wrapper (set border: 0; for that as well?) or margins on html or body - they'd be my first port of call. Also, what browser are you having issues with? I had a strange layout problem on one of my sites with IE8 that was resolved by adding <!DOCTYPE html> on the first line (this specifies that html is the root element - I assume without this it was adding an anonymous root element that was throwing everything out...).

  12. #12
    Flower Child stytagm's Avatar
    Join Date
    Aug 2004
    Location
    London
    Posts
    754
    Thanks
    47
    Thanked
    23 times in 18 posts

    Re: Relatively Absolute or Absolutely Relative?

    Bit of a bumpy post, and possibly not even what you're looking for, but this following sticky footer page has about the simplest non-javascript sticky footer I've seen, and it was really clearly explained and very easy to implement. Even works fine on IE6!

    It's valid CSS and while it has a little bit of superfluous and non-sematic markup, it's nothing to lose sleep over.

    http://ryanfait.com/sticky-footer/

    I've used it on a project at work that just went live and it's behaved very well all through testing in all browsers (unlike some of my other markup )
    They told me I was gullible ... and I believed them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Absolute Radio - Gotta Love it.......
    By Syd in forum Movies, TV, Music and Books
    Replies: 9
    Last Post: 29-06-2009, 03:17 PM
  2. Is it absolutely necessary ??
    By acro666 in forum PC Hardware and Components
    Replies: 9
    Last Post: 25-09-2007, 04:26 PM
  3. 26-piece tool kit, absolutely FREE
    By Couger in forum Retail Therapy and Bargains
    Replies: 11
    Last Post: 03-09-2006, 03:27 PM
  4. Relative XP?
    By Romanov in forum PC
    Replies: 1
    Last Post: 06-05-2005, 09:03 AM
  5. Eclipse relative class path help
    By LWA in forum Help! Quick Relief From Tech Headaches
    Replies: 3
    Last Post: 08-11-2004, 11:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •