473,406 Members | 2,371 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,406 software developers and data experts.

DIV layout question

Hi all, quick question: if I have two adjacent elements (e.g. <IMG>
elements) without a <BR> inbetween, they will get rendered side by
side if there is space in the window, as you'd expect. However, two
adjacent <DIV> elements get rendered vertically.

I tried setting style.position = "relative" etc, doesn't seem to help.
Is there any way to make DIVs behave like "normal" elements in this
respect? Or is there another container element that will/can be made
to behave "correctly"? I think IFRAMEs will, but I don't really want
to use them.

Context - this relates to a Firefox extension I'm working on which
will replace IMGs with DIVs (or other container) in pages on the fly,
so I don't have the option of changing the layout scheme of the
original pages.

Thanks for any tips.
Feb 11 '06 #1
7 1533
Tony A. wrote:
Hi all, quick question: if I have two adjacent elements (e.g. <IMG>
elements) without a <BR> inbetween, they will get rendered side by
side if there is space in the window, as you'd expect. However, two
adjacent <DIV> elements get rendered vertically.

I tried setting style.position = "relative" etc, doesn't seem to help.
Is there any way to make DIVs behave like "normal" elements in this
respect? Or is there another container element that will/can be made
to behave "correctly"? I think IFRAMEs will, but I don't really want
to use them.

Context - this relates to a Firefox extension I'm working on which
will replace IMGs with DIVs (or other container) in pages on the fly,
so I don't have the option of changing the layout scheme of the
original pages.

Thanks for any tips.

I think you should use the <span> element instead.

Kris
Feb 11 '06 #2
krimgelas wrote:
Tony A. wrote:
Hi all, quick question: if I have two adjacent elements (e.g. <IMG>
elements) without a <BR> inbetween, they will get rendered side by
side if there is space in the window, as you'd expect. However, two
adjacent <DIV> elements get rendered vertically.
[...]
I think you should use the <span> element instead.


Thanks for the reply Kris - I tried using <span> instead, and indeed
that works as expected in Internet Explorer, but unfortunately not in
Firefox, and my code is for a Firefox extension.

I've shown the actual code I'm using below. In IE, two adjacent spans
generated this way get rendered side by side if there's space, as
expected. But in Firefox, the spans get rendered on top of each other,
as if set to absolute positioning or something (not the case,
otherwise it wouldn't work in IE). Maybe it's a Firefox bug, I should
probably post something in the Mozilla forums.

for (i=0;i<document.images.length;i++){

// create a div for the image, sized to image dimensions
var imgDiv = document.createElement("SPAN");
//imgDiv.style.position = "relative"; // makes no difference
imgDiv.style.width = document.images[i].width;
imgDiv.style.height = document.images[i].height;

document.images[i].parentNode.insertBefore(imgDiv,document.images[i]);

// move the image into it
imgDiv.appendChild(document.images[i]);
}
Feb 11 '06 #3
Actually scratch my previous reply, I tried it again with all other
code stripped out, and spans worked as expected in both browsers, so
I'm doing something wrong elsewhere. Damn I hate debugging javascript!
Thanks for the tip.
Feb 11 '06 #4
Tony A. wrote:
Hi all, quick question: if I have two adjacent elements (e.g. <IMG>
elements) without a <BR> inbetween, they will get rendered side by
side if there is space in the window, as you'd expect. However, two
adjacent <DIV> elements get rendered vertically.
Because <div> is a "block" element which will produce a new line similar
to <p>.
I tried setting style.position = "relative" etc, doesn't seem to help.
Is there any way to make DIVs behave like "normal" elements in this
respect? Or is there another container element that will/can be made
to behave "correctly"? I think IFRAMEs will, but I don't really want
to use them.


As mentioned, span will no create a new line since it is an "inline"
element.

If you apply display:inline to the <div>, it will remain on the same line.

--
Gus
Feb 11 '06 #5
Sat, 11 Feb 2006 19:30:00 GMT from Tony A. <yo******@need.to.know>:
Hi all, quick question: if I have two adjacent elements (e.g. <IMG>
elements) without a <BR> inbetween, they will get rendered side by
side if there is space in the window, as you'd expect. However, two
adjacent <DIV> elements get rendered vertically.


Well, yes. <DIV> is a block-type element, like <P>.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Feb 11 '06 #6
Sat, 11 Feb 2006 21:29:06 GMT from Tony A. <yo******@need.to.know>:
Damn I hate debugging javascript!


So don't use it -- it's a loser for you and for your visitors.

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Why We Won't Help You:
http://diveintomark.org/archives/200..._wont_help_you
Feb 11 '06 #7
Stan Brown wrote:
Well, yes. <DIV> is a block-type element, like <P>.


That's not the best way to phrase it. <div> (by general default) has a
CSS "display" value of "block", as does <p>. <span> has the value of
"inline".

The idea of "<div> is a foo-type element" is a _HTML_ view of it, not a
CSS view. The difference is that whatever "type" <div> has is
fundamental to the HTML DTD and can't be changed (it's actually
related to their membership of the %block; entity and their content
model of %flow; - in contrast <span> is inline) By contrast the CSS
display property can have its value changed easily by any stylesheet.

Why should this matter? Why is the right terminology important?
Because the "HTML type" is rigid and unchanging, but the CSS property
is flexible.
As regards <img>, then this is an "inline replaced" element and is
neither "block" not "inline". It's similar to "inline block", but even
that's not quite the full story.
http://www.w3.org/TR/CSS21/visudet.h...eplaced-height

If you want to hack with the presentation of <img>, then do it with CSS
and the display property. Avoid the position property - I doubt very
much if that's what you're really after.

Feb 13 '06 #8

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

Similar topics

82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
8
by: T. Bjarne | last post by:
I'm writing a form with a grid layout (similar to the ones in phpMyAdmin). The form will contain X number of columns and Y rows - all cells containg INPUT elements. As long as the data isn't...
3
by: John | last post by:
Hi, This is my first experiment with C#, I'm trying to handle the resize event. According to the documentation I should handle the Layout event for this. My question is: how do I register this...
4
by: NWx | last post by:
Hi, I develop an ASP.NET app which should be used from Internet, so I don't have control over what browsers will be used. I don't want to target every possible users, so I don't really mind is...
10
by: Volker Lenhardt | last post by:
For a QApplication (PyQt) on the small screen of my Zaurus 5500 PDA I try to layout my data output in a QScrollView as the central widget. I'd prefer to use QGridLayout, but cannot add it to the...
7
by: David Veeneman | last post by:
I'm just getting started with ASP.NET in Visual Studio 2005. The last web work I did involved ASP 3.0 in FrontPage. I've been through the MSDN tutorials on creating web pages, but not of them...
9
by: neoswf | last post by:
hey guys ive looked at http://news.google.com page code layout, and ive seen that the page layout is table based. the containers are tables, the hidden personalization panels are also in...
7
by: Trammel | last post by:
Im trying to do something which I hoped would be alot easier than it seems. Im trying to design the layout of the page in CSS to avoid table, etc but having problems making the bottom "fade"...
15
by: Gary Peek | last post by:
Can anyone tell us the browsers/versions that exhibit errors when tables are nested too deeply? And how many levels of nesting produces errors? (not a tables vs CSS question)
5
by: Ed Sproull [MSFT] | last post by:
First I'm pretty new to ASP.NET and I'm having a simple problem. I have small website with a header, sidebar and the the content. I want my content to appear beside my sidebar which seems to be a...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.