How to Add Colored Content Boxes to Your Website

I’ve been asked a few times recently if there’s a way to include support for various colored content boxes for sites powered by the Genesis Framework.

There are a number of themes in the market that implement this with shortcodes. I feel that isn’t necessary and want to show you just how it easy it is to do with CSS.

Below are the 6 default colored content boxes that are included in this tutorial:

This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.
This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.
This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.
This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.
This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.
This is an example of a Content Box, which is easy to implement and can be used to put emphasis on a particular thought or sentiment.

Implementing the Content Boxes

In your text editor, all you need to do is wrap the text in a div with a class applied to it. Here’s some sample HTML, along with the CSS required for the colored content boxes.

Email Newsletter

Like what you read here in this blog post?
Get more like it delivered to your inbox daily.

Comments

  1. says

    Brilliant.

    I have wanted to add boxes like these for a while, but the plug-ins I tried always ended up more problematic than anything else (partly, I assume, because they had to offer a lot “more” that I did not want, so they would be seen as “worthwhile” plug-ins in the first place).

    Simple. Incredibly useful. Many thanks.

    • says

      Glad to hear it. So many things like this (in my opinion) are included in ways that are far more complicated than they should be. A few lines of CSS and a simple paragraph class and you’re on your way!

      • says

        I agree with you Brian. That is what I encourage the members of my Club to do. To be able to do things like this without resorting to plugins all the time.

    • says

      Ah yes, I also ran in this issue when creating our sales letter (see large green boxes at middle and end) http://bit.ly/MYVPus – these content boxes span multiple paragraphs so you have to use divs!

      What’s a little frustrating is that when you use div tags the text immediately below the content box sits flush to the bottom of the content box (even if it’s in a p tag!). I just looked at Keith’s code and I see he uses an empty P tag – I’ve been doing the same, however what’s weird is that sometimes, if I republish the post WordPress seems to remove these empty tags for me. I tried putting a non-breaking space inside the open and closing p tags but I still get the same problem. I think it’s when I switch to design view and publish. Anyone else have this issue?

        • says

          Yes sorry about the link – I just realised I’m on day 29 of a 30 day trial with my new host, and I’d experienced problems so I decided to cancel the account and move my site back – not exactly something I’d recommend for a Friday evening … or any evening for that matter ;)

          I tend to switch between the two editors. As far as I’m aware it keeps my empty tags when switching, but maybe not when posting.

      • says

        Hi Jason

        I’ve added the CSS below.
        The border-radius is what gives it the rounded corners and you can mess around with the values.

        .yellowinfobox {
        background: none repeat scroll 0 0 #FFFFE6;
        border: 1px solid #DDD;
        border-radius: 8px 8px 8px 8px;
        box-shadow: 0 2px 3px #666;
        display: block;
        margin: 10px;
        padding: 35px 35px 20px 40px;
        }

        You can get CSS info like that using the developer tools in Chrome or firebug in Firefox.
        At the moment I’m using the developer tools and the CSS below was just copied and pasted from my page.

        Hope that helps

  2. says

    Great tip Brian. One thing I would also love to see, are more short codes in future releases of Genesis. Such as CTA buttons, highlights, and more. A lot of themeforest themes come with them, and I constantly miss the small things like that inside Genesis.

    Maybe even make them a plugin, that would work just as well.

    Cheers Brian,
    Jonathan

    • says

      The thing is Jonathan, most of that stuff can be handled by CSS and easier implementation that does not require anything from Genesis itself. In other words, no code bloat in the Framework. Here’s another example of something that folks use shortcodes for.

      • says

        I was thinking something more along these lines, just adding more value to running on Genesis — possibly by creating a huge plugin.

        Something that worked uber well specifically with Genesis could be a huge benefit to people that want to enable it — even if it means more code bloat (speaking non-core of Genesis).

        Cheers Brian

        • says

          Ah, gotcha. Yeah – the problem with that from a Content Box standpoint is the CSS that’s involved. If you customize the hexcodes, how to save it without it being overwritten in a plugin update?

  3. says

    Thanks for this Brian. For those someone that needs their content boxes stand out more, they must have a background knowledge of CSS but this should be a good start. :-)

  4. says

    In the child themes I built I used div classes with appropriate styling. I prefer your approach. But then you are the expert, I’m a newbie. :)

  5. says

    Hi Brian,

    Love this but unfortunately I’m not seeing any styling for the content boxes on this post. I’m running that latest version of Chrome on a Macbook Pro. In saying that, it looks great in Safari!

  6. says

    Thanks for this! I’ve been wanting to do it, and now it seems like such a simple thing… I’ll be putting this code to good use!

  7. says

    Probably nice for a lot of people… but it feels a bit strange to see basic CSS presented a higher math :-)
    So anyone who like this… go check out what you can do with just a little bit of CSS you ‘ll be amazed what old fashioned html/css is capable of ;-)

  8. says

    This is exactly what I’ve been looking for. I was using block quotes as a workaround, but prefer these content boxes in many cases.

  9. says

    Great tutorial, I always knew how to do it (in theory at least), but it is actually a lot less code than I thought it would be. I just relaunched my company’s website on the (in)spyr child theme (with a few customizations) http://protechig.com/ and it would be great to highlight special offers with those boxes.

    I also read a blog post yesterday speaking that 51% of the top 1,000,000 websites that are running WordPress, and the Genesis framework is the #2 premium theme of those sites congrats on your good work!

    Also, for future tutorials, I’d love to see a tutorial on responsive web design, especially with that 1140 framework, I love the 1140 theme by the way.

    Keep up the awesome work!

  10. says

    Thanks for writing this tutorial on colored boxes Brian.

    I requested this not so long ago and its always easy following your simple to follow tutorials.

  11. says

    The only change I would make would be to abstract the box class (which defines the padding and margin) away from the coloring.

    Like this: https://gist.github.com/3014500

    This way, if you wanted to add a new color, you would only need to add a new class for that color instead of also adding it to the first line where the margin/padding are defined. And it adds the nice benefit of making the CSS slightly more readable. :)

    Great post, Brian. Thanks for sharing it!

    • says

      Thanks for the suggestion Brett. It’s probably the proper way to go, but in the end the idea is to keep this super simple for users, and one class for the content boxes is what I was shooting for.

  12. says

    Very simple stuff here, basic really… I switched from the bloat of Woo to Genesis after realizing how easy it was to replicate the most used shortcodes with CSS. This means a leaner and faster website! Thanks Brian :-)

  13. says

    ‘I’m fairly certain that I’m one of the people who’s been a pest about colored boxes,, callouts, pull-quotes, and other obscure layout elements. And this looks like it might be possible for the CSS-challenged among us without causing cascading power outages, traffic-light malfunctions, or whatever other things happen when one makes CSS mistakes. So, thank you, Brian, for this tutorial. And applause for putting it out there for the larger WP community. Question(s): if it’s enclosed within a div, isn’t it then possible to specify margins and use it as callout or pull-quote? And – margins aside – if one were to use these frequently, are there safe ways to assign buttons using one of the MCE editor add-on plugins? Great tutorial. Thanks again – Jon

  14. says

    Brain,
    Thanks for sharing.

    What is the timeline for Genesis 1.9? I check in with StudioPress Forums quite often but have been unsuccessful in discovering this information.

  15. says

    Hi Brian,

    Your tutorial is great. But Is there any way to simplify the process? For example, every time I want to get a blue box, I have to enter the lengthy, heavy class “content-box-blue”. Can you tell us how to make a simple popup window on WordPress Post Editor, so we can click to format the text as our wishes?

  16. says

    Brian, I avoided buying Genesis until this week. I didn’t feel like my coding skills were up-to-snuff to make the most use of the framework until recently. I’ve been using it for a couple of projects I’m working on this week and I love it.

    I’m with you. Don’t bloat it up with a bunch of shortcodes that most people will never use. I like the approach Genesis has taken and I’m looking forward to making the most out of it.

    • says

      Awesome to hear Matt, and glad that you finally took the plunge! Even I had the “ah-hah” moment where it all clicked and was easy to work with from there on out!

  17. says

    You should just use divs, not paragraphs. using paragraphs causes some issues with margins.

    .content-box-yellow {background-color: #fef5c4; border: 1px solid #fadf98; border-radius: 6px; clear: both; margin: 15px 0 35px; padding: 20px;}

  18. says

    We need to add these cool styles to tinymce buttons or shortcodes. Most of my clients can’t use (And I prefer they do NOT use) the html editor.

    Is there a good tutorial or best practices for adding new tinymce buttons?

    The second item is adding these to an editor stylesheet. There’s so much that we can do to make the lives of regular users easier!

  19. says

    Brian: Thanks for this simple but very useful tutorial. It’s a great way to break up and highlight certain sections of lengthy text. Take care. –Tom

  20. says

    This is just brilliant, Brian, thanks a bunch, easy to implement a couple of boxes in my own color just by editing the hex code in your examples.
    You’ve gained a new subscriber, there are things here i find useful and come late or never in the SP blog.
    Once again, genesis, proves to be the right choice.

  21. says

    This works great on some of my sites using the Minimum theme. On the one I’m working today with Genesis 1.9.1, it doesn’t seem to work at all. I don’t see it in the Genesis CSS, either. Someone missed the memo. Could have been me.

  22. says

    Simply the best solution. Before this I was using 3rd party plugin, however, knowing now that using your own style with just a couple of CSS codes gives you a fresh air. Thanks Brian.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>