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

asp:label Strict Mode rendering...

Anyone figure out a workaround for setting the width on labels in 2.0??? I
know width is no longer a valid property on inline text elements (per W3C),
so what are the other options??? I have many valid uses for setting an
explicit width on a label...and no, I do not want to switch back into Quirks
mode just to get it to work.

TIA,
mike
Nov 19 '05 #1
2 1605
Okay, Michael,

I spent a good bit of time researching this, so you owe me!!! ;-)

You have to use a bit of JavaScript. Basically, you set the CSS width and
(optionally) text-align properties on the tag. Yes, I know, the width
property is not valid. However, IE will recognize it and use it. Example:

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam
vitae ante sed augue lobortis suscipit. Aenean ultricies cursus
lorem.<span class="label"
style="display:inline;width:200px;text-align:center;">Duis erat. </span>
Pellentesque venenatis vehicula diam. Donec leo massa,
pulvinar consequat, ultrices eget, ullamcorper sit amet, magna.
Vivamus sollicitudin diam et enim. Sed pede nulla, adipiscing vitae,
luctus a, pretium quis, turpis. Nunc fermentum diam eget diam.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Phasellus tempus. Morbi sit amet magna et est
commodo consectetuer. Cras blandit. Nulla faucibus condimentum eros.
</p>

Then you use a JavaScript that executes when the page loads:

<script type="text/javascript" >
var sps = document.getElementsByTagName("span");
for (var index = 0; index < sps.length; index++)
{
var sp = sps[index];
if (sp.className == "label")
{
var s = sp.style.width.substring(0, sp.style.width.indexOf("px"));
var i = (s - sp.offsetWidth) / 2;
if (sp.style.textAlign == "center")
{
sp.style.paddingLeft = i;
sp.style.paddingRight = i;
}
else if (sp.style.textAlign == "right")
sp.style.paddingLeft = i * 2;
else
sp.style.paddingRight = i * 2;
}
}
</script>

This JavaScript adds padding according to the "width" style, which, although
it doesn't get used by "correct" UAs, is still there, and readable, combined
with the "text-align" style, which is used to set the padding appropriately.
The CSS class determines which spans get the treatment.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"MichaelY" <Mi******@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Anyone figure out a workaround for setting the width on labels in 2.0???
I
know width is no longer a valid property on inline text elements (per
W3C),
so what are the other options??? I have many valid uses for setting an
explicit width on a label...and no, I do not want to switch back into
Quirks
mode just to get it to work.

TIA,
mike

Nov 19 '05 #2
I'll say I owe you....nice!!!

This will work - I pondered such a solution - except not with all styles in
a seperate CSS file....bummer. Fortunately, most of my fixed-width spans
invovle forms, so I guess I can use tables where needed.

**sigh**....still wondering if all of these CSS standards really have web
APPLICATIONS in mind, or if it is all geard towards web BROCHURES (blogs,
normal sites, etc.)....oh well - I'll keep a smile on my face, and push
onward.

**grin**

Thanks a million,
Mike

"Kevin Spencer" wrote:
Okay, Michael,

I spent a good bit of time researching this, so you owe me!!! ;-)

You have to use a bit of JavaScript. Basically, you set the CSS width and
(optionally) text-align properties on the tag. Yes, I know, the width
property is not valid. However, IE will recognize it and use it. Example:

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam
vitae ante sed augue lobortis suscipit. Aenean ultricies cursus
lorem.<span class="label"
style="display:inline;width:200px;text-align:center;">Duis erat. </span>
Pellentesque venenatis vehicula diam. Donec leo massa,
pulvinar consequat, ultrices eget, ullamcorper sit amet, magna.
Vivamus sollicitudin diam et enim. Sed pede nulla, adipiscing vitae,
luctus a, pretium quis, turpis. Nunc fermentum diam eget diam.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Phasellus tempus. Morbi sit amet magna et est
commodo consectetuer. Cras blandit. Nulla faucibus condimentum eros.
</p>

Then you use a JavaScript that executes when the page loads:

<script type="text/javascript" >
var sps = document.getElementsByTagName("span");
for (var index = 0; index < sps.length; index++)
{
var sp = sps[index];
if (sp.className == "label")
{
var s = sp.style.width.substring(0, sp.style.width.indexOf("px"));
var i = (s - sp.offsetWidth) / 2;
if (sp.style.textAlign == "center")
{
sp.style.paddingLeft = i;
sp.style.paddingRight = i;
}
else if (sp.style.textAlign == "right")
sp.style.paddingLeft = i * 2;
else
sp.style.paddingRight = i * 2;
}
}
</script>

This JavaScript adds padding according to the "width" style, which, although
it doesn't get used by "correct" UAs, is still there, and readable, combined
with the "text-align" style, which is used to set the padding appropriately.
The CSS class determines which spans get the treatment.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"MichaelY" <Mi******@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Anyone figure out a workaround for setting the width on labels in 2.0???
I
know width is no longer a valid property on inline text elements (per
W3C),
so what are the other options??? I have many valid uses for setting an
explicit width on a label...and no, I do not want to switch back into
Quirks
mode just to get it to work.

TIA,
mike


Nov 19 '05 #3

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

Similar topics

10
by: Dwizz | last post by:
Hello, I really hope that someone can help me resolve my problem, I've been working on it for the past few days, to no avail. I have an asp:label which gets its value from the database, but what...
1
by: moondaddy | last post by:
I want to use a asp Label control (or a <div runat=server> element) in a template column of a datagrid. In the code behind in the grid's ItemDataBound event I need to dynamically set the innerHTML...
3
by: Harry | last post by:
Hi, Can anyone tell me why the below code does not work. I dont get any errors, but nor does the Text for the asp:label get set. Thanks in advance as always H
2
by: Peter Rilling | last post by:
Below is some code that I do not know why it does not work. Okay, as you can see it is simple HTML with two ASP:Label controls. Each label has some code that basically gets a string that will be...
2
by: tshad | last post by:
Is there another way to put labels on a page other than asp:label? I have been building a page where I use a label to display the calculated result of some imput. I do it using Javascript. But...
1
by: nospamjac | last post by:
Hi, Is there a way to update the text of an asp:label on a webform without refreshing the entire page? What is called by button clicks and other events that refresh a webform control? See the...
3
by: Shapper | last post by:
Hello, I have an Asp:Label which CSS class is "style": ..style { border-color: #303030; border-style: solid; border-width: 1px; display: block;
4
by: Guy Noir | last post by:
So, I have a table that I only want to appear after some event has fired. Using the asp:table control and the Visible property, this is a piece of cake. The problem is that when I try and drop a...
1
by: Steve Hershoff | last post by:
I'm using VS 2003, and need to extract the text from an asp label in my code-behind file. The label is part of a DataList's ItemTemplate. I've noticed that in my ascx file (we're using User...
0
by: Dhananjay | last post by:
hi all i have a problem on populating a message on asp:label server control.I am able to insert records into the table.but it is not populating any message like "Records entered successfully"....
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
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
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
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
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...
0
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,...

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.