首頁 > php教程 > php手册 > Prevent Widows with PHP and?JavaScript

Prevent Widows with PHP and?JavaScript

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-06 20:12:49
原創
1330 人瀏覽過

Read the full article at: Prevent Widows with PHP andJavaScript One of the small touches you can add to your website is preventing widows in your H1 - H6 tags. ?For those who arent aware, a widow (in terms of text and headings) means only

Read the full article at: Prevent Widows with PHP and JavaScript

Treehouse
Wufoo

One of the small touches you can add to your website is preventing “widows” in your H1-H6 tags. ?For those who aren’t aware, a widow (in terms of text and headings) means only one word of a title wraps to the next line — a bit of an ugly sight if you ask me. ?The way to prevent widows with just text is by adding a   between the last two words of the text instead of a regular space character. ?Here are two snippets for preventing widows in your website: ?one?using JavaScript and another using PHP!

// With JavaScript
var text = text.replace(/\s(?=[^\s]*$)/g, '?');
登入後複製
// With PHP
$text = preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1?$2', $text);
登入後複製

As I mentioned originally, widows are not necessarily a bug, but a?small visual quirk that just doesn’t look great. ?Keep these regex usages?handy so you can prevent such a smudge!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
javascript - 使用react報錯
來自於 1970-01-01 08:00:00
0
0
0
"Bootsrap-Vue Modal的hide方法無效"
來自於 1970-01-01 08:00:00
0
0
0
java - springboot新手學習
來自於 1970-01-01 08:00:00
0
0
0
spring - JavaWeb中 Service 層的事務問題
來自於 1970-01-01 08:00:00
0
0
0
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板