Wrap Text with CSS Box: Part II
Whether you blog or have a static website, there are plenty of reasons to bring special attention to certain elements within your page.
In my last post, I showed you an easy way to wrap text in a box using CSS by placing the CSS/HTML code directly in your post. That can come in extremely handy in the right situation. But what if you put this block of info in every post, or every other post, or once a week? Even though it’s not difficult, re-typing that code every time could become a chore. In this post, we’ll look at how to get the same effect by adding the CSS in your stylesheet once, and assigning a class to the div we wrap around the text.
The first step, is to place the code in your stylesheet that will form the appearance of the box. In Wordpress, the file is called style.css. In CSS, an element that is assigned an id is marked with a #, and an element that’s assigned a class is marked with a .(period). Here we will use the latter. For this example, we’ll name the class, “special”. Here’s an example of the CSS that was used for the box at the top of this post. You can use something similar in your stylesheet. Of course, you can edit and adjust it any way you want.
font-family: Verdana;
font-size: 14px;
color: #000;
background: #F5FBEF;
border: 1px solid #E3F6CE;
padding: 10px;
margin: 10px auto;
}
That was easy enough, huh? Now those of you who are not at all familiar with a stylesheet, I can assume you are wondering where in the stylesheet this code would go. Truth is, it doesn’t really matter. I placed mine around the other post-related styles, just to make it easier to go back and find if I want to.
Now all that’s left, is to place that div around our text. Here I’ll use the same text from the example at the top of this post.

You can also set up different colors pre-loaded in your theme. Just give each one a different class name. Now the great thing about this, is the next time you want the same box to wrap around a block of text, the div and class is all you have to add to the post. The style is already in your stylesheet!








Nice tip.. I have been looking for this ..I would like to implement this at my blog
And it is now implemeted on my post page.. Great it works
Hey Dexter,
Very cool! I’m glad it worked for you. You have a really nice looking site there.
@ anthony,
I was a prize from Shoe money contest thru Weborithm, Thanks for checking it out.
I love it. I loved your previous tip about this — I call them info pops.
But this was simple enough to do that I did it, and IT WORKED!
Thanks Anthony
@JDub - Your welcome…….and the colors you chose match the theme nicely.
Thank you. I’m just a hack though, you’re the true artist
Have a great weekend!
[…] Wrap Text with CSS Box: Part II — Antbag.com […]
So glad I found this. I was looking for a way to make my code for link exchanges to stand out on my links page. This was soooo easy. I’m self taught and this was great for me.
You can see what I did here if you’d like:
http://www.brodiegirl.com/index.php?main_page=page&id=1&chapter=0&zenid=8e94fc22c756a0a1138e961d393f3bb4
Thanks for this tip!
Awesome Jess! Glad to help.
Did you do your own design on your Zen Cart site? Nice job! I’ve considered several times rebuilding my wifes store on Zen Cart.