English 中文(简体)
How to create a function that resizes text on a page without javascript?
原标题:

Does anyone have any ideas how to create a function that resizes text on a page dynamically without the use of JavaScript? I m using CMS based on C#?

Is it possible with CSS only? if it s not possible then i want to do with javascript like this page http://demo.joomla.org/1.5/?template=beez and as a fallback want to user server side solution which this page hasn t http://demo.joomla.org/1.5/?template=beez

问题回答

Without javascript? Well, guess you will have to perform a postback onchange, then perform resize in your codebeind. Not very user friendly though.

I doubt CSS can do that.

You could create 3 links:

<a href="?size=medium">A</a> <a href="?size=large">A</a> <a href="?size=x-large">A</a>

Then on postback, use the value of the size query string attribute as a CSS font-size value. something like (pseudocode)

// aspx
<div style="font-size:<%= getsize(); %>"> ...

// code behind
getsize(){
  return Request.QueryString["size"];
}

If you are getting size from database then you can do one thing: Create a panel and put all controls in it and set size dynamically.

See following for more details:
http://asp-net-example.blogspot.com/2009/04/how-to-set-change-panel-font-size.html

I think you are misunderstanding something, you want a C# function for something that is fundamentally client side? Do you want to do it after the page has loaded or before? You can resize text on a page with CSS easily.

body{ font-size:60%; }

If you are looking for say 3 sizes (standard, large, huge) then the way I ve done this is to create the visual elements as ImageButtons or CSS ed Buttons to style them to fit the design.

You can then hold the body{font-size:1em;} outside of the CSS includes (but before it in the head section) within a Literal to honor the browser defaults by default. When the postback occurs you can adjust the literal accordingly - e.g. large would be adjusted to body{font-size:1.5em}.

litFontSize.Text = "body{font-size:1.5em;}"

You do need to check that the body font-size is being inhereted throughout though, cross browser - form text for one will need independent definiton in my experience.

What do you want to trigger the dynamic-resizing? The window being resized? Or the user pressing a button?

If you want to resize text when a user resizes the window, then no - you won t be able to do that with CSS alone, since CSS doesn t have any way of setting font sizes based on the window size. Every site I ve seen that does this does it via javascript.

If you want the trigger to be a button press, then this is pretty simple - the button sends a postback to the server, you pick up their desired size from a dropdown or from the specific button that was pressed, and then you can add some CSS into the page or add a link to a different stylesheet.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签