473,657 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

float/position: any difference between div and span?

I've been thinking about float-ing a span versus float-ing a div,
and the same for absolute positioning. When what is floated or
positioned is a short chunk of text, I don't see any _visual_
difference between the two.

What I want to do is float (or position) a revision date at the
right margin of a line that also has some text left justified. I
tried earlier to do this and failed utterly in MSIE 4. But I was
using span not div, and having recently come across
http://www.blooberry.com/indexdot/cs...sify/float.htm and http://www.blooberry.com/indexdot/cs...y/position.htm

I see that MSIE4 is known not to work for inline elements with these
properties.

I understand of course that something containing other blocks needs
to be a div, but if it's just text does it matter?

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #1
12 10933
Stan Brown wrote:
I've been thinking about float-ing a span versus float-ing a div,
and the same for absolute positioning. When what is floated or
positioned is a short chunk of text, I don't see any _visual_
difference between the two.

What I want to do is float (or position) a revision date at the
right margin of a line that also has some text left justified. I
tried earlier to do this and failed utterly in MSIE 4. But I was
using span not div, and having recently come across
http://www.blooberry.com/indexdot/cs...sify/float.htm


and
http://www.blooberry.com/indexdot/cs...y/position.htm


I see that MSIE4 is known not to work for inline elements with these
properties.

I understand of course that something containing other blocks needs
to be a div, but if it's just text does it matter?


As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
....) inline.
Having said this, I know that some browsers don't protest against inline
elements being treated as if they were block elements. As you found out,
they render the content the way you want them to.

But keep in mind that it is not correct. There could come a moment in
time (ahum again) that all browsers (me dreaming here) do treat mark-up
and style as specified. This would mean you have to go thrue all your
pages to find the then malfunctioning source code.

It's up to you, I guess.

--

Groet,
Barbara

http://home.wanadoo.nl/b.de.zoete/html/vliegen.html *Zweefvliegen*?
http://home.wanadoo.nl/b.de.zoete/html/weblog.html *Dagboek*

Jul 20 '05 #2
Stan Brown wrote:
I've been thinking about float-ing a span versus float-ing a div,
and the same for absolute positioning. When what is floated or
positioned is a short chunk of text, I don't see any _visual_
difference between the two.

What I want to do is float (or position) a revision date at the
right margin of a line that also has some text left justified. I
tried earlier to do this and failed utterly in MSIE 4. But I was
using span not div, and having recently come across
http://www.blooberry.com/indexdot/cs...sify/float.htm


and
http://www.blooberry.com/indexdot/cs...y/position.htm


I see that MSIE4 is known not to work for inline elements with these
properties.

I understand of course that something containing other blocks needs
to be a div, but if it's just text does it matter?


As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
....) inline.
Having said this, I know that some browsers don't protest against inline
elements being treated as if they were block elements. As you found out,
they render the content the way you want them to.

But keep in mind that it is not correct. There could come a moment in
time (ahum again) that all browsers (me dreaming here) do treat mark-up
and style as specified. This would mean you have to go thrue all your
pages to find the then malfunctioning source code.

It's up to you, I guess.

--

Groet,
Barbara

http://home.wanadoo.nl/b.de.zoete/html/vliegen.html *Zweefvliegen*?
http://home.wanadoo.nl/b.de.zoete/html/weblog.html *Dagboek*

Jul 20 '05 #3
Barbara de Zoete wrote:

As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
...) inline.


There is nothing inherently wrong about treating inline elements as
block elements, or the reverse. If it really were a bad idea, the
"display" property might not even exist.

What one shouldn't do is _markup_ an element as inline (span) when it
should have been block (div) in the first place. ;)

--
To email a reply, remove (dash)ns(dash). Mail sent to the ns
address is automatically deleted and will not be read.

Jul 20 '05 #4
Barbara de Zoete wrote:

As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
...) inline.


There is nothing inherently wrong about treating inline elements as
block elements, or the reverse. If it really were a bad idea, the
"display" property might not even exist.

What one shouldn't do is _markup_ an element as inline (span) when it
should have been block (div) in the first place. ;)

--
To email a reply, remove (dash)ns(dash). Mail sent to the ns
address is automatically deleted and will not be read.

Jul 20 '05 #5
kchayka wrote:
Barbara de Zoete wrote:
As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
...) inline.

There is nothing inherently wrong about treating inline elements as
block elements, or the reverse. If it really were a bad idea, the
"display" property might not even exist.

What one shouldn't do is _markup_ an element as inline (span) when it
should have been block (div) in the first place. ;)


Okay, you've got me confused and therefore you've got my attention.
One can give both <div> and <span> a display:block; ?
But when it comes to that the <span> should be a <div>?

Is this what you mean? Or do I get it all wrong now?

--

Groet,
Barbara

http://home.wanadoo.nl/b.de.zoete/html/vliegen.html *Zweefvliegen*?
http://home.wanadoo.nl/b.de.zoete/html/weblog.html *Dagboek*

Jul 20 '05 #6
kchayka wrote:
Barbara de Zoete wrote:
As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
...) inline.

There is nothing inherently wrong about treating inline elements as
block elements, or the reverse. If it really were a bad idea, the
"display" property might not even exist.

What one shouldn't do is _markup_ an element as inline (span) when it
should have been block (div) in the first place. ;)


Okay, you've got me confused and therefore you've got my attention.
One can give both <div> and <span> a display:block; ?
But when it comes to that the <span> should be a <div>?

Is this what you mean? Or do I get it all wrong now?

--

Groet,
Barbara

http://home.wanadoo.nl/b.de.zoete/html/vliegen.html *Zweefvliegen*?
http://home.wanadoo.nl/b.de.zoete/html/weblog.html *Dagboek*

Jul 20 '05 #7
In article <kr************ *************** **@news1.news.x s4all.nl> in
comp.infosystem s.www.authoring.stylesheets, Kris
<kr*******@xs4a ll.netherlands> wrote:
In article <MP************ ************@ne ws.odyssey.net> ,
Stan Brown <th************ @fastmail.fm> wrote: [When floating a revision date right, does it make any difference
whether it's wrapped in span or div?]
There isn't. Because both get set to behave like block-level elements
automaticall y when you float them. The only override that works from
then on is display: none; which will effectively remove the element from
appearance.
Makes sense; thanks.
You may or may have not found already that IE4 does very little right in
the CSS department. Better to treat it as Netscape4.x and pals.
Well, yes. As I think I said, I struggled for a whole afternoon (and
asked for help here), without success -- because I was using span.
The references I cited earlier lead me to suspect that div might
actually work. Before I tried more experiments I wanted to ask
whether there was anything wrong with using div.
Use <span class="date"></span>, is what I suggest.


Okay, but why do you suggest span over div? What's the advantage of
span (or the disadvantage of div) in this situation? That's what I'm
trying to understand.

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
2.1 changes: http://www.w3.org/TR/CSS21/changes.html
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #8
kchayka wrote:
Barbara de Zoete wrote:
kchayka wrote:
Barbara de Zoete wrote:
As far as I know <div> is a block element and <span> is an inline
element. One shouldn't float inline elements, for they should be (ahum
...) inline.

There is nothing inherently wrong about treating inline elements as
block elements, or the reverse. If it really were a bad idea, the
"display" property might not even exist.

What one shouldn't do is _markup_ an element as inline (span) when it
should have been block (div) in the first place. ;)


Okay, you've got me confused and therefore you've got my attention.
One can give both <div> and <span> a display:block; ?


<div> is a block element by default, so it is display:block by default.
Same for other block elements p, hx, ul, li...

<span> is an inline element so it defaults to display:inline.
Ditto img, a, strong, em...

You can make pretty much any inline element a block element simply by
setting display:block. I do it all the time with images and anchors.
For example: a {display:block}
Likewise, you can change a block element to inline. However, I'm
assuming that if you do either, there is some specific reason for it and
other related properties will also be set, like maybe float.
But when it comes to that the <span> should be a <div>?


I can't tell without seeing the markup, but consider the element in
context. An inline element cannot contain a block element, so if the
<span> contains elements like paragraphs or lists, then it really should
be a <div> instead. If the span contains only other inline elements or
text and is contained in some block element, then it really is a span.

Mark up the HTML correctly according to the context, then change the
element properties with CSS. That's what it's for. :)
Is this what you mean? Or do I get it all wrong now?


I'm not sure. What do you think now?


Thank you for this very clear explanation. I think I get the point. I
checked my source and somehow (without really understanding it before) I
seem to have used divs and span in the way you just explained. Intuition
perhaps or an earlier understanding that got lost when learning more and
more and things getting more and more complicated.

Thanks.

--

Groet,
Barbara

http://home.wanadoo.nl/b.de.zoete/html/vliegen.html *Zweefvliegen*?
http://home.wanadoo.nl/b.de.zoete/html/weblog.html *Dagboek*

Jul 20 '05 #9
In article <MP************ ************@ne ws.odyssey.net> ,
Stan Brown <th************ @fastmail.fm> wrote:
Use <span class="date"></span>, is what I suggest.


Okay, but why do you suggest span over div? What's the advantage of
span (or the disadvantage of div) in this situation? That's what I'm
trying to understand.


It gets explained more better than I could right now, in replies of
other people to this thread.

--
Kris
kr*******@xs4al l.netherlands (nl)
"We called him Tortoise because he taught us" said the Mock Turtle.
Jul 20 '05 #10

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

Similar topics

1
2624
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML: **************************************************************
2
2303
by: Rainer Birkenmaier | last post by:
Hi Folks, I have 2 little problems: 1) http://birkenmaier.org/b.php IE 6.0 does something weired here: in the red box the first lines of text have a slight indet (2 or 3 pixels only). This seems to be triggered by the floating box on the left (yellow), since only the text lines that span the height of the floating box are affected. 2) http://birkenmaier.org/c.php
6
2805
by: TJ | last post by:
I've got a calendar that is based on the concept of lots of blocks that are spans with float:left. I would like to be able to have a detail section on the right side of the screen, so that when the user selects an item on the calendar, the detail can get displayed on the right side there. What I have below appears to look perfect in mozilla based browsers - the detail is aligned at the top right corner of the calendar, but in IE the...
3
19409
by: Michael Shell | last post by:
Greetings, I've been playing with CSS inline floats of <span> elements and the results are not quite what I would expect. In the example attached at the end of this post, I would expect the floated span 2 to be on the same line as span 1, but instead it is on the same line as span 3, which is on the line below span 1. Eric Meyer's CSS pocket reference gives a clue as to why this is so: "A floated element will generate a block-level box...
16
2612
by: Wolfgang Meier | last post by:
Hi, Although it might seem like I am firing out random posts in quick succession this matter is indeed one I thought about for quite some time without coming to a conclusion: Why is it that most professional CSS authors prefer /float/ing elements over elements held in place by /position/? Given, for example, the following layout...
0
2045
by: jonipony | last post by:
HELP: Float Left box is drifting to the right in ie! -------------------------- I need som HELP with my CSS coding! On the following web page my design falls apart at screen size 800 x 600 (looks fine at larger screen sizes) when the left menu box that should float left is drifting to the right in Internet Explorer 6.0 (it doesn't drift to the right in Netscape 7.1).
5
4914
by: Oliver Block | last post by:
Hello everybody, I wonder why a <span style="float:right">some text</span> might be displayed out of a surrounding div element. It is shifted to the next line. I thougt it is supposed to appear inside the surrounding div. There is
22
51494
by: ashkaan57 | last post by:
Hi, I am trying to put text on left and right side of the page and used: <div> <span>blah blah</span> <span style="float:right">blah blah</span> </div> The 2nd text does go to the right but the next line. What am I doing wrong? TIA.
27
3859
by: GloStix | last post by:
WARNING VIDEO TAKES A WHILE TO LOAD http://screencast.com/t/BWQ6DNtsM I really don't know how to fix this other than putting another div. But I dont' exactly want to do that for every page. random div's everywhere Is there any other way? Also I'm trying to get a scaled thumbnail of the orginal picture WHILE maintaining the size of the css box.. Is that possible? Or do I have to scale it in Photoshop and make a separate image =\
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.