Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > CSS
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 11-07-2004, 04:04 PM
  #1
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
<div> Troubles (FF vs. IE)

I'm having two basic problems with divs. I know I could easily complete each task with tables, but I know divs are valid, so that's the path I've chosen.

First problem would seem simple, but I can't find the answer. How can you center a <div> without centering the content inside of it, and keeping it as an inline element?
I'm looking for any CSS attribute that can let me do this instead of having to have a div inside another div, or a span inside a div (both of which only work in Firefox) since there would be many of these divs on a page.

Second problem is keeping some "bars" filled to their assigned width. I prefer to use divs for this task, so please don't try and suggest images instead.
There are 3 divs (to begin with, at least) with a set background color, height, and width. Everything looks fine in IE, but the divs remain at their minimum in Firefox.
Anyway to keep this from happening (without using images--including spacer GIFs)?

Code:
.bar{height:15px;display:inline;font-size:12px;}
------------
<br><div class="bar" style="background-color:red;width:42px;">&nbsp;</div>
<br><div class="bar" style="background-color:blue;width:58px;">&nbsp;</div>
<br><div class="bar" style="background-color:silver;width:99px;">&nbsp;</div>
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-07-2004, 04:57 PM
  #2
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 8,391
iTrader: (0)
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
Hi there juparis,

I have to admit that I found your post rather puzzling

So I will post my reply in code and let you tell me where I have misread your questions
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>div problems</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<style type="text/css">
<!--
.bar{
     height:15px;
     float:left;
     font-size:12px;
 }
#red {
     background-color:red;
     width:42px;
 }
#blue {
     background-color:blue;
     width:58px;
 }
#silver {
     background-color:silver;
     width:99px;
 }
#center {
     clear:both;
     width:100px;
     height:20px;
     border:solid 1px #000;
     margin:auto;
  }
</style>

</head>
<body>


<div class="bar" id="red"></div>
<div class="bar" id="blue"></div>
<div class="bar" id="silver"></div>

<div id="center">centered div</div>

</body>
</html>
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-08-2004, 09:05 AM
  #3
scoutt
Mister Admin to you
 
scoutt's Avatar
 
Join Date: Jul 2001
Posts: 30,867
iTrader: (0)
scoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the rough
to center a div you have to use margins, specificly the left and right

magin-left: auto
margin-right:auto

but why would you make it inline and then want to center it? if it is inline just add text-align:center. it shouldn't make the the text inside it center as you took away the block part of it.

if that is what you meant.

to do the minimun you have to use min-height or set the height to 100%. IE will not do the min-height so you have to hack it. if you know it will never go any bigger or any smaller you have a static height.
__________________
Have a Script or Snippet you want to share?

WWW Standards: HTML 4.01, CSS2.1, CSS3, XHTML 1.0
PHP Standards: PHP Standards
scoutt is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 04:42 PM
  #4
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
Thanks for the replies! I would have replied earlier myself, but I had no access to the file for a few days... Got it back, though, and so far coot's code seems to work (for the most part).

Ok, the reason I wanted an inline, centered div (w/o centered content) was mostly for the border properties, and keeping it tight with my table. If I make it an table cell, part of the JavaScript function (another praise to coot) will not work--I don't know why but I thought this might be easier to figure out. The function toggles the visibility of the div, which didn't work with table cells in FF.
Anyway, the only problem here is that 1) The div isn't centered, and 2)display:none; seems to have no effect on it (for the toggling). The function works after you check and uncheck the checkbox. I'd like to keep it hidden at first.

The bar coding works perfectly, thanks coot! I noticed you used an XHTML doctype. I've never used that, but was wondering; do the CSS properties need to be formatted the way you showed? Or could it be left as I normally type:
#div{blah:none;border:red;something:else;}


Ok, so there's my problem, and here's the page. As an added bonus (I don't want to make you guys work too hard since this is still free), how can you change the space a <br> provides between objects? There must be a CSS attribute, but I haven't been able to find it yet. Thanks for your help so far!
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 04:47 PM
  #5
bendman
Semantic Fanatic
 
bendman's Avatar
 
Join Date: Jun 2004
Location: Washington, DC
Posts: 1,301
iTrader: (0)
bendman is on a distinguished road
br is just a return so you should be able to change the font size where the br is, and the br will change size
__________________
[twitter] [facebook]
bendman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 05:04 PM
  #6
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
It seems like a good suggestion, but I would be using a ton of these BRs, and setting a font size after each one (just to change it a few lines down again) doesn't seem too appetizing. I tried using CSS to set a font-size already, but that has no affect.
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 05:07 PM
  #7
bendman
Semantic Fanatic
 
bendman's Avatar
 
Join Date: Jun 2004
Location: Washington, DC
Posts: 1,301
iTrader: (0)
bendman is on a distinguished road
you could always put whatever's below it in a div or span and move it down relatively
__________________
[twitter] [facebook]
bendman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 06:38 PM
  #8
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 8,391
iTrader: (0)
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
Hi there juparis,

I have just read your post
and haven't had time to fully digest it
as I'm just off to get some zzzzz
but I can get your div centered for you before I depart

I see that you have named the div...div1

....but you have forgotten to change the csss rule to reflect this action
you still have it as... #center
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 06:44 PM
  #9
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 8,391
iTrader: (0)
coothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud ofcoothead has much to be proud of
....p.s.

you do NOT use <br> to space objects
you use margin

Check it out here
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 07:15 PM
  #10
scoutt
Mister Admin to you
 
scoutt's Avatar
 
Join Date: Jul 2001
Posts: 30,867
iTrader: (0)
scoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the rough
Quote:
Originally posted by juparis
It seems like a good suggestion, but I would be using a ton of these BRs, and setting a font size after each one (just to change it a few lines down again) doesn't seem too appetizing. I tried using CSS to set a font-size already, but that has no affect.
go with what coot said.

also I believe a line-break uses line-height instead.
__________________
Have a Script or Snippet you want to share?

WWW Standards: HTML 4.01, CSS2.1, CSS3, XHTML 1.0
PHP Standards: PHP Standards
scoutt is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 09:35 PM
  #11
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
Thanks coot--it seems my mistakes are ever-flowing.. I will start using margins as you said, don't worry.

Thanks scoutt for the line-height idea. I know you told me that for another tag once, but it seems my memory hasn't been it's best with school going on, hehe.

To anyone, I'm still curious about how people type up the CSS styles (hope I'm wording this right). I realize coot's way seems more organized, but takes up a lot of space while I like to keep things nice and tight (even though it really makes no difference; just a personal habit). Does it matter either way? Is one method suggested over another?
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 10:24 PM
  #12
scoutt
Mister Admin to you
 
scoutt's Avatar
 
Join Date: Jul 2001
Posts: 30,867
iTrader: (0)
scoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the roughscoutt is a jewel in the rough
it doesn't matter. for your readability mostly
__________________
Have a Script or Snippet you want to share?

WWW Standards: HTML 4.01, CSS2.1, CSS3, XHTML 1.0
PHP Standards: PHP Standards
scoutt is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 10:52 PM
  #13
bendman
Semantic Fanatic
 
bendman's Avatar
 
Join Date: Jun 2004
Location: Washington, DC
Posts: 1,301
iTrader: (0)
bendman is on a distinguished road
I'd suggest an external stylesheet with lot's of white space then you have all your style things in one spot and you can find them easy.
__________________
[twitter] [facebook]
bendman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-11-2004, 10:54 PM
  #14
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
I don't think it matters too much. I'm only using these styles for one page. Either I open up the page to edit the content and styles at the same time, or open the content, and open the styles seperately.

It all adds up to the same amount of space in the end... Had I been using this for 2+ pages, I probably would.
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-12-2004, 04:59 PM
  #15
Juparis
Sleep Deprived Lazyhawk
 
Juparis's Avatar
 
Join Date: Feb 2004
Location: In the dreams of the righteous; in the hearts of the deceitful
Posts: 2,900
iTrader: (0)
Juparis will become famous soon enoughJuparis will become famous soon enough
New Problem

Alas, my good fortune could not last forever; a new problem has arisen..

When viewed in different resolutions, the blue bar seems pushed off to the right (beside the red bar; similar to a table cell error), and the heights of the <td> varies. Does anyone know how to solve this? I figure the margin causes the blue bar to go whack, but I only used the margins because of the <td> that would compress itself... I was viewing a different computer when I noticed the change, otherwise I would have brought this up earlier...
__________________
The Original... Juparis
>Blog : DeviantArt : Pandora : Facebook > MichaelTribune.net > Inactive
|Be committed to Do what it takes to Have what you want|
Juparis is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


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



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 10:44 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.