473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CSS Block-level elements and line breaks

Hi

I read in several CSS tutorials that block-level elements, such as
<div& <pare rendered with an implicit line break before and
after.

I set to test this out using the following HTML:

I included comments where I would expect to see line breaks (e.g a new
line) in the rendered output.

<body>
<!-- Line break above-- >
<div id="ContainingBlock1" style="background-color:red;">

<!-- Line break above-- >
<div id="ContainingBlock2" style="background-color:blue;">

<!-- Line break above-- >
Anonymous Block 3
<!-- Line break below -->

<!-- Line break above-- >
<p id="ContainingBlock4" style="width:100px; height: 100px;
background-color:Purple; color:White;">
<!-- Line break above-- >
Anonymous Block 5
<!-- Line break above-- >
</p>
<!-- Line break below -->
</div>
<!-- Line break below -->

<!-- Line break above-- >
<p id="ContainingBlock6" style="width:100px; height: 100px; background-
color:green; color:White;">

<!-- Line break above-- >
Anonymous Block 7
<!-- Line break below -->
</p>
<!-- Line break below -->

</div>
<!-- Line break below -->
<!-- Line break above -->
<div id="ContainingBlock8" style="background-color:red;">
<!-- Line break above-- >
<div id="ContainingBlock9" style="width:100px; height: 100px;
background-color:blue;">
</div<!-- Line break below -->

<!-- Line break above-- >
<div id="ContainingBlock10" style="width:100px; height: 100px;
background-color:green;">
</div>
<!-- Line break below -->
</div>
<!-- Line break below -->
</body>
Rendering the above HTML both in IE 7 & Firefox 2.0.0.7 show only one
line break between ContainingBlock2 & ContainingBlock6 as well as
between ContainingBlock1 and ContainingBlock9

Can someone please explain this?

Thanks,

Itai

Oct 5 '07 #1
10 7188
Scripsit Itaichuk:
I read in several CSS tutorials that block-level elements, such as
<div& <pare rendered with an implicit line break before and
after.
You can put it that way, though I would describe it in terms of... well,
blocks.
I included comments where I would expect to see line breaks (e.g a new
line) in the rendered output.

<body>
<!-- Line break above-- >
<div id="ContainingBlock1" style="background-color:red;">
How can you a break something that does not exist? There is nothing before
the <divtag that should generate a line.

Maybe you expect line break to mean an empty line? Well, it doesn't.

Besides, playing with <divelements with no real content is somewhat
artificial. Browsers might have their own, and different, ideas of how to
render <div></div>, <div</divand <div>&nbsp;</div>. Why would you use
them?

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Oct 5 '07 #2
<body>
<!-- Line break above-- >
<div id="ContainingBlock1" style="background-color:red;">

How can you a break something that does not exist? There is nothing before
the <divtag that should generate a line.
Maybe you expect line break to mean an empty line? Well, it doesn't.

how would you explain the "new lines" between ContainingBlock2 &
ContainingBlock6 as well as
between ContainingBlock1 and ContainingBlock9?
>
Besides, playing with <divelements with no real content is somewhat
artificial. Browsers might have their own, and different, ideas of how to
render <div></div>, <div</divand <div>&nbsp;</div>. Why would you use
them?
I'm referring to the 'box model' and the line breaks associated with
block elements.
if DIV/P are block elements and line breaks are part of the
definition
then I would expect that the absence of content will not break the
model?


>
--
Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/

Oct 5 '07 #3
Itaichuk wrote:
>><body>
<!-- Line break above-- >
<div id="ContainingBlock1" style="background-color:red;">
How can you a break something that does not exist? There is nothing before
the <divtag that should generate a line.
Maybe you expect line break to mean an empty line? Well, it doesn't.


how would you explain the "new lines" between ContainingBlock2 &
ContainingBlock6 as well as
between ContainingBlock1 and ContainingBlock9?
Do you mean the "margins"?
>Besides, playing with <divelements with no real content is somewhat
artificial. Browsers might have their own, and different, ideas of how to
render <div></div>, <div</divand <div>&nbsp;</div>. Why would you use
them?

I'm referring to the 'box model' and the line breaks associated with
block elements.
if DIV/P are block elements and line breaks are part of the
definition
then I would expect that the absence of content will not break the
model?
All box model means is that when one block element ends and another
begins the 2nd's content will be on another line, i.e., not inline!

<div>Block 1</div><div>Block 2</div>
"Block 2" will display below "Block 1", now if you are talking about the
extra space between, that's margins and not line breaks...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Oct 5 '07 #4
In article <sl*********************@bowser.marioworld>,
Ben C <sp******@spam.eggswrote:
In particular OP may expect that two adjacent line breaks should leave a
bigger gap than one, and so this may be what he is talking about.

But that isn't what a line break is. It just breaks a line. Even
<br><br><bris not supposed to necessarily leave any larger a gap than
just one <br(although in most browsers it does).
A line break is like an instruction to snap a butternut cookie.
Most people like to point out that - as it were - you can't snap
a non-existent cookie. But browsers are deeply humble and see
that it is showing respect for the non-existent (as we show
respect to the dead) to break (be moved by each <br>) - as a
matter of good grace and form.

I will see what I think *after* I have taken my pills.

--
dorayme
Oct 5 '07 #5
On 2007-10-06, Itaichuk <it*********@yahoo.comwrote:
Thanks for explanation!

I added the following, and things are now sorted out for me.

<style type="text/css">
*
{
margin: 0pt;
padding: 0pt;
}
</style>

I was assuming, incorrectly, that a line break implicitly generates a
new empty line.
Yes, that was it. Divs don't generally have any margin or padding or
anything by default anyway, but you had some <p>s in there, and they do.
One thing though:
>OP: You had lots of comments saying "Anonymous Block 5" etc. in places
where there aren't anonymous blocks. Of the ones you've marked (3, 5 and
7) only "Anonymous Block 3" is actually an anonymous block.

From: http://www.w3.org/TR/REC-CSS2/visuren.html#q5:

Quote -
[...]
If it is clear from the context which type of anonymous box is meant,
*both anonymous inline boxes and anonymous block boxes are simply
called anonymous boxes in this specification.*
Ah, so you mean anonymous _box_, not anonymous block!

You have probably heard that the Inuit have 57 different words for snow.
CSS unfortunately only has three words for box: "box", "block" and
occasionally "rectangle".
Oct 6 '07 #6
Ooops, sorry about that :-) ..

Can please look at this:

<div id="container" style="position: relative; top: 0px; left: 0px;
margin-left: 50px; margin-top: 50px; overflow: auto;">
<img alt="" src="1.jpg" width="100px" height="100px"
style="float: left; margin: 5px 0px 0px 5px; background-color: blue;" /
>
<div style="float: left; margin: 5px 0px 0px 5px;">
<blockquote>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
</blockquote>
</div>
</div>
IE 7 will display the blockquote right to the image while Firefox
2.0.0.7 displays it on a new line just under the image.

Do you figure what's going on?

Thanks!!

-Itai

Oct 6 '07 #7
Itaichuk wrote:
Ooops, sorry about that :-) ..

Can please look at this:

<div id="container" style="position: relative; top: 0px; left: 0px;
margin-left: 50px; margin-top: 50px; overflow: auto;">
<img alt="" src="1.jpg" width="100px" height="100px"
^^^^^^ ^^^^^
First off, html|xhtml attributes do not list units except %

http://www.w3.org/TR/html4/types.html#type-length

but in stylesheets you do!

style="float: left; margin: 5px 0px 0px 5px; background-color: blue;" />
^^
Hmm xhtml? Might be an issue.

<snip more code>
>
IE 7 will display the blockquote right to the image while Firefox
2.0.0.7 displays it on a new line just under the image.

Do you figure what's going on?
Who knows, most likely the problem is in what you are not showing. See
don't post code, post a URL to the page. All can be explained by what
else is either in or *not* in the whole page that is most likely
triggering quirks mode and constancy among browsers will most assuredly
fail.

Now don't go post a whole page of code here, make an example page
uploaded it to your server and then post the URL!
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Oct 6 '07 #8
Here is the page:

http://www.frente.org/~itai/floatq.html

Tnx

-Itai

Oct 6 '07 #9
On 2007-10-06, Itaichuk <it*********@yahoo.comwrote:
Ooops, sorry about that :-) ..

Can please look at this:
[...]
IE 7 will display the blockquote right to the image while Firefox
2.0.0.7 displays it on a new line just under the image.

Do you figure what's going on?
The blockquote is a float with auto width. That means it gets its
shrink-to-fit width, which is min(max(content minimum, available),
preferred).

Preferred width is width of the blockquote with no line breaks (very
wide in this case-- lots of x's in it). So in this case the width of the
blockquote should be equal to the max(content minimum, available).

That's basically the content width of the containing block (i.e. its
inside-padding width).

But should the width of any floats that are already there be subtracted
from this? Firefox thinks so, IE7 probably does too, Konqueror and Opera
don't.

CSS 2.1 does say, about shrink-to-fit width, "CSS 2.1 does not define
the exact algorithm." (CSS 2.1 10.3.5) So Firefox isn't exactly wrong on
this one.

So why does it look different in Firefox and IE7 for you? I suspect it's
just a difference in font size. You've got a lot of x's together making
the content minimum width quite wide in that example. Delete a few of
the x's, or put text there (i.e. with spaces every 8 or so characters)
and the blockquote will go to the side in FF too. But not in Opera or
Konqueror.

If on the other hand content minimum is greater than available in IE7
and it is putting the blockquote to the side in spite of that, then it
_is_ wrong.

Note: you need the CSS 2.1 spec for this, not CSS 2, which didn't
specify shrink-to-fit for auto-width floats. Don't believe the blurb at
the front, CSS 2.1 is what Opera, Konqueror, Firefox, Safari are all
aiming for, not CSS 2.
Oct 6 '07 #10
Here it is:

http://www.frente.org/~itai/floatq.html

just maximize the IE/Firefox window.

Regards,

Itai

Oct 6 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
18
by: Minti | last post by:
I was reading some text and I came across the following snippet switch('5') { int x = 123; case '5': printf("The value of x %d\n", x); break; }
7
by: seamoon | last post by:
Hi, I'm doing a simple compiler with C as a target language. My language uses the possibility to declare variables anywhere in a block with scope to the end of the block. As I remembered it this...
6
by: ste.paoletti | last post by:
hi, I have read that browsers support block element inside inline element but the css is not valid. Someone can tell me more about? What do you think? Thanks.
2
by: morrell | last post by:
I have a request to find out is there an easy way to solve this little poblem. ___________________ | Block 1 | | | | | | |...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
8
by: Alvin | last post by:
I'm making a very simple game in SDL, and I'm not asking for SDL help I hope - this looks like something C++ related, so I'll ask here. I have a class for a simple block, or tile, in the game,...
2
by: Bob Greschke | last post by:
This is the idea Block = pack("240s", "") Block = pack(">H", W) Block = pack(">H", X) Block = pack(">B", Y) Block = pack(">H", Z)) but, of course, Block, a str, can't be sliced. The real...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
4
by: tech | last post by:
Hi, I need to pass a block of say 320 bytes memory between some classes which do various processing on it. The app needs to be quick so i can't keep copying. The simplest way is via pointer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.