How to use PHP and CSS to change the webpage text size

Source: Internet
Author: User
Using php (as the mainstream development language) and CSS to change the size of Web pages -- when designing a website, remember that not all visitors are awesome young people, they are not necessarily familiar with the various Web browser usage methods. When designing a website, remember that not all SyntaxHighlighter. all ();

Using php (as the mainstream development language) and CSS to change the size of Web pages -- when designing a website, remember that not all visitors are awesome young people, they are not necessarily familiar with the various Web browser usage methods.

When designing a website, keep in mind that not all visitors are excited young people, and they are not necessarily completely familiar with the use of Web browsers. Smart designers understand this and often incorporate various special accessible features into the design of the website so that even elders or persons with disabilities can easily and comfortably use the website, instead of spending extra effort.

The text size regulator is one of the most effective accessible features that any website may need. In short, it is a tool used to change the text size of a webpage, this feature is usually used to increase text size so that it is easy to read. many browsers have come with this feature, but beginners of web browsers do not know how to use this feature. therefore, website designers often put easier-to-use buttons on each web page to implement this function.

This guide will show you how to use php (as the mainstream development language) and CSS to add a text size regulator with this function on the webpage. therefore, add this accessibility to your website, so that you will learn how to use it if you continue to read down from users over 50 years old.

Note: This guide assumes that you have installed apache (the most popular WEB server platform on Unix) and php (as the mainstream development language)

How does it work?

Before writing code, it is very helpful to take some time to understand how the text size regulator works. Each page on the website contains a series of control buttons that allow users to select the text size of the page: small, medium, and large. Each font size corresponds to a CSS style sheet, these style sheets save the rules used to render the webpage text size.

When a user makes a choice, php (as the current mainstream development language) stores the selected font size in a session variable, and then reloads the webpage, this page reads the selected font size from the session variable, and dynamically calls the corresponding style table to re-render the webpage with a smaller font size or larger font size.

Process

Step 1: Create a webpage

Starting from creating an HTML document, complete the placeholder content first. List A is an example:
List:

Text size: small | href = "resize. php (as the mainstream development language )? S = medium "> medium | large

Loremipsum dolor sit amet,
Consecteturadipisicingelit, sed do eiusmodtemporincididuntutlabore et dolore
Magna aliqua. Utenim
Ad minim veniam, quisnostrud exercitation ullamcolaboris nisi utaliquip ex ea
Commodoconsequat.
Duisauteirure dolor in reprehenderit in
Voluptatevelitessecillumdoloreeufugiatnullapariatur.
Deleteursintoccaecatcupidatat non proident, sunt in culpa qui
Officiadeseruntmollitanim id estlaborum.
 

Special attention should be paid to text hyperlinks on the top of the page. each hyperlink points to the name resize. php (as the mainstream development language) script file, and pass the selected font size to it through the url get method.

Save this document with the. php extension in your Web server directory (as the mainstream development language), for example, index. php (as the mainstream development language ).

Step 2: create a style sheet

Next, create a style sheet file for each text size: small.css, medium.cssand large.css. this is the content of the small.css file:

Body {
Font: 10px
}

In the same sample, you can create medium.css and large.css, respectively using 17px and 25px to save these style sheet files and the web pages created in the previous step in the same directory.

Step 3: create a mechanism for changing the text size

As described above, the webpage can find the pre-defined session variables to "know" which style table file to load, and the session variables are resize through the script file. php (as the mainstream development language) to control (see list B), this file is activated when the user clicks the button at the top of the page to change the text size, this is resize. php (as the mainstream development language) content:

List B

// Start session
// Import selected size into session
Session_start ();
$ _ SESSION [textsize] = $ _ GET [s];
Header ("Location:". $ _ SERVER [HTTP_REFERER]);
?>

This is simple. when you select a new text size, resize. php (as the mainstream development language) obtains the font size value through the GET method and stores it in the SESSION variable $ _ SESSION [textsize, then, redirect the browser to the opened page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.