voku/css-to-inline-styles

Only a Fork of -> CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

Maintainers

👁 voku

Package info

github.com/voku/CssToInlineStyles

pkg:composer/voku/css-to-inline-styles

Statistics

Installs: 261 840

Dependents: 2

Suggesters: 0

Stars: 19

Open Issues: 2

2.0.3 2020-02-23 12:51 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 64e16278545d5ce1b6197136b3fbbaf90f1f2670

  • Tijs Verkoyen <css_to_inline_styles.woop@verkoyen.eu>
  • Lars Moelleken <lars.woop@moelleken.org>

cssemailinlinestylecss-to-htmlCSSToHtmlCSSinline


README

👁 Build Status
👁 codecov.io
👁 Coverage Status
👁 Scrutinizer Code Quality
👁 Codacy Badge
👁 SensioLabsInsight
👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 PHP 7 ready
👁 License

CssToInlineStyles class

WARNING: this is only a Extended-Fork of "https://github.com/tijsverkoyen/CssToInlineStyles"

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very usefull when you're sending emails.

About

PHP CssToInlineStyles is a class to convert HTML into HTML with inline styles.

Installation

The recommended installation way is through Composer.

$ composer require voku/css-to-inline-styles

Example

use voku\CssToInlineStyles\CssToInlineStyles;

// Convert HTML + CSS to HTML with inlined CSS
$cssToInlineStyles= new CssToInlineStyles();
$cssToInlineStyles->setHTML($html);
$cssToInlineStyles->setCSS($css);
$html = $cssToInlineStyles->convert();

// Or use inline-styles blocks from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setUseInlineStylesBlock(true);
$html = $cssToInlineStyles->convert();

// Or use linked files from the HTML as CSS
$cssToInlineStyles = new CssToInlineStyles($html);
$cssToInlineStyles->setLoadCSSFromHTML(true);
$html = $cssToInlineStyles->convert(false, 0, __DIR__ . '/../tests/');

Documentation

The following properties exists and have set methods available:

Property Default Description
cleanup false Should the generated HTML be cleaned?
useInlineStylesBlock false Use inline-styles block as CSS.
stripOriginalStyleTags false Strip original style tags.
excludeMediaQueries true Exclude media queries from extra "css" and keep media queries for inline-styles blocks.
excludeConditionalInlineStylesBlock true Exclude conditional inline-style blocks.

Warning

Also if the default is cleanup === false, you maybe need to use this feature, because Outlook has some special features where the inline-CSS will be ignored and it will fallback to use only the CSS-Class- or ID-properties.

$cssToInlineStyles->setCleanup(true);

Known issues

  • no support for pseudo selectors