Is it possible to style CSS with Style tags instead of inline styles in HTML fields? Specifically for knowledge articles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2018 03:17 PM
I'd like our knowledge base articles to follow a similar pattern for continuity sake. It would be much better in my opinion to be able to throw CSS customizations between a Style Tag as opposed to doing them all inline. The problem that I'm having is that I will write a bit of code and it will initially take. However, when I attempt to go back into the code editor user the "<>" button, it automatically comments out everything inside of Style Tag. Please see the example below. I tried adding "style:{}" to the HTML whitelist in the HTMLSanitizerConfig and that didn't work. If anyone has any input it would be greatly appreciated.
Before:
<style>
.bullets li{
color: blue;
font-size: 20px;
font-family: Helvetica;
}
</style>
<ul class="bullets">
<li>Testing 1</li>
<li>Testing 2</li>
<li>Testing 3</li>
</ul>
After:
<style><!--
.bullets li{
color: blue;
font-size: 20px;
font-family: Helvetica;
}
--></style>
<ul class="bullets">
<li>Testing 1</li>
<li>Testing 2</li>
<li>Testing 3</li>
</ul>
<p></p>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2018 11:45 PM
Hi Michael,
Yes it is possible, with style tag
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<style>
.bullets>li{
color: blue;
font-size: 20px;
font-family: Helvetica;
}
</style>
<ul class="bullets">
<li>Testing 1</li>
<li>Testing 2</li>
<li>Testing 3</li>
</ul>
<p></p>
</body>
</html>
with inline css (styles are applied on individual elements using style attribute)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul>
<li style="color: blue;font-size: 20px;font-family: Helvetica;">Testing 1</li>
<li style="color: blue;font-size: 20px;font-family: Helvetica;">Testing 2</li>
<li style="color: blue;font-size: 20px;font-family: Helvetica;">Testing 3</li>
</ul>
<p></p>
</body>
</html>
Best practice is to use css with external file or using <style> tag. It reduces repetition caused using inline css.
Regards,
Pranali Kadam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2018 02:00 PM
Thank you for taking the time to respond Pranali.
My issue is that after I put everything in the style tag, the system automatically comments out everything within the style tag. So it makes it appear as though only inline styles can be used. I'd prefer to use style tags as you're correct, it would save me a ton of time. My preference is to just create a template that can be used over and over.
Have you been able to find a way to make style tags work in a knowledge article?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2018 08:16 AM
Hi Michael,
Yes you are right, same happening with me in knowledge article.
But you can try one thing, select required text and give text color, font size, font type.
It automatically adds the html code in span tag.
Please check below screenshots:
Please mark my answer as Correct/Helpful in case that helped you somehow.
Regards,
Pranali Kadam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 11:37 AM
We're facing the same issue with imported KB articles. OOTB SNOW import functionality not importing correctly because it adds the <style> tag which gets automatically removed when saving the form.