search
HomeBackend DevelopmentPHP TutorialHow to change the text size of web pages using PHP and CSS_PHP Tutorial

How to change the text size of web pages using PHP and CSS_PHP Tutorial

Jul 13, 2016 pm 05:33 PM
cssphpmainstreamuseandsizehowdevelopChangeletternowuseWeb pagelanguage

  用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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508665.htmlTechArticleUse php (as the current mainstream development language) and CSS to change the text size of the web page - when designing the website , one thing to keep in mind: not all visitors are bright young people,...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment