


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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 is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.
