HTML/CSS Question

Started by DoorKnobHandle, Wed 04/07/2012 20:18:59

Previous topic - Next topic

DoorKnobHandle

Hey there!

I'm working on a website for a project and I have a little problem with the layout. What we want is a blind table layout like this:

|----|--------|----|
|    | HEADER |    |
|    |--------|    |
|    | NAVBAR |    |
|    |--------|    |
|    |        |    |
|    |        |    |
|    |        |    |
|    | CONTENT|    |
|    |        |    |
|    |        |    |
|    |        |    |
|    |--------|    |
|    | FOOTER |    |
|----|--------|----|


The left and right columns are what we call bumpers. There's cool pre-rendered art in there as this is for an upcoming game! I have this laid out easily as a blind table in HTML where the left and right bumpers use the rowspan property and all the middle table cells have a width and max_width of 1024px.

My first question is: how can I ensure this collapses properly in lower resolutions. The middle column is 1024px wide and should ALWAYS stay at that size and centered in the middle. When you shrink the browser window or view the page in lower res, the bumpers should simply shrink.

My second question is: at 1920x1080 screen resolution, for example, the bumper art is still a bit wider than the space it's got. When looking at the page in 1280x720, for example, the bumper art for those left and right columns is much to wide of course. Is there a way to have the tables cut off the bumper art FROM the right direction? That is, the INSIDES of the bumpers (right edge for left bumper and vice verse) should always stay at the edge of the table cell, the OTHER side should get cut off. I've tried overflow:hidden tags and a couple other things and nothing really works properly, overflow:hidden doesn't do anything in my case for example.

I'm stumped on how to set this up properly, and would greatly appreciated any help from you web-designers! If you need more info or anything, please let me know!

Anian

#1
Ok, I don't know how much you dabble in html and such so I just tell you what I gathered from your post.

If you're not gonna use divs and what's called "responsive" design (basically you define a grid in .css which tells at what resolutions what happens to a particular segment of the page) - there are wordpress themes that have this already in them but I find that most people override those properties as you lose some control over the look of the page, especially if you're like me and don't know enough php so you modify other people's themes...it gets bloody complicated and messy real fast in my opinion.

Ok gone too far with that :grin: If you're gonna stick with tables and just make it simple and easy, just with manual updating of html instead of blog and such features of CMS, here's what I'd do:
I'd suggest center the main table (without the bumpers) (you can do this with a div as well, just mark how far from the left it is), I found that tables have an align atribute but you better handle it with css because it seems it's going to be outdated soon. Here's complete solution to centering the table, just copy paste the solution you want: http://www.granneman.com/webdev/coding/css/centertables/
I think you can even use this in a css
Code: AGS
table { margin: auto; }


Main thing is leave the bumpers out of the table completly, no rowspaning, then put the prerendered background as a background image for the whole page and turn off repeat, also center it. That way no matter what size the screen is, the viewer will still see the content (the table with header, navbar, content, footer) the way it's meant to be seen and the size of the background will be ignored if it's smaller than those 1024px or whatever you set the content/table to be the width off.
The browser won't look at the bumper images as content but as for example a background color, but you'll have control and the readers won't know the difference.

Background image should be like prerendered stuff on the right and the left with a 1024px wide black or whatever color in the middle.
And here's the css code you need of the background, just replace the smiley.gif with the image you want to use and where it is uploaded:
Code: AGS
body
{ 
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center; 
}
I don't want the world, I just want your half

DoorKnobHandle

First of all, thanks a ton, you're a life-saver!! :)

I like all of this EXCEPT that this means we have to bake the bumpers into the background image. See, the plan is to have a small tileable spacefield graphic as the background and then the bumper graphics are spaceships that blend over that spacefield background.

Is there any way to modify your approach to work like that?

Anian

#3
I see, well CSS3 does have that option of using multiple backgrounds (it's just what you might think it is, google multiple backgrounds css3, there are plenty of easy tutorials).

But not all people have the latest browsers so, other options:
Maybe make starfield background image repeat and then make a div that has the width of the table(with the content stuff) + whatever you need for the bumpers with another background image with the ships and the gap/black area in the middle (if you want it to blend, use gif and make the edges on the left and right with transparency). Within that div place the table with the content, centered.

Or:
If you just want to make it really simple you could make just the ordinary background image which shows blank center area (or anything at all) + bumpers with ships + an area which has the stars that fade to black on the far left and far right side - just one big image.
Then make the background color of the body black and you basically get the baked background but you also get a bit of the starfield in it, even it's not tileable. Still should be an ok small size if the starfield is not overly complicated.
I don't want the world, I just want your half

DoorKnobHandle

#4
Okay I went for the div approach now.

So I have a div enclosing everything in my HTML body using the style
Code: AGS
width:2048; height:1024; background-image:url("images/bumper.png");
and in that, I have my blind table which is now just a single column with 4 cells, header at the top, navbar underneath, then the content area and finally the footer.

bumper.png is a new image, since my blind table is 1024px and each bumper is 512px wide, this one has a width of 2048px. In the left 512 horizontal pixels, it has the left bumper, then 1024 transparent pixels to be overwritten by the blind table, and the last 512px are the right bumper.

My blind table uses the style
Code: AGS
margin:auto; padding:0; border-spacing:0;


This works in the sense that I have the background image for the HTML body set to the tiled starfield, then I get the bumpers (from the div's background image) drawn and blended over that nicely using an alpha channel, and in the middle I have my table centered.

The problem is the div itself isn't centered. I tried with the HTML center tag as well as with adding a
Code: AGS
margin:auto;
style, but this only, apparently, centers the contents of the div. The problem is that, when I view this site with the aforementioned dimensions in 1920x1080 screen resolution, I get a scrollbar at the bottom which is all the way left. Accordingly, I see ALL 512 horizontal pixels of the left bumper, then the table, which is offset a bit to the right and not centered 100% and then a little bit of the right bumper! I still need to have the left and right bumpers cut off so that I always have my table in the center, even when resizing the window.

Is that doable? Thanks again for your continued help, this is a lot better already!


Khris

The trick is to put the bumpers inside the main div, then use "position:absolute;" to align them with the edges.
To get rid of the horizontal scrollbar, use "overflow-x: hidden;" for the body tag.

What I do is use 1000px as the width of the main div so there's some space left for the scrollbar. Also, setting the html tag's min-height to 101% prevents the contents from jumping horizontally when you switch from a tall page to one without scrollbar or vice-versa.

Here's a full template: http://khris.agser.me/dkh/
html: http://pastebin.com/ZV16Ux7E
css: http://pastebin.com/TUPLfjCy

Anian

#6
Hold on, I didn't even calculate this before, you're making a 2048px wide page? you do realise the fatal flaw is that you said that there is something 2048px big on a 1920px wide screen?  :shocked:
This is far too wide. And I mean this in a way that most people will look at this page on about 1920px and smaller, thus a lot of the image will be lost.

The scroll appears probably because you entered the width of the div, that makes the browser forced to make the site that wide, thus have to scroll. The background image doesn't make a scroll bar and won't stretch the div or other containers.

EDIT: well Khris made far more effort than I did, and this is basically what you should do, just use div-s instead of tables, it'll make things easier if that is the effect you want to make, you can postion them anywhere you want.
And even here, Khris, made the page narrower than 2048px, you should keep it 1920px and smaller.

I don't want the world, I just want your half

Khris

As far as I understood the 2048px, that's the total width of bumper images + main contents (512 + 1024 + 512).
Thus on a 1680 wide monitor, which is becoming more and more common, more than 300 pixels of both bumper images can be seen.
They just frame the page and their weight is probably next to the center div, they don't have to be seen in their entirety.

DoorKnobHandle

Khris hit the nail on the head! Thanks a ton for your effort, too!

This is absolutely perfect except that, while the horizontal scrollbar is indeed hidden, I can still use the middle mouse button to move around the full 2048px width of the two bumpers plus the 1024px content area! The browser also still starts "on the left", not centered (ie. I still start out seeing all 512 horizontal pixels of the left bumper and only a bit of the right bumper).

Does that make sense? Can this be resolved somehow as well?

This is what I have so far:

HTML
Code: "AGS"

<html>

<head>

<title>This is the title!</title>

<meta http-equiv="Content-Language" content="EN-US">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" type="text/css" href="style.css" />
<link href="http://fonts.googleapis.com/css?family=PT+Sans+Caption" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="main">

	<div id="left_bumper" class="bumper"></div>
	<div id="right_bumper" class="bumper"></div>

	<div id="header">
		<img src="images/logo.png">
	</div>

	<div id="navbar">
		<img src="images/navbar.png">
	</div>

	<div id="content">
		Content
	</div>

	<div id="footer">
	    Footer
	</div>

</div>

</body>

</html>



CSS
Code: "AGS"

body
{
	background-image: url("images/background_small.png");
	margin: 0;
	padding: 0;
	font-family: "PT Sans Caption";
	font-size: 12pt;
	color: #fff;
	overflow-x: hidden;
}
     
#main
{
	margin: auto;
	text-align: center;
	width: 1024px;
	position: relative;
}
     
.bumper
{
	position: absolute;
	overflow: hidden;
}
     
#left_bumper
{
	background-image: url("images/left_bumper.png");
	left: -512px;
	width: 512px;
	height: 1024px;
}
     
#right_bumper
{
	background-image: url("images/right_bumper.png");
	right: -512px;
	width: 512px;
	height: 1024px;
}
     
#header, #navbar, #footer
{
	text-align: center;
	padding: 0px;
	margin: 0px;
}
     
#content
{
	background-color: #111;
	min-height: 300px;
}

#footer
{
	background-color: #222;
	font-size: 8pt;
}

Khris

That's weird, Firefox centers it just fine, from the start. I didn't test it in other browsers though.

Here's an amended version:
Code: c
	<body>
		<div id='ships'>
			<div id='main'>
				<div id='header'>header</div>
				<div id='navbar'>navbar</div>
				<div id='content'>content</div>
				<div id='footer'>footer</div>
			</div>
		</div>
	</body>


Code: css

#ships {
	background-image: url('images/ships.png');
	background-position: center top;
	background-repeat: no-repeat;
	margin: 0;
	padding: 0;
	min-height: 422px;
}


ships.png is a 2048px wide picture with the two ships at the outer edges.
The body's "overflow-x: hidden;" is thus no longer needed.

I've updated http://khris.agser.me/dkh/

DoorKnobHandle

#10
That is weird, I am running Firefox as well and your (old) page is centered but it is also smaller than 1080px horizontally, if I understand you correctly. Mine was larger than 1080px and was not centered anymore.

This new approach, however, works fine in Firefox. Thanks so much! In Internet Explorer 9, however, the blind table isn't centered but instead all the way left... I have zero experience in making websites browser-compatible, any idea what could be causing this to happen?

EDIT: Found a solution, centering a DIV in IE needs special treatment... margin:auto doesn't work in IE, so the body needed a text-align:center

Khris

Yeah, IE always requires additional work.

While this isn't really helpful, what I do is redirect IE users to a page that recommends downloading an actual browser.

DoorKnobHandle

Haha yeah, I can see why you'd do that! :)

Thanks again, this works very nicely!

SMF spam blocked by CleanTalk