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

JavaScript to achieve text expansion and collapse effect

The implementation of expanding and collapsing li...

Two methods of MySql comma concatenation string query

The following two functions are used in the same ...

Drop-down menu and sliding menu design examples

I found a lot of websites that use drop-down or sl...

How to load third-party component libraries on demand in Vue3

Preface Take Element Plus as an example to config...

Basic steps to use Mysql SSH tunnel connection

Preface For security reasons, the root user of My...

Design Theory: A Method to Understand People's Hearts

<br />Once, Foyin and Mr. Dongpo were chatti...

Workerman writes the example code of mysql connection pool

First of all, you need to understand why you use ...

Where is the project location deployed by IntelliJ IDEA using Tomcat?

After IntelliJ IDEA deploys a Javaweb project usi...

A brief analysis of crontab task scheduling in Linux

1. Create a scheduling task instruction crontab -...

Summary of Linux commands commonly used in work

Use more open source tools such as docker and kub...

Introduction to TypeScript basic types

Table of contents 1. Basic types 2. Object Type 2...

The principle and basic use of Vue.use() in Vue

Table of contents Preface 1. Understanding with e...

5 ways to migrate from MySQL to ClickHouse

Data migration needs to be imported from MySQL to...