


How to change the text size of web pages using PHP and CSS_PHP Tutorial
用php(做为现在的主流开发语言)和CSS改变网页文字大小——在设计网站的时候,要牢记一点:并不是所有的访问者都是神采奕奕的年轻人,而且他们也不一定完全熟悉Web浏览器的各种使用方法。
在设计网站的时候,要牢记一点:并不是所有的访问者都是神采奕奕的年轻人,而且他们也不一定完全熟悉Web浏览器的各种使用方法。聪明的设计者了解这一点,他们常常将各种特殊的可访问特性融入网站的设计中,这样,即使是年长者或是残疾人士都可以方便舒适地使用网站,而不必花费额外的力气。
文本大小调节器是最有效的可访问特性中的一个,任何网站都可能需要它,简而言之,这是一个用于改变网页文字大小的工具,通常用于将文本变大从而易于阅读,很多浏览器已经自带了这一特色,但是网络浏览器的初学者并不知道如何使用这一功能,因此,网站的设计者经常将更易于使用的按钮放在每个网页上来实现这一功能。
这篇指南将向您介绍如何使用php(做为现在的主流开发语言)和CSS在网页上添加具备这种功能的文本大小调节器,因此,赶快向您的网站添加这一可访问性,这样从年纪大于50岁的用户那里获得赞誉的积分,继续向下读,您将学会使用它的方法。
注意:这篇指南假定您已经安装了apache(Unix平台最流行的WEB服务器平台)和php(做为现在的主流开发语言)
它是如何工作的?
在写代码之前,花一些时间来理解文本大小调节器的工作方式是非常有益的。网站中的每个网页都包含一系列控制按钮,他们允许用户选择页面的文字大小:小号、中号和大号,每种字号都对应于一种CSS样式表,这些样式表保存了用于渲染网页文本大小的规则。
当用户做出选择的时候,php(做为现在的主流开发语言)将用户选定的字号存储在一个会话变量中,然后重新加载网页,该页面将从会话变量中读取选定的字号,并动态调用相应的样式表以更小的字号或更大的字号来重新渲染网页。
过程
第一步:创建网页
从创建HTML文档开始,首先完成占位符的内容,列表A是一个例子:
列表A:
Text size: small | href="resize.php(做为现在的主流开发语言)?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.
Excepteursintoccaecatcupidatat non proident, sunt in culpa qui
officiadeseruntmollitanim id estlaborum.
对页面顶部的文字超链接要特别注意,每个超链接都指向了名为resize.php(做为现在的主流开发语言)的脚本文件,并通过URL GET方法将选定的字体大小传递给它。
在您的Web服务器目录中以.php(做为现在的主流开发语言)的扩展名来保存这个文档,例如,index.php(做为现在的主流开发语言)。
第二步:创建样式表
接下来,为每种文字大小创建样式表文件:small.css, medium.css和large.css,这是small.css的文件内容:
body {
font: 10px
}
同样,可以创建medium.css和large.css,分别使用17px和25px,将这些样式表文件和上一步创建的网页保存在同一个目录中。
第三步:创建文本大小的改变机制
正如上文介绍的,网页通过查找预先定义的会话变量可以"知道"加载哪个样式表文件,会话变量是通过脚本文件resize.php(做为现在的主流开发语言)来控制的(参见列表B),该文件是在用户点击了网页顶部改变文字大小的按钮时激活的,这是resize.php(做为现在的主流开发语言)的内容:
列表B
// start session
// import selected size into session
session_start();
$_SESSION[textsize] = $_GET[s];
header("Location: " . $_SERVER[HTTP_REFERER]);
?>
This is very simple. When the user selects a new text size, resize.php (as the current mainstream development language) obtains the font size value through the GET method and stores it in session variable $_SESSION[textsize], and then redirect the browser to the originally opened page.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
