New Podcast

Posted Tuesday, July 27 at 2:29 pm

Ryan Price and Mike Anello recently talked with Jacob Redding (jredding), author of Beginning Drupal as well Treasurer and Interim General Manager of the Drupal Association.

Download Podcast 41
DrupalEasy_ep41_20100727.mp3
Syndicate content

NEWSLETTER

Stay informed on our latest news!

Syndicate content

Testimonial

On March 11th I attended the first DrupalEasy Workshop in Orlando, Florida. I'm an experienced web developer who has recently picked up Drupal as a tool for helping to build high quality content-driven websites. Mike and Ryan were excellent teachers - they gave a thorough overview of a complex topic in a short space of time, and provided plenty of resources for us to continue learning. The workshop is essential for anyone who has previously configured a basic Drupal site and wishes to take their skills to an advanced level. I would not hesitate to recommend DrupalEasy.com training and hope to attend more workshops in the future.

Who are we?

DrupalEasy is the collective expertise of Ryan Price and Michael Anello, who joined forces to provide training and consulting services worldwide. Read all about them and what they can do.

What is Drupal?

Drupal is a free, super-powerful content management system for sites that require information posting and collection, including blogs, forums, videos, photos, and databases of information. We think it is the best platform available. Here's why...

Why Drupal?

More and more savvy organizations are going with Drupal for content management, and its no mystery why. It’s free, flexible, and easy to maintain for small or large volume sites. Learn more...

Adding Rounded Block Borders to Your Site's Theme

No votes yet

Rounded corners are all the rage - and they have been for quite some time in web design. The way they "soften" up a design make them quite attractive to designers and decision-makers. Unfortunately, implementing rounded corners in a web page is not nearly as easy as it is to implement in a mockup using an image application.

When talking about rounded corners, there are 2 distinct user cases to be considered - the first is when creating rounded corners only on the top corners of an area - this is commonly seen on tabs and block headers. The alternative use case is when all four corners of an area are rounded - this is usually seen in blocks and around content areas. This article will focus on the the case where all four corners need to be rounded. The result will be a method of adding the ability to optionally apply a rounded border to any block on your site in a way that doesn't break when the block is resized.

Tabs with 2 rounded corners and a content border with 4 rounded corners.

By the end of the article, you should be able to add this option to just about any Drupal theme - the relevant files you'll need are available for download at the end of this article.

I'll be using the Block Theme module to allow you to turn the border on and off for specific blocks - you might recall that this module was my pick-of-the-week in DrupalEasy Podcast 03.

While I can't guarantee that this method will work flawlessly with your theme, I can confirm that it works without modification in the Zen Classic (an included subtheme of the Zen theme) and Blueprint themes. In addition, I got it to work on the K2 theme with a single CSS tweak.

The method for actually building the rounded border in HTML and CSS was actually blatently borrowed (thanks!) from the Panels module. Another great example of not having to re-invent the wheel.

The first thing you're going to want to do is download and and enable Block Theme.

Enable the Block Theme module

Next, navigate your way to the Block Theme settings page (admin/settings/blocktheme) and add "rounded|Rounded Border" to the "Custom Block Templates" text area.

Block Theme settings

Next, you'll need to add some files to your theme. All of these files are available for download at the end of this article. First, put the "blocktheme-rounded.tpl.php" template in your theme directory. If you're using a sub-theme, you'll need to be sure the sub-theme has a block.tpl.php file as well. If not, copy the block.tpl.php file from the base theme into the sub-theme.

The "blocktheme-rounded.tpl.php" file is similar to a default block.tpl.php file with some extra HTML elements.

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="<?php print $classes; ?>">
<div class="rounded_border">
    <div class="wrap-corner">
      <div class="t-edge"><div class="l"></div><div class="r"></div></div>
      <div class="l-edge">
        <div class="r-edge">
          <?php if ($block->subject): ?>
            <h3><?php print $block->subject ?></h3>
          <?php endif;?>

          <div class="content"><?php print $block->content ?></div>
          <?php print $edit_links; ?>
        </div>
      </div>
      <div class="b-edge"><div class="l"></div><div class="r"></div></div>
    </div>
  </div>
</div>

Then put the "rounded_borders" directory into your theme's "images" directory (if your theme doesn't have an "images" directory, feel free to create one). It is in this directory that the border images reside. I've included a 1-pixel grey border to get you started, although the images are fairly easy to recreate in different colors and thicknesses. You can even add drop shadows to the borders.

In order to link up the images with the new HTML elements, you'll need to place the "rounded_borders.css" file into your theme's "css" directory (again, if one doesn't exist, then feel free to create one).

If you decide to modify the borders, be warned that you may need to tweak some of the CSS in the rounded_borders.css file - particularly if you change the size of the image files or the thickness of the borders. That's a little beyond the scope of this article, but if you do need to tweak the CSS, pay particular attention to the "background-position", "height", and "width" values.

Finally, you'll need to add one line to your site's .info file. This tells your theme to load the "rounded_borders.css" file.

stylesheets[all][] = css/rounded_borders.css

At this point, you absolutely must clear your site's cache (specifically, the theme registry) if you have the Administration Menu and Devel modules installed, then you can do this from the Administration Menu's Drupalicon menu item (all the way on the left).

Clear the theme registry

Superduper - you're all done with the installation. Now all you have to do it go into your block administration page and and click to "configure" a block that you'd like to apply the rounded border to. On the block's configuration page, select "Rounded Border" as the "Custom Theme".

Select your custom theme

Ta Da! You've done it.

The search block with a rounded border

If you're interested in learning how to create tabs with rounded corners, check out this article from A List Apart.

Trackback URL for this post:

http://drupaleasy.com/trackback/96
AttachmentSize
drupaleasy_rounded_borders.zip5.05 KB

12 comments

user picture
ultimike wrote 50 weeks 6 days ago

Robert, The answer to both

Robert,

The answer to both your questions is basically the same. Yes, you can surround both comments and nodes with rounded corners using the same technique. All you need to do it apply the technique to the comment.tpl.php and node.tpl.php template files.

-mike

Robert A. Young Chu wrote 51 weeks 1 hour ago

I have tried enabling

5

I have tried enabling "rounded" for a block and it didn't display at all; however that was never really my intention. I have placed the div tags around the content section of <?php print $content; ?>, and have succeeded in making my my content section rounded. Thanks a lot for this contribution!

In addition I also have two question that someone might have the answer to or know where to get them.

1. Do you know how have each comment display a rounded corner just like the ones found here http://drupal.org/node/414526 ?

2. Is there a way to make individual stories (content type) have rounded corners, so that whenever a new one is created (and automatically posted to a certain node) they look like they are separated like the comments, instead of with horizontal breaks?

Thank you once again for this contribution, and your time spent developing this is very appreciated.

Robert

gio wrote 1 year 4 weeks ago

me I couldn't make it work..

me I couldn't make it work.. first all my theme disappeared, then I adjusted everything adding the rounded block css into the style css and my theme came back.... but when I set the rounded corner custom block theme no rounder corners appear...... (whitejazz theme... recoloured by me, maybe that's why it won't work...)

Guest wrote 1 year 12 weeks ago

Thank you so much for this

5

Thank you so much for this post! I'd been working for several hours to try and figure this out.

Dave wrote 1 year 14 weeks ago

Well, that was easy...! I

Well, that was easy...!

I simply copied the div tags from blocktheme-rounded.tpl.php, and placed them around the <?php print $content; ?> line in page.tpl.php.

Looks really good. I'll post the link when the site's up and running.

Great module this.

Dave wrote 1 year 14 weeks ago

Hi Mike, My name's Dave and

Hi Mike,

My name's Dave and I'm a developer based in London.

Ok cool, I'll check that out and let you know how it goes

user picture
ultimike wrote 1 year 14 weeks ago

Guest (if that is your real

Guest (if that is your real name),

You can absolutely extend this to any other part of your site.

If you want to surround the page content, then edit your page.tpl.php and use the HTML and CSS included in the article as your guide...

-mike

Guest wrote 1 year 14 weeks ago

I've got this up and running

I've got this up and running now and it looks great. So much so that I'd like to extend the functionality if possible to cover other areas of my site.

I'd like to surround the page content in rounded borders as well. Do you guys think this might be possible with your module? What might I have to do to extend it in this way?

Graphic Design Seminar wrote 1 year 14 weeks ago

wow, great post, i had no

5

wow, great post, i had no idea it was that easy. thanks for the tutorial i think this is awesome.

user picture
ultimike wrote 1 year 14 weeks ago

You should be able to just

You should be able to just add both to your .info file - like this:


stylesheets[all][] = css/style.css
stylesheets[all][] = css/rounded_borders.css

-mike

Guest wrote 1 year 14 weeks ago

What seems to be happening is

What seems to be happening is that the theme is only reading rounded-borders.css. Adding my existing style.css content to rounded-borders.css restores the theme. Alternatively, adding the rounded-borders content to style.css then adding: stylesheets[all][] = css/style.css to the info file also fixes it. Is there a way to get Drupal to read both .css files? My theme is based on bluemarine, dead simple.
Guest wrote 1 year 14 weeks ago

Followed these steps...and my

Followed these steps...and my theme disappeared! It seems the style.css is no longer being recognised. Plus my custom logo isn't loaded anymore either.

I've tried placing style.css in the main theme directory and the new css directory. I don't think I missed any steps from above. Any suggestions as to why this has happened?

On the up side, my user login module now had nice rounded corners...

Syndicate content