Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1963 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     HTML/XHTML/DHTML/CSS :

DIV size in CSS and XHTML to suit image

Thread title: DIV size in CSS and XHTML to suit image
Closed Thread    
    Thread tools Search this thread Display Modes  
03-25-2009, 11:05 PM
#1
Mochara is offline Mochara
Status: I'm new around here
Join date: Mar 2009
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

Mochara is on a distinguished road

  Old  DIV size in CSS and XHTML to suit image

Hi there. I have a website i'm creating using divs. The first div I have is a "header" div which is at the top of website and contains a registration and login toolbar. Then I have a banner div for a banner image, a main content div and a footer div all of which is contained within a container div. The problem is with the banner div, I have the background image set to the image of the banner I want to show but I want to make sure that the site does not get so small that the banner image appears outside the banner div. The image is 800px wide and 350px high. The code I have at the moment (both the index page and the CSS is as follows)

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Diary of the Dead - Home</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body class="oneColElsCtrHdr">

<div id="container">
<div id="header" align="center">
<?php
include 'header.php';
?>
</div>
  <div id="banner">
  <img src="images/layout/header.png" alt="We live no more" width="800" height="350"/>
  <!-- end #header --></div>
  <div id="mainContent">
    <h1> Main Content </h1>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at,  odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce  varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id,  libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat  feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut,  sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh.  Donec nec libero.</p>
    <h2>H2 level heading </h2>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>
    <!-- end #mainContent --></div>
  <div id="footer">
    <p>Footer</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
PHP Code:
@charset "utf-8";
body {
    
font100VerdanaArialHelveticasans-serif;
    
background-color#D6D6D6;
    
background-imageurl(images/layout/metal.jpg);
    
background-repeatrepeat;
    
margin0/* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    
padding0;
    
text-aligncenter/* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    
color#000000;
}

/* Tips for Elastic layouts 
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.oneColElsCtrHdr #container {
    
width46em;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
    
background#FFFFFF;
    
margin0 auto/* the auto margins (in conjunction with a width) center the page */
    
border1px solid #000000;
    
text-alignleft/* this overrides the text-align: center on the body element. */
}
.
oneColElsCtrHdr #header { 
    
background#FFFFFF;
}

.
oneColElsCtrHdr #header h1 {
    
margin0/* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    
padding10px 0/* using padding instead of margin will allow you to keep the element away from the edges of the div */
}

.
oneColElsCtrHdr #banner {
    
background-repeatno-repeat;
    
min-height350px;
    
min-width800px;
    
margin-top0;
    
margin-bottom0;
    
positiontop-left;
    }

.
oneColElsCtrHdr #mainContent {
    
padding0 20px/* remember that padding is the space inside the div box and margin is the space outside the div box */
    
background#FFFFFF;
    
margin0;
}
.
oneColElsCtrHdr #footer { 
    
padding0 10px/* this padding matches the left alignment of the elements in the divs that appear above it. */
    
border-top-stylesolid;
    
border-top-color#000000;
    
border-top-widththin;
    
background:#FFFFFF;

.
oneColElsCtrHdr #footer p {
    
margin0/* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
    
padding10px 0/* padding on this element will create space, just as the the margin would have, without the margin collapse issue */

However what i'm getting as a result of this is at: www.sylvanas.net/dead

How do I make sure that the site never gets smaller than 800px wide and that the banner div is always 350px high so that the picture does not overlay on top of the website. I've tried many possible solutions and none of them have worked so far.

03-25-2009, 11:55 PM
#2
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

Any reason for making it elastic? Ofcourse there would be some issues when you are basing your wrapper relative to it's parent and still want it to be fixes to a specific size...

To set a minimum width just do as you have done, min-width: 800px; on your wrapper. But i assume you know that it's completly(almost ) useless in IE right?

03-26-2009, 12:53 AM
#3
Mochara is offline Mochara
Status: I'm new around here
Join date: Mar 2009
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

Mochara is on a distinguished road

  Old

I was always taught in college that using fixed sizes when creating a website was very very bad because of varying text sizes and that you should always use an elasticated or hybird layout

Am I an idiot? =p

I realised that CSS is useless in IE (Damn microsoft) I tried a couple of things and that just happened to be the last one I had tried so it was saved in the code.

03-26-2009, 10:55 AM
#4
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

Originally Posted by Mochara View Post
I was always taught in college that using fixed sizes when creating a website was very very bad because of varying text sizes and that you should always use an elasticated or hybird layout

Am I an idiot? =p

I realised that CSS is useless in IE (Damn microsoft) I tried a couple of things and that just happened to be the last one I had tried so it was saved in the code.
Well it all depends on the purpose and you ar definitly not an idiot Problem here is you want the design to base around a header image that has a fixed size yet still want to make the whole page elastic.

What would be so wrong in having the page a fixed size and still let the font-size be relative?

I meant that you had applied min-width: to #header when it's #container you should worry about.

So in the end it's up to you in what direction you want to go because may it be having a bigger header image showing more/less depending on the font-size, setting a min-width (for almost every browser :/) and having the header image centered so you get some spacing on the sides when its bigger then the image or making #wrapper a fixed size and still use relative units for the font-size to be able to increase/decrease the text. Most modern browsers has a zoom function now anyways

03-26-2009, 11:38 AM
#5
Mochara is offline Mochara
Status: I'm new around here
Join date: Mar 2009
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

Mochara is on a distinguished road

  Old

Originally Posted by hjalmar View Post
Well it all depends on the purpose and you ar definitly not an idiot Problem here is you want the design to base around a header image that has a fixed size yet still want to make the whole page elastic.

What would be so wrong in having the page a fixed size and still let the font-size be relative?

I meant that you had applied min-width: to #header when it's #container you should worry about.

So in the end it's up to you in what direction you want to go because may it be having a bigger header image showing more/less depending on the font-size, setting a min-width (for almost every browser :/) and having the header image centered so you get some spacing on the sides when its bigger then the image or making #wrapper a fixed size and still use relative units for the font-size to be able to increase/decrease the text. Most modern browsers has a zoom function now anyways
The main problem i've been told about when making a website a fixed size is that if someone has a massive screen then you're going to have a tiny website in the middile of their screen and a load of background around it.

Is this an issue? Or should I just ignore the people with obnoxiously large screens?

03-26-2009, 02:46 PM
#6
hjalmar is offline hjalmar
Status: Senior Member
Join date: Nov 2004
Location: Sweden
Expertise:
Software:
 
Posts: 857
iTrader: 11 / 100%
 

hjalmar is an unknown quantity at this point

  Old

you aren't making a fluid site tho!!

http://www.w3schools.com/css/css_units.asp

03-26-2009, 02:56 PM
#7
Mochara is offline Mochara
Status: I'm new around here
Join date: Mar 2009
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

Mochara is on a distinguished road

  Old

Sorry =p it only just sunk in that ems don't scale with screen size..

03-27-2009, 01:04 PM
#8
xmysteriox is offline xmysteriox
Status: I'm new around here
Join date: Mar 2009
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

xmysteriox is on a distinguished road

  Old

only make fluid templates when requested / nescesary. It's a lot of work and can cause headaches ^^

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed