6 replies [Last post]
tebk77
tebk77's picture
User offline. Last seen 10 weeks 17 hours ago. Offline
rank Regular
Regular
Timezone: GMT-4
Joined: 2009-05-16
Posts: 34
Points: 37

Hi,
I'm wondering if display:block can be used in a .css style to specify BOTH width and height of a div?

I once read that it's not good to specify both height and width for a div... And then I THOUGHT I read but with display block you can specify both h & w.

thanks.

Deuce
Deuce's picture
User offline. Last seen 4 weeks 5 days ago. Offline
rank Guru
Guru
Timezone: GMT-5
Joined: 2005-11-20
Posts: 4421
Points: 1840

Setting height can be a bad

Setting height can be a bad thing, but not always... depends on the situation. A set height tends to break the fluid nature of web browsers. If a user decides to set their browser text larger than your design and you have a set width, it can easily break the design.

all ยป http://dictionary.reference.com/browse/all

Google isn't a bunch of guys reading and grading web sites, it's more like a bunch of monkeys sniffing food and putting the good bananas at the top. -Triumph

Ed Seedhouse
Ed Seedhouse's picture
User offline. Last seen 2 days 1 hour ago. Offline
rank Guru
Guru
Timezone: GMT-7
Joined: 2005-12-14
Posts: 3544
Points: 643

A DIV is display block by

A DIV is display block by default. But don't use divs to show elements that have their own meanings. Use the appropriate semantic html tag for that. Overuse of divs is one of the worst things you can do on a web page but, alas, all too frequent.

Ed Seedhouse

Posting Guidelines

High on a hill, in Wrangellia.

Tyssen
Tyssen's picture
User offline. Last seen 1 day 20 hours ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8140
Points: 1322

Ed Seedhouse wrote: A DIV is

Ed Seedhouse wrote:

A DIV is display block by default.

So are all these.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Ed Seedhouse
Ed Seedhouse's picture
User offline. Last seen 2 days 1 hour ago. Offline
rank Guru
Guru
Timezone: GMT-7
Joined: 2005-12-14
Posts: 3544
Points: 643

Tyssen wrote: Ed Seedhouse

Ed Seedhouse wrote:

A DIV is display block by default.

Tyssen wrote:

So are all these.

Yes, which is why I pointed out that overuse of DIVs is a real bad idea. Almost always you can find an element that describes the enclosed content better, and that's what you should use.

Ed Seedhouse

Posting Guidelines

High on a hill, in Wrangellia.

tebk77
tebk77's picture
User offline. Last seen 10 weeks 17 hours ago. Offline
rank Regular
Regular
Timezone: GMT-4
Joined: 2009-05-16
Posts: 34
Points: 37

I had no idea

So display:block is the same as a div. Why is it sometimes included in a

stylesheet?

I'm about ready to leave the float positioning and go back to tables! What do you think?

Ed Seedhouse
Ed Seedhouse's picture
User offline. Last seen 2 days 1 hour ago. Offline
rank Guru
Guru
Timezone: GMT-7
Joined: 2005-12-14
Posts: 3544
Points: 643

tebk77 wrote: So

tebk77 wrote:

So display:block is the same as a div.

NO it is not. DIV is defined by the W3C as being a "block" element but that can be changed in the CSS, though it seldom if ever should be.

"display:block;" is a CSS property, and has nothing directly to do with html.

tebk77 wrote:

Why is it sometimes included in a <div> stylesheet?

Because there are jillions of bad web designers putting pages up on the web?

tebk77 wrote:

I'm about ready to leave the float positioning and go back to tables! What do you think?

I think you are still "thinking tables" and that's where you're trouble mainly lies. You don't just switch from "tables to divs", that's nonsense and if someone told you to do that they were talking nonsense.

If you've been using tables for layout for awhile you can't just switch. You've picked up many bad habits that you must unlearn. The worst habit of all is using html elements for what they "look like" instead of what they mean. Write your html first in valid and semantic html and then and only then do your CSS to make the page look as you want it to look.

I suggest you put aside your knowlege of html and CSS completely for awhile and approach them afresh as if you knew nothing about them. Go to a site like HTML Dog and work through the tutorials, all of them, with a "beginner's mind".

It will save you many many fruitless hours of toil and trouble if you do. Your problem does not lie in what you do not know, it lies in what you think you know that actually isn't so.

Ed Seedhouse

Posting Guidelines

High on a hill, in Wrangellia.