473,765 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

div width question

I have a div with a width of 40em (is em cool to use for width?). The
situation below applies even if width is auto or 80% or something.
Inside the div I am displaying some code with <pre> tags. If the code
has a very long line (wider than the div), then what's supposed to
happen? IE and Mozilla do two very different things. IE expands the
div to encompass the line (creating horizontal scrollbars in the
browser window if nec). Mozilla lets the line cross the div boundary
w/o expanding the div. Which is correct?

The real question is: how can I get the IE behavior in both browsers?
I would like the div to be say 80% of the page width normally, but
expand to fit any long lines when the content dictates. Is this
possible?

Thanks,
Chris
Jul 20 '05 #1
5 35083
Chris Stromberger <bi*********@ho tmail.com> writes:
I have a div with a width of 40em (is em cool to use for width?). The
Real world units (mm, cm, in, pt) are generally hopeless as your
browser is on the whole pretty clueless about your screen's dpi. My
laptop's 1400x1050 screen is smaller than my LCD's 1280x1024 but
Windows almost certainly has them both down as 76dpi (or something).
Go figure.

That leaves the media's `natural' units (px, and their derivatives,
em, en and ex). Years ago TeX manuals used to suggest that you use
em (the height of a capital M in the current font) for vertical line
spacing and ex (the width of a lowercase x) for horizontal line
widths. Classically, your line separation would be the order of 1em
(1.2em rings a bell) and the line width wouldn't be more than 76ex.

Of course, these days it's much more common to be dealing with images
so it's a bit harder. I'd guess that most people define overall page
widths/heights in px (because they know how big their images are)
then, if they're feeling keen, they'll set additional em or ex
dimensions for text oriented divs.
happen? IE and Mozilla do two very different things. IE expands the
div to encompass the line (creating horizontal scrollbars in the
browser window if nec). Mozilla lets the line cross the div boundary
w/o expanding the div. Which is correct?


I think this is the `overflow' property.
http://www.w3schools.com/css/css_positioning.asp is one of many
references.

Cheers,

Ian
Jul 20 '05 #2
Chris Stromberger <bi*********@ho tmail.com> writes:
I have a div with a width of 40em (is em cool to use for width?). The
em and % are the best things to use for sizing, depending on context.
px can be used in situations where something needs to match something
else with a definite pixel size, like an image.
situation below applies even if width is auto or 80% or something.
Inside the div I am displaying some code with <pre> tags. If the code
has a very long line (wider than the div), then what's supposed to
happen? IE and Mozilla do two very different things. IE expands the
div to encompass the line (creating horizontal scrollbars in the
browser window if nec). Mozilla lets the line cross the div boundary
w/o expanding the div. Which is correct?
From my reading of http://www.w3.org/TR/CSS2/visufx.html I think
Mozilla is correct.
The real question is: how can I get the IE behavior in both browsers?
I would like the div to be say 80% of the page width normally, but
expand to fit any long lines when the content dictates. Is this
possible?


div.foo {
min-width: 80%; /* IE ignores min-width. */
width: 80%;
/* But seems to treat this _as_ min-width in the event of overflow */
}

div.foo, [notinie] { /* IE now can't see this rule */
width: auto; /* Let decent browsers take up more than 80% if needed */
}

This may not do exactly what you want, since browsers may expand the
div past 80% if there's enough content, even if linewrapping the
content would keep it under 80%. If you're only keeping a <pre> in
the div, you should be fine.

That said, if you're only keeping a pre in the div, why not put the
above properties direct onto the pre?

--
Chris
Jul 20 '05 #3
On Sat, Aug 30, Chris Morris inscribed on the eternal scroll:
em and % are the best things to use for sizing, depending on context.
px can be used in situations where something needs to match something
else with a definite pixel size, like an image.


I'll grant you that some kinds of image material resize badly:
typically that would be line-art, images of text (but we shouldn't
normally do that, should we?). That would be the kind of material for
which gif or indexed PNG format is apt, and those images are best
shown at their natural pixel size.

But JPEG, on the other hand, suitable for photo-realistic-type images,
can re-size fairly well, and - depending on the circumstances - it
could be quite a reasonable idea to size such an image in em units to
match the accompanying text. A bit of testing with a few browsers in
different browsing situations would be advisable, obviously, to
develop a "feel" for what works and what's best avoided. I've done
this to some extent in the past, but I haven't done a recent browser
survey, so I won't try to give any detailed advice just now.

all the best
Jul 20 '05 #4
Alan J. Flavell wrote:
On Sat, Aug 30, Chris Morris inscribed on the eternal scroll:

I'll grant you that some kinds of image material resize badly:
typically that would be line-art, images of text (but we shouldn't
normally do that, should we?).
Unfortunately for things like headers - e.g. a banner that says
"Products and Services" in a large font, does not look as good when
rendered in a browser as it does if it was created in Photoshop and used
as an image. I'll agree that we should only even consider such notions
in "special" circumstances as there are many downsides and this should
only be done if a text alternative is available.

Furthermore, I recently came accross an interesting series of articles at:

http://www.web-graphics.com/mtarchive/000815.php

Yes, there are downsides but one has to way the pro's and con's and make
a judgement call (BTW it is interesting to note that in the last article
the JAWS downside may be a non-issue with certain (newer?) versions of
JAWS).

But JPEG, on the other hand, suitable for photo-realistic-type images,
can re-size fairly well, and - depending on the circumstances - it
could be quite a reasonable idea to size such an image in em units to
match the accompanying text.
I'm not sure that I can agree that JPEG resizes really well. Most
images will resize adequately if they are made smaller than the original
BUT even this is not always the case. Enlarging images means that the
browser has to interpolate the pixels that essentially don't exist and
unfortunately browsers do a really poor job in this area (this is
understandably so as they need to be fast and therein lies the trade off).

The best thing to do for images IMO is provide them at their exact size
unless the picture is condusive to being resized - e.g. a square black
box. But even in these cases one has to consider whether the bandwidth
savings, coupled with addtional work put on the browser (albeit
seeminlgy negligible) are truly worth it. I'd say in general not but
again it depends on the circumstances (e.g. if a single black pixel is
used to draw numerous lines on a page of different sizes then it would
be worth it to have the single black pixel and resize it as opposed to
numerous http requests for those additional line images even if each
file itself is tiny).

A bit of testing with a few browsers in
different browsing situations would be advisable, obviously, to
develop a "feel" for what works and what's best avoided. I've done
this to some extent in the past, but I haven't done a recent browser
survey, so I won't try to give any detailed advice just now.


As a rule of thumb I'd say avoid resizing any image unless you are
looking for a specialized effect or file size is an issue (but even in
the latter case choosing higher compression levels and/or applying
gaussian blurs for jpegs or choosing less colors for gifs is typically a
better option IMO especially when in many cases the perceived
degradation - on the web page - is negligible).

--Nikolaos

Jul 20 '05 #5
Thanks. Overflow looks like what I need.

On Sat, 30 Aug 2003 10:20:32 +0100, Ian Fitchet
<id*@lunanbay.L ESS-SPAM.com> wrote:
Chris Stromberger <bi*********@ho tmail.com> writes:
I have a div with a width of 40em (is em cool to use for width?). The


Real world units (mm, cm, in, pt) are generally hopeless as your
browser is on the whole pretty clueless about your screen's dpi. My
laptop's 1400x1050 screen is smaller than my LCD's 1280x1024 but
Windows almost certainly has them both down as 76dpi (or something).
Go figure.

That leaves the media's `natural' units (px, and their derivatives,
em, en and ex). Years ago TeX manuals used to suggest that you use
em (the height of a capital M in the current font) for vertical line
spacing and ex (the width of a lowercase x) for horizontal line
widths. Classically, your line separation would be the order of 1em
(1.2em rings a bell) and the line width wouldn't be more than 76ex.

Of course, these days it's much more common to be dealing with images
so it's a bit harder. I'd guess that most people define overall page
widths/heights in px (because they know how big their images are)
then, if they're feeling keen, they'll set additional em or ex
dimensions for text oriented divs.
happen? IE and Mozilla do two very different things. IE expands the
div to encompass the line (creating horizontal scrollbars in the
browser window if nec). Mozilla lets the line cross the div boundary
w/o expanding the div. Which is correct?


I think this is the `overflow' property.
http://www.w3schools.com/css/css_positioning.asp is one of many
references.

Cheers,

Ian


Jul 20 '05 #6

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

Similar topics

2
3180
by: Alex Shi | last post by:
In php, is there a way obtain the width of a charactor of a certain font? Alex -- ================================================== Cell Phone Batteries at 30-50%+ off retail prices! http://www.pocellular.com ==================================================
25
13370
by: Sune A | last post by:
Hi All! I'm having problems with www.suneworld.com The thing is that I'd like to lock the width of the page, so that it won't adjust dynamically. Any CSS people out there that can help me? Kind regards, Sune Alexandersen
3
3959
by: DaveC | last post by:
Hi.. I have a C exam in a few days.. Looking back at old exams I find a few things we have not been taught / cant remember being taught. Below is a question from last year. My question is how do you align values and define field widths in the printf function? I'm ok with the rest of the question. Thanks DaveC
9
19533
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2: How do I determine how many characters I can get on a line Question 3: How do I determine how many lines I can get on a page. Assume no margins Question 4: Does their exist some kind of refernce table that will equate a font with chars/line and...
5
3637
by: VB Programmer | last post by:
I have a simple datagrid on a webform. (I'm using VB.NET.) In the page load I get some data, set the .DataSource property of the dg, then do a .DataBind. The columns are automatically created. Question: How can I dynamically change the width's of these columns? Thanks in advance.
5
1436
by: John Smith | last post by:
Here is my HTML table formatting code. <table border="1" width="100%"> <tr width = "100%"> <td width="33%">11asdhagdshaskgashjgahjgadhjgdjshdgasjdgajdgadjhgdgahjdgadhjsgad
50
6079
by: Shadow Lynx | last post by:
Consider this simple HTML: <!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>Strict kills my widths!</title> </head> <body> <table style="width:400px; table-layout:fixed;">
28
1937
by: ryanhokanson | last post by:
I was just trying to get a list of all my reports along with their widths. I can't use the "Reports" collection because it only works on open reports. So I tried looking into the "AllReports" collection and it doesn't seem any more useful... only allows you to find out the name of each report.
4
5215
by: patrick j | last post by:
Hi First I must apologise to Mr. Dorayme for my use of his web-page as the example for my question. In order assist in making him feel better I'll mention it is an excellent article. However what I am enquiring about is how to make what he has done work in IE 6. Here is the web-page:
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9959
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
9835
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
8833
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
7379
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
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2806
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.