What steps can be taken to limit the impact of CSS frameworks such as tailwindcss and bootstrap on the HTML content of wysiwyg editors such as Tinymce and Ckeditor?

When working with a TinyMCE editor, I have noticed that the output includes proper HTML tags such as h1, h2, b, ul, ol, li. However, when trying to display this output using TailWindCSS or Bootstrap on my own frontend, all the styles for each HTML tag appear very basic with uniform size, margin, and padding like regular text elements.

I have learned that these CSS frameworks utilize something similar to "normalize-css" to achieve this consistent look. But how can I preserve the unique CSS styles from TinyMCE in my frontend while still using Tailwind and/or BootstrapCSS?

Answer №1

I utilize the @layer feature in tailwindcss to establish a base style, as shown below:

// tailwind.scss
@tailwind base;

@layer base {
  // custom revert css styles here
  .no-tailwindcss-base {

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      font-size: revert;
      font-weight: revert;
    }

    ol,
    ul {
      list-style: revert;
      margin: revert;
      padding: revert;
    }
  }
}

@tailwind components;
@tailwind utilities;

After defining the className, you can apply it to your HTML element like this:

<div class="no-tailwindcss-base" />

Answer №2

It seems that my approach aligns closely with Zhongxu's response regarding the @layer directive. However, as I am not well-versed in this directive, the solution provided did not quite work for me. Thus, I have devised my own CSS styles to unravel the issue, though credit is due to Zhongxu:

@tailwind base;

@layer base {

    .no-tailwindcss-base h1,
    .no-tailwindcss-base h2,
    .no-tailwindcss-base h3,
    .no-tailwindcss-base h4,
    .no-tailwindcss-base h5,
    .no-tailwindcss-base h6 {
        font-size: revert;
        font-weight: revert;
    }

    .no-tailwindcss-base ol,
    .no-tailwindcss-base ul {
        list-style: revert;
        margin: revert;
        padding: revert;
    }
}

@tailwind components;
@tailwind utilities;
<div class="no-tailwindcss-base">
   <!-- Other elements here-->
</div>

Answer №3

Here is a small tweak to @TheFaultInOurStars' solution, streamlining the code and applying no-tailwindcss-base to all child elements.

@layer base {
    .no-tailwindcss-base, .no-tailwindcss-base * , .no-tailwindcss-base > * {
        font-size: revert;
        font-weight: revert;
        margin: revert;
        display: revert;
        vertical-align: revert;
        max-width: revert;
        height: revert;
        border-width: revert;
        border-style: revert;
        border-color: revert;
        outline: revert;
        list-style: revert;
        padding: revert;
    }
}

Answer №4

Tailwind Preflight is the culprit here. This feature removes all margins, paddings, and any base styles that are set.

@tailwind base; /* Preflight will inject its styles here */

@tailwind components;

@tailwind utilities;

If you wish to disable it

// tailwind.config.js
module.exports = {
  corePlugins: {
   preflight: false,
  }
}

Once Preflight is disabled, html tags like h1, h2, b, ul, ol, li will be displayed properly.

Answer №5

Using the "unreset" method suggested by swyx proved to be effective for me (https://gist.github.com/sw-yx/28c25962485101ca291ec1947b9d0b3e)

  1. Include the unreset class in your CSS or let it be generated by a build tool
  2. Wrap the TinyMCE-generated HTML within a div and apply the unreset class
<div class="unreset">
    {!! $tinyMCEhtmloutput !!}
</div>

Answer №6

After facing the same issue, I managed to discover a solution that perfectly suits my needs. Utilizing tailwind css alongside the django summernote editor (compatible with any editor), I made a simple tweak in my HTML template file by adding only disc bullets for unordered lists:

<style> ul{   list-style-type: disc; } </style>

While this approach may not be ideal for those looking to display numbered lists or roman numerals, it served my purpose effectively without having to dive into complex root files or configuration setups. Sometimes simplicity trumps all. Cheers!

Answer №7

When working with tailwindcss, you have the option of utilizing the typography-plugin. To make use of this feature, simply incorporate the prose class like so:

<article class="prose lg:prose-xl">
  <h1>The benefits of drinking green tea daily</h1>
  <!-- ... -->
</article>

Answer №8

// Trying to make this work, fingers crossed... @tailwind base;

@layer base {

no-tailwindcss-base{

h1,
h2,
h3,
h4,
h5,
h6`enter code here`{
  list-style: revert;
  margin: revert;
  padding: revert;
}

} }

@tailwind components; @tailwind utilities;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The content does not fill the entire page's height

I am facing an issue with a linear-gradient background image that does not extend to cover the entire content height. I have experimented with different solutions like using min-height: 100% and adjusting the positioning of the html and about-body divs, b ...

Creating a for loop using jQuery to append the value of [i] to the string "id" for the element

As a newcomer to programming, my code may not be the best. I am attempting to automate game results (1 / X / 2) based on the input of home and away goals in a form. To achieve this, I need assistance with my jQuery for loop. Here is the current code: for ...

Exploring reviews with an innovative combination of Node.js and MongoDB

Recently diving into the world of Nodejs and mongoDB, I am excited to create two distinctive pages: one for users to update their account details such as profile picture, email, and name - all of which would be saved into the database; and another for re ...

Encountering issues with certain Bootstrap components while integrating with ReactJS

I'm currently experimenting with Bootstrap components such as Modals and Popovers, but I'm facing an issue where nothing is being displayed. Specifically, when I attempt to click on the button to show the modal Fading or popover, nothing happens. ...

Choose the OK button on the modal during the testing phase

I am having difficulty selecting an element on my webpage using testcafe because I am not very familiar with selectors. I am open to choosing it in the JSX or HTML, but I am struggling with both methods. Once I click the "LayerAddingPopUpButton", a modal a ...

Submitting a form and then redirecting to a PHP page

I have a dynamic form and I am currently using jQuery to submit it. Here is the code I have been using: $('#formsite').on('submit', function (e) { //prevent the default submithandling e.preventDefault(); //send the data of ' ...

Is there a way to use Jquery to determine if a parent div contains a scroll

I'm trying to find a jQuery example that checks if any parent div has a scroll bar, but I can't seem to locate a helpful one. Here is the code snippet I am working with: <div> <div class="heading"> <div class="visit ...

Issue with Bootstrap dropdown functionality when used within a Horizontal description block

I'm struggling to get a dropdown menu to work properly within a horizontal description. The dropdown menu just won't toggle when clicked. <div class="container-fluid"> <div class="row vertical-align"> <dl class="dl-horizonta ...

PHP echo statement does not contain Div, yet Div renders properly when placed outside the echo statement

I am facing an issue where my photos are not displaying as expected. The photos div shows up perfectly fine when placed outside the echo statement, but for some reason, it does not render when echoed. The structure of my divs is organized like this: userp ...

Troubleshooting Error in Converting a JSX File with Tailwind CSS and Typescript

I found a code example on the Tailwind website. However, when I changed the file extension to .tsx, I encountered an error related to the className attribute. Do I need to specify a type for the className variable? What steps should I take to resolve thi ...

PHP code for turning an email address into a clickable link

While I was able to discover how to convert a URL into a clickable link using PHP here, I am now curious if anyone has a solution for the same functionality but with an email address. Any help would be appreciated! Thank you! ...

Is it possible to incorporate varied icon images for every item in an unordered list?

While I'm not an CSS expert, I do have a decent understanding of it. My current project involves creating an unordered list with unique icons for each item, along with changing the background color upon hover. I wonder if there's a way to achiev ...

What can be done to prevent the aspect ratio from being altered?

I am working on creating a parallax effect using a background image that is set to a width of 100% and a height of 700px. I have set the image to have a fixed attachment, but the problem arises when I change the size of the browser window - the picture los ...

"Enhance your website's user experience with the ability to zoom in and out

One issue I encountered on my website was that when I included an iframe, the map would zoom in and out while scrolling. To try to fix this, I set pointer-events to none. However, this caused all actions on the map to be disabled, making it impossible to n ...

Alignment of text varies between canvas and HTML

How can I ensure that the labels in both canvas and HTML display overlap exactly, regardless of font family and size? The current code fails to center text inside an area when switching between canvas and HTML view. let canvas = document.getElementById( ...

Tips for transferring a codepen.io example to a .vue file

A codepen.io example (https://codepen.io/srees/pen/pgVLbm) has caught my attention, and I would like to experiment with it within the framework of a .vue application I'm currently developing. However, I'm facing some difficulties transferring the ...

Is it a CSS or Javascript quirk when a div can become the child of the div before it?

On every browser I've checked, the code in the html is exactly the same: <td class="bardisplay"> <div class="bar hot" /> <div class="bar cool" /> </td> However, in the debugger of each browser, including Chrome, the DOM ...

Adding LocalStorage functionality to buttons in order to switch colors can be done by storing the

I've run into an issue trying to incorporate LocalStorage with the buttons that change colors as themes in JavaScript. I'm new to coding and eager to add this feature to my personal blog. $(document).ready(function () { $(".header--theme-button ...

Unable to Implement Background Gradient Using Tailwind CSS Classes in React Component

<article onClick={handleNavDetail} className={`bg-${pokemonStack?.types[0].type.name} p-3`} > tailwindcss: 3.4.3, TypeScript: Version 5.3.3, React: 18.2.0, While working on a React component that showcases Pokémon details with Tailwind CSS ...

The video keeps shifting out of the second column in the row within the bootstrap layout

I'm having trouble positioning a video within a row on my webpage. I want the video to display as the second column in the row, aligning to the right of the page. However, it keeps appearing below the first column as if it's in a separate row. H ...