Giter Site home page Giter Site logo

daguy / prevent-text-orphans Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 36 KB

Dynamically prevent text orphans by enforcing a minimum number of words in the last line of any text block

Home Page: http://scariati.kissr.com/github/pto/

CSS 49.23% HTML 21.67% JavaScript 29.10%
html jquery text orphans jquery-plugin

prevent-text-orphans's Introduction

Prevent Text Orphans

  • By James Scariati
  • October 2015

Description

Dynamically prevent text orphans by enforcing a minimum number of words in the last line of any text block.

View Demo

Dependencies

Use

Include jQuery and the jquery.preventTextOrphans.min.js plugin in your HTML:

<head>
	<script src="lib/jquery.min.js"></script>
	<script src="lib/jquery.preventTextOrphans.min.js"></script>
</head>

Add the following class to your CSS:

.no-wrap {
	white-space: nowrap;
}

Then call preventTextOrphans() on the elements where you wish to apply it:

$("h1, h2, h3").preventTextOrphans();

Options

The following options are available:

$("h1, h2, h3").preventTextOrphans({
	minimum: 2,
	wrapperClass: "no-wrap",
	wrapperElement: "span"
});
  • minimum: The minimum number of words that must appear in the last line of the text block. Defaults to 2
  • wrapperClass: The class name to use on the HTML element that wraps the minimum number of words
  • wrapperElement: The HTML element that wraps the minimum number of words

Notes

HTML tags in the text block are preserved, but are treated as one item, regardless of how many words they contain. For example, given the following HTML:

Let Us Know What <strong>You Think</strong>

The entire <strong> tag and its contents will be treated as one "word," so applying preventTextOrphans() will result in four words in the last line of text rather than two:

Let Us Know <span class="no-wrap">What <strong>You Think</strong></span>

To be addressed in a future update...

prevent-text-orphans's People

Contributors

daguy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.