Posts tagged corners

CSS3 New features – Interesting info ;)

0

Hello fellow developers,
I'm sure all of you have heard of the "new" CSS3 stuff, it's been around for a while now, and it certainly has some very interesting new features.

First, I'll review some of the things that were the hardest to develop, yet they looked so damn well:

  • Rounded corners - We all love them, but how hard is to find a good way to do them?
  • Alpha transparency - PNGs, JavaScript tweaks... I must admit they are hard...

Plus, I'll show you how to create rounded+transparent borders!

Conclusion: The world needs new CSS features:

Solution: CSS3

Let's get going

Now before we get too exited, take into account that these new features "work" on major browsers, except obviously IE. So I would never use them for client sites... Meaning that you should only use these for personal designer portfolios, where you want to impress colleagues.

So now that this was clear, let's see how the new stuff goes:

Rounded corners:

For this you only have to select the element and use the following CSS code:

 
#example{
	-moz-border-radius: 20px;
	-webkit-border-radius: 20px;
}
 

Demonstration:

Example Div (CSS code for it below)

CSS for the example:

 
	background-color:#FFFFFF;
	border:#CCCCCC solid 2px;
	-moz-border-radius: 20px;
	-webkit-border-radius: 20px;
	padding:30px;
	text-align:center;
 

For more options go to the official CSS3 specs page for rounded corners

Transparency

This one is one of my favorites, combined with rounded corners :)

The way it works is simple, you can make any background color transparent by using one of several methods, I will show you the one I consider the easiest.

You know how in normal CSS we can select colors via the RGB color code, as in:

 
color: rgb(0,0,0);
 

Well, in CSS3 we can now add a fourth parameter, that will contain the alpha information, from 0 to 1.

Demonstration:

Example div. CSS for it below

CSS for the example above:

 
	background-color:rgba(0,0,0,0.5);
	color:#000;
	padding:30px;
	margin:20px;
	border:#CCCCCC solid 2px;
	text-align:center;
 

This effect won't look as cool here, because the background is a plain color. Use it over textured backgrounds for a great effect!

Rounded+transparent borders!

These really look amazing, rounded, transparent borders! Take a look at a live example

Unluckily, we cannot use rbga() colors on borders, but there is a simple workaround, embed the div you want with another one, with a padding of the size of the border (It looks better with larger borders)

Demonstration:

Example CSS below

CSS for the example above:
DIV 1 (Outer div) - Note the bigger radius

 
margin:20px;
padding:20px;
background-color:rgba(0,0,0,0.5);
-moz-border-radius: 30px;
-webkit-border-radius: 30px;
 

DIV 2 (Inner div)

 
padding:20px;
text-align:center;
background-color:#FFFFFF;
color:#333333;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
 

Well, I hope you found this interesting!

Show us your uses!

Have you already implemented any of these techniques? Please show us!
Comment below with the URL of the site where you used the new features of CSS3

New version of the nifty corners script

1

I'm sure you've heard of the Nifty Corners js script to create very cool rounded corners, and some of you might even have used it, well there is a new version:
Nifty Corners Cube

It improves most flaws of the first version, plus it adds new features and functionalities. This is the new stuff:

  • The numbers of parameters has been reduced from four of the first version and five of the second version to just two, of which one is optional.
  • It's not necessary specify the colors anymore, since they are detected automatically.
    They're easier to integrate into the design process, since the padding (both horizontal and vertical) of elements to round is preserved
  • It's easier to use them with other scripts
  • The support of CSS selectors has been improved and expanded
  • Just a single line in the head section is now needed for the whole library: even if they're still based on both CSS and javascript, the presentational CSS for Nifty Corners is loaded automatically by js
  • They're now released under GPL licence.

So go on, download it and test it, and tell us how it went ;)

Most used CSS tricks

6

Most used CSS techniques, from stylizedweb.com blog

1. Rounded corners without images

 

 
<p id="”container”">
<strong class="”rtop”">
</strong>   
 
< !-–content goes here –->
<strong class="”rbottom”">
</strong>
 
.rtop, .rbottom{display:block}
.rtop *, .rbottom *{display: block; height: 1px; overflow: hidden}
 
.r1{margin: 0 5px}
 
.r2{margin: 0 3px}
 
.r3{margin: 0 2px}
 
.r4{margin: 0 1px; height: 2px}

Rounded corners without images

2. Style your order list

 
<ol>
<li><span>This is line one</span></li>
<li><span>Here is line two</span></li>
<li><span>And last line</span></li>
</ol>
 
 
ol {
font: italic 1em Georgia, Times, serif;
color: #999999;
}
 
ol span{
font: normal .8em Arial, Helvetica, sans-serif;
color: #000000;
}

Style your order list

3. Tableless forms

 

 
<form>
<label for="”name”">Name</label>
<input id="”name”" name="”name”" />
<label for="”address”">Address</label>
<input id="”address”" name="”address”" />
<label for="”city”">City</label>
<input id="”city”" name="”city”" />
</form>
 
 
label,input {
display: block;
width: 150px;
float: left;
margin-bottom: 10px;
}
 
label {
text-align: right;
width: 75px;
padding-right: 20px;
}
 
br {
clear: left;
}

CSS Tableless forms

4. Double blockquote

 

blockquote:first-letter {
background: url(images/open-quote.gif) no-repeat left top;
padding-left: 18px;
font: italic 1.4em Georgia, “Times New Roman”, Times, serif;
}

Double blockquote

5. Gradient text effect

<h1><span></span>CSS Gradient Text</h1>

h1 {
font: bold 330%/100% “Lucida Grande”;
position: relative;
color: #464646;
}
h1 span {
background: url(gradient.png) repeat-x;
position: absolute;
display: block;
width: 100%;
height: 31px;
}
 
&lt;!–[if lt IE 7]&gt;
&lt;style&gt;
h1 span {
background: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’gradient.png’, sizingMethod=’scale’);
}
 
<!--[endif]–->

Gradient text effect

6. Vertical centering with line-height

 

div{
height:100px;
}
div *{
margin:0;
}
div p{
line-height:100px;
}

Vertical centering with line-height

7. Rounded corners with images

 

 
<p class="”roundcont”">
<p class="”roundtop”">
 
CONTENT
 
<p class="”roundbottom”">
 
.roundcont {
width: 250px;
background-color: #f90;
color: #fff;
}
 
.roundcont p {
margin: 0 10px;
}
 
.roundtop {
background: url(tr.gif) no-repeat top right;
}
 
.roundbottom {
background: url(br.gif) no-repeat top right;
}
 
img.corner {
width: 15px;
height: 15px;
border: none;
display: block !important;
}

Rounded corners with images

8. Multiple class name

 

&lt;img src=”image.gif” class=”class1 class2″ alt=”" /&gt;

.class1 { border:2px solid #666; }
.class2 {
padding:2px;
background:#ff0;
}

9. Center horizontally

 

&lt;div id=”container”&gt;&lt;/div&gt;
#container {
margin:0px auto;
}

Center horizontally

10. CSS Drop Caps

 

&lt;p class=”introduction”&gt; This paragraph has the class “introduction”. If your browser supports the pseudo-class “first-letter”, the first letter will be a drop-cap. &lt;/p&gt;
p.introduction:first-letter {
font-size : 300%;
font-weight : bold;
float : left;
width : 1em;
}

CSS Drop Caps

11. Prevent line breaks in links, oversized content to brake

 

a{
white-space:nowrap;
}
 
#main{
overflow:hidden;
}

12. Show firefox scrollbar, remove textarea scrollbar in IE

 

 html{
overflow:-moz-scrollbars-vertical;
}
 
textarea{
overflow:auto;
}

Easiest rounded corners ever

3

After an incredible amount of time spent looking for a way of easily rounding my corners, I've come across the one I find the easiest possible:

jquery + rounded corners plug-in

So now I'll explain how to install, use, improve...

Installation:

First of all, download and place the needed files:

Now place them in your desired folder, for this tutorial I'll be using "js/"

Usage:

In a html document, you would paste the following code in the head:

 
<script src="js/jquery.js" language="javascript" type="text/javascript"></script>
<script src="js/rounded.js" language="javascript" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
<!--
        $(document).ready(function() {
                $(\\'div.round\\').corner(); 
                // Note: Due to wordpress formatting a backslash \ is introduced here.
                //      You must delete it for the script to work
        });
-->
</script>

And anywhere in your website's body, whenever you place a div with a class="round", its corners will be rounded.

To create special corners, or achieve special effects, visit my demo page, full of special tricks.

Special cases:

The round command fills the "rounded" area with the body background color, so if you place this inside somewhere with a different background-color you must specify what color you want the corner to have.
Here you have an example:

 
        $('div.round').corner("cc:#F1F1F1");

If you want a bigger radius for your corners, just write the pixel radius in the parameters of corner():

 
       $('div.round').corner("10px");

Example and demo page:

I've set up an example and demo page, with all possible ways to do this, just go and see.

If you find any problems or suggestions feel free to comment!

Go to Top