Skin design tip: Rounded Corners in All browsers with jquery

Posted by man.os | Posted in dotNetNuke, jQuery, Skinning | Posted on 12-02-2010

13

After spending lots of time making round corners for my containers using God knows how many small images, html tags and css classes I found out that I could easily ditch all that with just a bit of jQuery magic! It is important to note that this is a cross-browser solution – your browser doesn’t have to support any rounded corner CSS properties, so it works even on Internet Explorer 6.

What you will need.

If you have DNN version 5.0 or greater then you already have jQuery ready and you will only need the jQuery Corner plugin (jquery.corner.js) . You can download it from here: http://www.malsup.com/jquery/corner/ .

Including the plugin

In your Skin file, include the jquery.corner.js file by adding this line:

<script src="http://github.com/malsup/corner/raw/master/jquery.corner.js"  type="text/javascript" charset="utf-8"></script>

or better if you have copied the file to your skin’s path  (e.g. in the scripts folder)

<script src="<%=SkinPath%>/scripts/jquery.corner.js" type="text/javascript" charset="utf-8"></script>

Making the Container

And now for any container you want to have rounded corners you just have to add this line at the end of your container code :

<script type="text/javascript">
 $('.panel').corner();
</script>

where .panel is the name of the div that you want to make its corners rounded.
You can see much more options by using some parameters here:
http://www.malsup.com/jquery/corner/

A complete container example:

<%@ Control language="vb" CodeBehind="~/admin/Containers/container.vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Containers.Container" %>
<%@ Register TagPrefix="dnn" TagName="ACTIONS" Src="~/Admin/Containers/Actions.ascx" %>
<%@ Register TagPrefix="dnn" TagName="ICON" Src="~/Admin/Containers/Icon.ascx" %>
<%@ Register TagPrefix="dnn" TagName="TITLE" Src="~/Admin/Containers/Title.ascx" %>
<%@ Register TagPrefix="dnn" TagName="VISIBILITY" Src="~/Admin/Containers/Visibility.ascx" %>

<div class="panel">
  <h2> <dnn:ACTIONS runat="server" id="dnnACTIONS" /> <dnn:TITLE runat="server" id="dnnTITLE" CssClass="" /></h2>
  <div  id="ContentPane" runat="server"></div>
 </div>
<script type="text/javascript">
 $('.panel').corner();
</script>

And that’s it! No-images cross-browser rounded corners!

Comments (13)

Wow this is a great resource.. I’m enjoying it.. good article

this jquery work?? i create a simple html with script but dont work see the html:

<script type="text/javascript" src="jquery.corner.js"

Round $(this).corner();
Bevel $(this).corner(“bevel”);
Notch $(this).corner(“notch”);

$(this).corner(“bevel”);

hi i try with small html but dont work :


<script type="text/javascript" src="jquery.corner.js"

Round $(this).corner();
Bevel $(this).corner(“bevel”);
Notch $(this).corner(“notch”);
Notch $(this).corner(“notch”);

Notch $(this).corner(“notch”);
Notch $(this).corner(“notch”);

$(this).corner(“bevel”);

“”"

html:

html>
script type=”text/javascript” src=”jquery.corner.js” /script>
div class=”panel”>
div class=”demo”>Round $(this).corner();
div class=”demo”>Bevel $(this).corner(“bevel”);
div class=”demo”>Notch $(this).corner(“notch”);
Notch $(this).corner(“notch”);

Notch $(this).corner(“notch”);
div class=”demo”>Notch $(this).corner(“notch”);
/div>

script type=”text/javascript”>
$(this).corner(“bevel”);
/script>

/html>

Hi,
for simple html (no dnn) you can try the following. Just make sure that you also have a css class for .panel which has a border on it (to be rounded) :

<script src=”http://github.com/malsup/corner/raw/master/jquery.corner.js” type=”text/javascript” charset=”utf-8″></script>

<div class=”panel”>
</div>

<script type=”text/javascript”>
$(‘.panel’).corner();
</script>

hi thanks for response, i try first with example for dnn but dont work for me.

I need include the .panel into my dnn css?? if is true with which attributes?

@Omar: You could put it in the dnn css or the skin’s css. However if you are not familiar with the above you could also do it in the text/html module that you have put the code. So before the code you could use something like :

<style type=”text/css”>
<!–
.panel {
border: 5px solid #F00;
}
–>
</style>

Thanks!!!

why i received this error??
in admin module work perfect but when select host module received this error, the same problem in random pages.. i have the script in my dnn root and the script in my container.aspx

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET CLR 1.1.4322; InfoPath.1; .NET4.0C; .NET4.0E)
Timestamp: Thu, 29 Jul 2010 13:33:59 UTC

Message: Object doesn’t support this property or method
Line: 733
Char: 2
Code: 0
URI: http://localhost/dotnetnuke/tabid/7/portalid/0/Default.aspx

ignore the last message i modify wrong file the correct files is skin.ascx ..

OK, I feel like a total noob but I do get the “object doesn’t support this properyt or method” error when I call “$(‘.panel’).corner();”

Can anybody suggets why please? I really want to use this plugin (and understand this error!)

Thanks

Noob update – I had the “jQuery.noConflict();” in my script – once I hremoved this, it’s all good. Thanks for the tute!

I’m had the same “Object doesn’t support this property or method” and it turned out to be another piece of javascript on the page which didn’t agree with this script…

Write a comment