473,839 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOCTYPE Strict uses "correct" box model - so why is 100% width now useless?

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:40 0px; table-layout:fixed;">
<colgroup>
<col style="width:50 %;"/ >
<col style="width:50 %;"/ >
</colgroup>
<tr>
<td>
<input type="text" style="width:10 0%;" />
</td>
<td>
<input type="text" style="width:10 0%;" />
</td>
</tr>
</table>
</body>
</html>

Both text boxes have their right edges clipped off. Sure, the "Proper"
box model says that width is the width of the content, excluding the
padding and border (and margin, of course.) Wonderful. So now, with
all standard text boxes (and many other controls) having things like
padding and borders, what good is a percentage width?

I could (and do, for lack of a better workaround) use a slightly
smaller width, like 98%, but that has to be adjusted depending on the
width of the table and how many columns it has - smaller tables require
even more reduction in percentage width for the text boxes to fit.

I know the geniuses in the W3C think that their box model is the best,
but if you draw a box (essentially a border) and then write some text
in the middle of it with some space between the edge of the box and the
text, then ask any kid to measure the width of the box, he'll measure
from border to border, INCLUDING padding!

I know, I should stop whining and just stop using STRICT, right? Well,
I could, but that's a step backwards and there are other parts of the
strict doctype that are very appealing.

There's got to be a viable solution to this. Sure, 100% minus padding
minus border is the real answer, but since that's not possible (without
using dynamic properties) to put specify such a formula as width, how
can I solve this issue?

I FEEL LIKE I'M TAKING CRAZY PILLS!

Mar 11 '06 #1
1 1941
I explored the Dynamic Properties avenue and came up with the following
css/function combo that will do what I consider to be proper width
calculations, although it's certainly not a perfect calculation since
it doesn't take into account every scenario. It's a relatively
intensive function when used/called by many different controls on a
page.

The real point is, why the heck should I need such a thing!!?? Please,
someone tell me I wasted my time by doing this because there really IS
a much better and less complex way of accomplishing this when using
Strict!

<!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>
<style>
.Auto100 {
width: expression(auto Width('100%', this));
}
</style>
<script language="javas cript">
// relWidth should be a percentage or a pixel offset (ex. -10 or
'100%')
// TABLEs must have table-layout:fixed or this will result in
infinite recursion!
// Note: If the arguments were (obj, relWidth), this would silently
fail to execute,
// and I have no idea why - the object MUST be the last argument.
function autoWidth(relWi dth, obj) {
var defaultCellPadd ing = 1;
var cellPadding = 0;
if (obj.parentNode .tagName == "TD") {
var parentTable =
obj.parentNode. parentNode.pare ntNode.parentNo de;
cellPadding = (parentTable.ce llPadding) ?
parentTable.cel lPadding : defaultCellPadd ing;
}
var objDiff = (obj.offsetWidt h - obj.style.pixel Width) +
(cellPadding * 2);
var maxWidth = obj.parentNode. clientWidth - objDiff;
if (typeof(relWidt h) == "string" && relWidth.slice(-1) == "%") {
var pctValue = relWidth.slice( 0, -1) * .01;
newWidth = parseInt(maxWid th * pctValue, 10) + "px";
} else {
newWidth = (maxWidth + parseInt(relWid th, 10)) + "px";
}
return newWidth;
}
</script>
</head>
<body>
<table style="width:70 0px; table-layout:fixed;" cellspacing="10 "
cellpadding="3" >
<colgroup>
<col style="width:50 %;"/ >
<col style="width:50 %;"/ >
</colgroup>
<tr>
<td colspan="2">Wit h the workaround - everything fits as it
should:</td>
</tr>
<tr>
<td bgcolor="lightg reen">
<input type="text" class="Auto100" value="TextBox" />
</td>
<td bgcolor="orange ">
<select style="width:10 0%;"><option>Dr op Down
List</option></select>
<!-- SELECTs are windowed: Auto100 won't work and isn't needed
-->
</td>
</tr>
<tr>
<td bgcolor="magent a">
<textarea class="Auto100" >TextArea</textarea>
</td>
<td bgcolor="tan">
<div style="backgrou nd-color:Window; padding:5px; border:1px
solid red;" class="Auto100" >DIV</div>
</td>
</tr>
<tr>
<td colspan="2"><br >
Without the workaround (normal percentages) - everything but
SELECTs are clipped:</td>
</tr>
<tr>
<td bgcolor="lightg reen">
<input type="text" style="width:10 0%;" value="TextBox" />
</td>
<td bgcolor="orange ">
<select style="width:10 0%;"><option>Dr op Down
List</option></select>
<!-- SELECTs are windowed: Auto100 won't work and isn't needed
-->
</td>
</tr>
<tr>
<td bgcolor="magent a">
<textarea style="width:10 0%;">TextArea</textarea>
</td>
<td bgcolor="tan">
<div style="width:10 0%; background-color:Window; padding:5px;
border:1px solid red;" class="Auto100" >DIV</div>
</td>
</tr>
</table>
</body>
</html>

--- Watch out for forced newsgroup word wrapping!

Mar 11 '06 #2

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

Similar topics

4
26218
by: N. Demos | last post by:
The following code renders as intended in IE (A TABLE, with cells of fixed width and height, inside of a DIV with fixed width and height and overflow set to hidden.) In Firefox, the table cells assume a narrower with than specified. If I comment out the width for the DIV, then the cells render with the correct width and height. Why is this happening? Thanks. Regards, N. Demos
50
6097
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;">
4
1481
by: metaperl | last post by:
I work at a place which is currently running SQL 2000, but they are planning to migrate to 2k5. I was thinking that this is the perfect opportunity to fix all the weaknesses we have had in our data model for the longest: primary keys and foreign keys with different names, use of character columns for boolean fields, use of integer columns for toggles, no referential integrity, etc. So, even if I create my Utopian perfect data model and...
0
9697
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,...
0
10908
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...
0
10586
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10293
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
9426
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
7828
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
7017
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();...
1
4484
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
3
3134
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.