Home > Web Front-end > CSS Tutorial > Can HTML Documents or Fragments be Displayed in CSS Content?

Can HTML Documents or Fragments be Displayed in CSS Content?

Mary-Kate Olsen
Release: 2024-10-23 22:33:30
Original
379 people have browsed it

Can HTML Documents or Fragments be Displayed in CSS Content?

Is it possible to display an .html document , or .html fragment at CSS content?

Question:

It is possible to display an image at the CSS content property of HTML element at url() value of content?

<code class="css">.content {
  content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAScAAADBCAYAAACNMHZqAAAABHNCSVQICAgIfAhkiAAAApJJREFUeJzt1DEBwCAQwMCnynEOBrqT4U5BpqzZcwYg5nsdAPDHnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUi6PDoDAbyCsn8AAAAASUVORK5CYII=);
}</code>
Copy after login
<code class="html"><div class="content"></div></code>
Copy after login
Copy after login
Copy after login

Or using content property at a pseudo element, for example ::before

<code class="css">.content::before {
  content: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAScAAADBCAYAAACNMHZqAAAABHNCSVQICAgIfAhkiAAAApJJREFUeJzt1DEBwCAQwMCnynEOBrqT4U5BpqzZcwYg5nsdAPDHnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUgyJyDJnIAkcwKSzAlIMicgyZyAJHMCkswJSDInIMmcgCRzApLMCUi6PDoDAbyCsn8AAAAASUVORK5CYII=);
}</code>
Copy after login
<code class="html"><div class="content"></div></code>
Copy after login
Copy after login
Copy after login

Is it possible to render an .html document ,.html element at CSS content ?

<code class="css">.content {
  content: url(data:text/html,abc);
}</code>
Copy after login
<code class="html"><div class="content"></div></code>
Copy after login
Copy after login
Copy after login

References:

  • [CSS Generated Content Module Level 3](https://www.w3.org/TR/css-content-3/)

Update:

The furthest have been able to reach, here, to embedding and displaying HTML document in CSS generated content; using approach demonstrated by @LGSon. Included CSS generated content within HTML at SVG as well.

As noted by @RokoC.Buljan, the MIME type is not "text/html".

<code class="css">content {</code>
Copy after login

The above is the detailed content of Can HTML Documents or Fragments be Displayed in CSS Content?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template