tijsverkoyen/css-to-inline-styles
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
symfony/css-selector | v6.4.0 | - | MIT | prod |
The tijsverkoyen/css-to-inline-styles package is a powerful tool that helps in converting HTML pages or files into corresponding HTML versions with inline styles. This can be profoundly useful, particularly when you are formulating and sending out HTML-based emails. Incorporating inline styles can enhance the compatibility of your emails across a diverse range of email clients, ensuring that your design and layout remains consistent in deployment.
Using the tijsverkoyen/css-to-inline-styles package is straightforward, requiring minimal setup. To begin with, you need to have Composer installed as the package is readily available there. You can get the package using the command:
$ composer require tijsverkoyen/css-to-inline-styles
To convert an HTML file with a CSS file, an instance of CssToInlineStyles class needs to be created and the convert function can then be invoked on this instance with the HTML and CSS contents as parameters.
Here is a simple example demonstrating this:
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
// create an instance
$cssToInlineStyles = new CssToInlineStyles();
$html = file_get_contents(__DIR__ . '/examples/sumo/index.htm');
$css = file_get_contents(__DIR__ . '/examples/sumo/style.css');
// convert and output
echo $cssToInlineStyles->convert(
$html,
$css
);
In this sample code, file_get_contents
function is used to read the contents of the HTML and CSS files. The convert
function is then used from the CssToInlineStyles object, to which the HTML and CSS contents are passed as parameters. The output after conversion is then printed.
The detailed documentation and various use-case examples for the tijsverkoyen/css-to-inline-styles package can be explored on its GitHub page found at https://github.com/tijsverkoyen/CssToInlineStyles. Here you will find necessary installation instructions, known issues, and practical examples to help you integrate and use the package effectively.