- Create Colored Boxes
- Invalid Short Codes & CSS
- 3 Ways to Make Colored Boxes
- Using Pure CSS Code
- Creating Shortcodes for Boxes
- Difference Between Shortcodes & CSS
- Changing Themes Without Breaking Code
- Reader Interactions
- Leave a Reply Cancel reply
- Primary Sidebar
- CSS Text Box Tutorial
- Inline Text Box
- Text Boxes as Info Messages
- Block Quotes with Text Box
- Menu Boxes
- Opening Hours
- Conclusion:
- About Editorial Staff
- You also might be interested in
- How to Create Bootstrap 5 Forms?
- How to Use Query Loop in WordPress to Create Posts List Page?
- How to Track and Block User IP in WordPress?
- How to Create a Coloured («Colored») Box in HTML/CSS
- How to put text into a box that has a background colour
- How to Create a Coloured («Colored») Box in HTML/CSS
- Prerequisites
- Creating a Coloured Box
- Demo
- Browser Compatibility
- thesitewizard™ News Feed (RSS Site Feed)
- Please Do Not Reprint This Article
- Related Articles
- New Articles
- Popular Articles
- How to Link to This Page
Create Colored Boxes
Have you ever landed on a website for the very first time which is all the same color?
How hard is it to find the most important content on that page?
On your own site you know where everything is but put yourself in your readers shows for a minute.
Around 80% of visitors to your site are new.
They have never seen your site before and when they leave, most will never come back.
So make it easy for them and more will come back.
One way to attract your readers attention is to use colored boxes. You can create colored boxes by creating shortcodes or using pure CSS code.
Invalid Short Codes & CSS
Highlight your most important: content, links and calls to action using colored boxes.
But this can cause a massive problem down the track for you.
The reason for this is most themes include this feature built into the core files.
When you change themes, you end up with invalid shortcodes, css code or html that doesn’t work.
This can be a nightmare to remove manually.
Invalid code will also look ugly, unprofessional and worst of all, the content you highlighted to grab your readers attention, is no longer highlighted.
This is called theme lock and sometimes used to try and lock you into staying with the same theme developer.
3 Ways to Make Colored Boxes
The solution to this is to either:
- Install a plugin with shortcodes which moves with you from theme to theme.
- Using CSS only – Insert a small code block into your child themes css file which works on all themes.
- Using CSS and php to create shortcodes for colored boxes.
Using Pure CSS Code
Here’s some code which you can easily paste into your child themes style.css file.
You can easily edit this code to change:
- The background color – background: #eee ;
- The border color – border: 1px solid #ddd ;
- The border thickness – 1px solid
- The padding between your text and the border – padding: 10px ;
- Create different types of boxes ( .alert, .note, .info) – .alert
Once you’ve created different colored boxes and styled them, simply wrap your content using this code in your HTML editor.
If you want 3 types of boxes, simply use the code block above and name them:
- .note – Use this to make a note box
- .alert – Use this to make an alert box
- .info – Use this to create an info box
Different themes use different code for displaying boxes
- Woo themes uses shortcodes built into the framework
- Genesis doesn’t offer any code built into the core files so you’ll need to install a plugin or use the code above.
- Thesis uses this code which won’t work in Genesis or StudioPress themes
Creating Shortcodes for Boxes
You can also create great looking boxes using shortcodes which won’t break when you move themes.
Add some PHP code and css to your files like this. Learn more about how to create short codes in WordPress to make colored boxes in my next post.
Difference Between Shortcodes & CSS
Shortcodes will enable you to include content with paragraphs within your colored boxes.
Pure CSS will only allow you to wrap the content within one paragraph.
Changing Themes Without Breaking Code
One of the big advantages of adding the code above is that you may find your old boxes start working again.
This depends on which theme you where using previously but in my case it worked after moving from Thesis.
If you do use code like this which is flexible, you won’t suffer any problems when you change themes.
How about yourself, what do you use to draw attention to your most important content?
Reader Interactions
Leave a Reply Cancel reply
You must be logged in to post a comment.
Primary Sidebar
Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…
CSS Text Box Tutorial
Text boxes are used to showcase different types of content like info messages, menus, social widgets, block quotes, etc. As far as we checked no theme by default offers customizable text boxes and you need to make your own to suit your needs. In this article we will create different types of text boxes for different purposes and you can copy paste the code on your site to add the widget.
Inline Text Box
When you want to create only one or two text boxes then the recommended way is to use inline CSS at element level instead adding CSS at site level. Below is an example code to convert a paragraph to a box with background.
This is a Sample Textbox
You can just add paste the code anywhere on the body of your page and it will look like below on the published site:
This is a Sample Text box with background color added using inline CSS. This is the easiest way to add text boxes to your site.
You can customize the background color and font attributes to align the box on your site.
Text Boxes as Info Messages
Info messages are useful to show different styles of messages to your audience like warning, alert, announcement, danger, etc.We use font awesome icons to add icons in front of the text and the CSS for the info message box is given below:
.webnots-notification-box < -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; color: #ffffff; font-family: verdana, 'open sans', sans-serif; margin-bottom: 25px; padding: 10px 14px 10px 44px; position: relative; box-shadow: 0px 1px 5px #999; >.webnots-notification-box:before < font-family: FontAwesome; font-size: 21px; left: 14px; position: absolute; >.webnots-information < background-color: #3498db; >.webnots-information:before < content: "\f129"; margin-left: 4px; >.webnots-question < background-color: #f1c40f; >.webnots-question:before < content: "\f128"; margin-left: 2px; >.webnots-tip < background-color: #16a085; >.webnots-tip:before
The HTML code for the info message box is as below:
This is the info box - You can input as much or as little information!This is the help box - You can input as much or as little information!This is the tip box - You can input as much or as little information!
You can add different types of messages by adding the required icon and below is some of the examples for info message boxes:
Block Quotes with Text Box
Block quotes on your site can be decorated with text boxes so that it looks attractive and beautiful on the site. Below is one example of customizing block quotes with CSS:
blockquote < font-style:italic; line-height:32px; font-size:20px; color:#fff; background: #3F51B5; margin:10px; padding: 15px 20px 15px 20px; border-radius: 5px; >blockquote:before, blockquote:after < position: relative; vertical-align: middle; font-family: 'Playfair Display', serif; font-size: 56px; font-weight: 700; line-height: 0; color: #FBC02D; >blockquote:before < left: -5px; content: '\201C'; >blockquote:after
The HTML should be like below:
This is block quote element customized with CSS text box properties. You can customize more as you need.
By adjusting the background and quotes color you can results like below:
This is block quote element customized with CSS text box properties. You can customize more as you need.
This is block quote element customized with CSS text box properties. You can customize more as you need.
This is block quote element customized with CSS text box properties. You can customize more as you need.
Menu Boxes
Text boxes can be used to show menus or a listed content to save lot of space on your site. Here we show two such boxes as basic, actually you can do much more.
.container-box < width: 300px; padding: 20px; margin-bottom: 20px; background-color: #f5f5f5; border: 1px solid #e3e3e3; border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); >.block < display: block; width: 100%; padding-right: 0; padding-left: 0; background-color: #5cb85c; >.item-list
The menu box 1 will be like below on the published site:
.box-column < width: 350px; border: 1px groove; padding: 5px; >.color-box < padding: 0; margin: 0; list-style: none; >.color-box li
The menu box 2 will look like below:
Opening Hours
Conclusion:
There are numerous possibilities of creating text boxes with simple CSS. Above are only few examples and you can customize the background, borders, colors and text as you need. You can play with these basic examples and build more custom text boxes for your need.
About Editorial Staff
Editorial Staff at WebNots are team members who love to build websites, find tech hacks and share the learning with community.
You also might be interested in
How to Create Bootstrap 5 Forms?
Forms are important and unavoidable part of any website. Bootstrap[. ]
How to Use Query Loop in WordPress to Create Posts List Page?
Blog posts page display all the blog posts on your[. ]
How to Track and Block User IP in WordPress?
WordPress is a robust content management system for online publishers.[. ]
How to Create a Coloured («Colored») Box in HTML/CSS
How to put text into a box that has a background colour
How to Create a Coloured («Colored») Box in HTML/CSS
I was asked by a visitor how he could create a box, give it a background colour («color» if you use a different variant of English), and insert text in it, the way some printed magazines and books sometimes place additional information in a separate box or panel on a page.
Prerequisites
This article assumes that you know a bit of HTML and CSS. Otherwise you will be at a loss as to where to put the code I supply below or how to adapt it for your purpose.
Creating a Coloured Box
The box itself can be any block tag in HTML. Many, if not most, webmasters use a for this purpose.
Let’s say that you have the following HTML snippet that you want to make into a box.
The CSS to give the DIV block a background colour is, predictably:
The background-color rule above specifies the HTML colour value of #cfc . You can of course use any other colour you like. Most web editors and plain text editors (other than the rudimentary Notepad that comes with Windows) have a colour picker, allowing you to visually select a colour to get the appropriate numerical value. Alternatively, if you prefer to do things the hard way, you can also consult the list of colours and their values on Wikipedia.
Unfortunately, although the above code is correct, if you use it as it stands, you will find that the background colour will hug the text you place very closely, causing the entire thing to seem barely like a box. To make things more box-like, you will probably want to add some space to the area around your text, and perhaps even give it a border.
The padding rule adds 10 pixels to the space between your text and the margins of the box, and the border rule creates a 1-pixel thick solid green border. You can of course change the values given here (ie, the number of pixels and the colour) to suit your page’s design.
If you’re posting to a blog that allows you to insert HTML, but does not make it easy for you to change the style sheet, you can even put those rules into your DIV tag.
Demo
The above code produces the following box.
This is a demo box to illustrate the code given in thesitewizard.com’s tutorial on creating coloured boxes.
Browser Compatibility
The CSS given above should work in all current browsers. It will probably even work in most older browsers too, including Internet Explorer 6 (which is most likely extinct today).
Copyright © 2017-2018 Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.
thesitewizard™ News Feed (RSS Site Feed)
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
Please Do Not Reprint This Article
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
Related Articles
New Articles
Popular Articles
How to Link to This Page
It will appear on your page as:
Copyright © 2017-2018 Christopher Heng. All rights reserved.
thesitewizard™, thefreecountry™ and HowToHaven™ are trademarks of Christopher Heng.
This page was last updated on 20 December 2018.