Custom Styles for SharePoint 2010 Rich Html Field

October 27 2010 184 comments

A typical requirement from a client is to be able to incorporate their own custom styles for the Rich Html Field. Allowing their public relations department to apply nice text formating for paragraphs with some Comic Sans Hotness might not be the best practice in here, so let’s be careful out there. The best scenario is only to allow custom formatting for headings, paragraphs and maybe a few different table styles but let’s go!

First, open up the page layout containing the HTML editor and add PrefixStyleSheet property for the RichHtmlField:

<PublishingWebControls:RichHtmlField
    id="Content"
    FieldName="PublishingPageContent"
    PrefixStyleSheet="my-rte"
    runat="server"
/>

Now, the default value for the property is ms-rte. We are going to redefine this to my-rte. Do not use any uppercase characters in the property value as apparently those wont work. Deploy the page and open it in edit mode to see the desired effect. The styles collections are now empty in the Ribbon.

We now have to define our own styles prefixed with the string my-rte. I’d suggest that you put these style declarations in a separate stylesheet to avoid javascript errors caused by complicated and hard-to-parse stylesheets. Let’s name our new stylesheet rte.css and add a few declarations there.

The Markup Collection

Let’s say I want to have an option to add a level 1 heading or an H1 tag for the given page via the Markup Styles dropdown list:

Step 1 – introduce the tag:

H1.my-rteElement-H1
{
  -ms-name:"my level 1 heading";
}

Step 2 – add the styles to the tag:

.my-rteElement-H1
{
    font-size: 150%;
}

Save the rte.css and make a reference for it in your master page, page layout or even use an alernative css. If you want your clients to be able to edit the styles themself, you could upload the rte.css in the Style Library and reference it there.

I have saved the file directly in the 14-hive /_layouts/my/ -folder and use a quick reference in the master page:

<SharePoint:CssRegistration
    ID="CssRegistration1"
    runat="server"
    Name="/_layouts/my/rte.css"
/>

Deploy and reload the page, fire up the edit mode and navigate to the ribbon where you can see your new style in action.

Your first custom style


Adding new elements is easy once you get to know the logic. Here’s an example of a parapgraph with nice rounded corners and superb font on modern browsers (note that I have combined the introduction and style values in one declaration):

P.my-rteElement-P
{
    -ms-name:"My CSS Rounded Paragraph";
    background: #808;
    color: #fff;
    border: 3px solid #f0f;
    text-transform: uppercase;
    text-align: center;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    box-shadow: 0 0 20px #000;
    -moz-box-shadow: 0 0 20px #000;  
    -webkit-box-shadow: 0 0 20px #000;
    padding: 10px;
    font: bold 2em Comic Sans MS;
}

Even Grammatical Errors Wont Silence the Comic of Sans

The Styles Collection

The Styles collection can be populated with the same way by changing the Element-suffix into Style ie.:

.my-rteStyle-MePinky
{
  -ms-name:"I am pink";
  color: #f0f;
}

This (P)arapgraph is Pink

Other Items

I’d suggest that you check out the default HTML editor styles in /Style Library/en-us/Themable/Core Styles/htmleditorstyles for quick reference how to style the other elements, including table styles on the Ribbon.

Popularity: 14% [?]

184 comments to “Custom Styles for SharePoint 2010 Rich Html Field”

  1. Vincent says:

    Hello, I’m happy to see some great articles on your site. Septic Tank Services

  2. dexter says:

    Wow, you did such an amazing job with such a small space. It looks outstanding! garden fence repair

  3. xander says:

    Great article, Thanks for writing about that. It’s really helpful for me. Keep it up your writing. garden fence repair

  4. visit us says:

    This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.

  5. When you need to have land excavated in Erie, PA, rely on our excavation company at. Our excavation contractors have extensive experience, which is why we are the preferred excavation company.

  6. Vince says:

    I needed to leave a little remark to help you and wish you a decent continuation. digital marketing Fort Worth, TX

  7. 重量を載せて欲しかったです。それ以外は満足しています。
    売り切れることもあるので事前にお問い合わせ下さい と書いてあったので、
    連絡をさせて頂きスムーズに購入出来ました。
    ありがとうございました。大切に使います。
    コーチ ショルダーバッグ ポピー シークイン タータン グルーヴィー 2WAY ショルダーバッグ 16048 スパンコール パテントレザー パープル系 マルチカラー 新品 ハンドバッグ 斜め掛け レザー 革 ベリーマルチカラー
    重いかな
    同じシリーズのSサイズのバッグを愛用しています。
    もうちょっと大きかったらな、と思うこともあるので注文しました。
    S200g→これ400g
    デザインが違うので仕方ないですが、重いかな。
    とても新品とは思えない綺麗な品で、状態も良く、満足しています。
    クロムハーツ 22k スーパーコピー 2ちゃんねる https://www.kopi2021.com/product/5240.htm

  8. Welcome to Buffalo Video Pros! Meet WNY’s premier wedding videography company. If you’re looking for a high-quality video from a local Buffalo, NY videographer, you found us!

  9. Very a nice article. I really feel amazing and thank you very much for the good content.

  10. pavement says:

    Looking for a pavement service near you? You have reached the right spot! We are Commercial Paving Buffalo NY, a local company ready to provide you with the best services at the most affordable price.

  11. this is really nice to read..informative post is very good to read..thanks a lot!

  12. Francis says:

    This is a brilliant blog! I´m very happy with the comments! basement foundation repair

  13. Henry says:

    Liking this blog. THanks for posting.

    carpet cleaning Douglas

  14. James says:

    This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.plaster walls

  15. Casual Sex in Northern Ireland is the best chat service in UK with hot ladies ready for you, check out and enjoy

  16. Nicelky dpne and written my friend!
    I started writing juset recently and realised
    lot of blogs simply rework old ideas but add very
    little off worth. It’s great to read an enlightening write-up of some real value to
    me.
    It’s going down on my list of crteria I need to replicate being a new blogger.

    Reader engagement and material value arre king.

    Some terrific suggestions; you havge definitely mqde it on my list of people to watch!

    Keep up the terrific work!
    Cheers,
    Robinson

  17. belfast personals is most polular web platform for making casual sex contacts with hot girls in UK

  18. tree removal says:

    Expert tree removal, stump removal and tree trimming in St. Louis. Call Now! 314-310-7445.

  19. A great and awesome write up. An all time relevant article.

  20. Home remodeling should always be left to the pros. Let Breathe Easy Construction’s home remodeling contractors take care of you.

  21. When living in South Florida, windows become a top priority for homeowners. Without them, your house is at risk from severe weather patterns and high insurance premiums. But South Florida Windows direct, and save big time.

  22. roof repair says:

    Great effort with the work that you have put in, keep up all the great work.

  23. Tree removal says:

    Tree Trimming? No problem, We are affordable tree care company in Tuscaloosa AL.

  24. Jack Lynn says:

    Found this information really interesting. Thank you for posting it. https://www.concretebundaberg.com.au/

  25. A great and awesome write up. An all time relevant article.

  26. We spend a large amount of our time on the road, and most people have had their car break down or run out of gas once or twice. These situations can be very stressful, and trying to find a reliable local towing service that also provides emergency roadside assistance only adds to the frustration.

  27. “We paved your way to a better life through Clark County paving, paving Vancouver WA, asphalt Vancouver WA, and gravel Vancouver WA.”

  28. mshahid says:

    Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. Anthony Scott Dietrich Gainesville VA

  29. Thanks for sharing! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.

  30. Welcome to U.S City Directories and thank you for visiting our official website. We only want what’s best for our valued consumers. Because of this, our content is made by the best writers in our team to produce high-quality articles. You can reach us if you have any inquiries that you want to know.

  31. Wow the article you give us is amazing, no wonder many people want to read this

  32. Welcome to US directories and thank you for visiting our official website. We only want what’s best for our valued consumers. Because of this, our content is made by the best writers in our team to produce high-quality articles. You can reach us if you have any inquiries that you want to know. http://usdirectories.net/

  33. When working with Internet-facing websites, rich content allows us to make difference and to add interaction and semantics to static pages.

Leave a Reply