Y
Y
Yaroslav Nikitin2014-11-21 19:44:46
PHP
Yaroslav Nikitin, 2014-11-21 19:44:46

How to isolate styles?

Problem essence:
The user enters the HTML code into one textarea and into the second CSS.
During user input, what he writes is generated, otherwise the site.
But as a result of such machinations, if the user writes styles for the body, then they will change on my site (it cannot be otherwise).
What are the suggestions in order to isolate the styles of the site (which is being generated) from the styles of the main site, I tried through the frame, but it didn’t work out, because I had to include a separate file (and somehow you still need to send the code from the textarea there).
I displayed the styles in such an oak way (I just wrapped the code from the textarea in tags):

document.getElementById('PressCSS').innerHTML = "<style>"+CSSeditor.getValue()+"</style>";

Here is an example: htmlacademy.ru/courses/4/run/1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sydorenko, 2014-11-21
@copyloc

1. Isolate with an id for the user html container. Custom selectors will automatically have #user_html added at the beginning of each rule so that styles only apply to what's inside the custom html container.
2. but it's better to use iframe to output custom html ( stackoverflow.com/questions/620881/putting-html-in... in iframe add custom styles ( stackoverflow.com/questions/3714880/how-to-apply-c.. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question