Solution for converting to inline styles in CSS (css-inline)

Solution for converting to inline styles in CSS (css-inline)

Talk about the scene

  • Send Email
  • Embedding HTML in third-party websites
  • Copy and edit articles from other editors and publish them to We Media such as WeChat and Toutiao

In the above scenarios, the compatibility of using inline styles is much higher, and the original style can also be kept unchanged.

Solution

  • juice
  • inline-css

The functions of these two solutions are very similar to Api . Here we take juice as an example.

Install

npm i juice --save

use

import juice from 'juice'
const html = `
<div class="test"><h1>Test Juice</h1></div>
<style>
div{
    width: 90%;
    height: 500px;
}
</style>
const result = juice(html)
console.log(result)

result

<div style="width: 90%; height: 500px;">
<h1>Testing Juice</h1>
</div>

ps: Let's take a look at CSS - inline-block elements (inline-block), label display mode conversion display

Inline-block elements
There are several special tags in the inline elements - <img />, <input />, <td>, you can set their width, height and alignment attributes, some materials may call them inline block elements.

Features of inline block elements:
(1) On the same line as adjacent inline elements (inline blocks), but with a blank space between them.
(2) The default width is the width of its content.
(3) Height, line height, margins, and padding can all be controlled.

Label display mode conversion display
Block inline: display:inline ;

Inline block: display:block ;

Block and inline elements are converted to inline blocks: display: inline-block block;

Summarize

This is the end of this article about the solution to convert inline styles in CSS (css-inline). For more relevant CSS inline style content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of JavaScript's built-in Date object

>>:  The combination and difference between ENTRYPOINT and CMD in dockerfile

Recommend

How many pixels should a web page be designed in?

Many web designers are confused about the width of...

Linux C log output code template sample code

Preface This article mainly introduces the releva...

Using MySQL in Windows: Implementing Automatic Scheduled Backups

1. Write a backup script rem auther:www.yumi-info...

How to use SVG icons in WeChat applets

SVG has been widely used in recent years due to i...

Html/Css (the first must-read guide for beginners)

1. Understanding the meaning of web standards-Why...

MySQL trigger syntax and application examples

This article uses examples to illustrate the synt...

10 very good CSS skills collection and sharing

Here, clever use of CSS techniques allows you to g...

Vue3 + TypeScript Development Summary

Table of contents Vue3 + TypeScript Learning 1. E...

Detailed explanation of soft links and hard links in Linux

Table of contents 1. Basic storage of files and d...

Vue axios interceptor commonly used repeated request cancellation

introduction The previous article introduced the ...

WeChat applet implements SMS login in action

Table of contents 1. Interface effect preview 2.u...

A collection of possible problems when migrating sqlite3 to mysql

Brief description Suitable for readers: Mobile de...