Nivo Slider – round corners with CSS3 and jQuery
Soo my web designer loves round corners. I mean really, really loves. Everything would be ok if setting it was simple. Well, I always thought that it is.
The solution works with Nivo Slider in ver 2.3
To get rounded corners you need to add declaration like this to your rule
{
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
That way we’ve got every 4 corners rounded. Of course remember that in IE8 and lower you can’t see this effect.
When using Nivo Slider turns out, that simple declaration like border:radius is not enough. The rounded corners was visible at beginning and then were lost. I tried with #slider img, a and so on, but nothing worked. Then I looked how slider works and what he really shows and I came up with this (i think) really simple solution. Basically slider is showing slices “glued” together, not original picture. That was it.
So my solution for this problem ladies and gentleman is:
» Add afterLoad function to script like below
$('#slider').nivoSlider({
[other options here if you have any]
afterLoad: ( function(){
//round top left corner and bottom left corner of first slice
$('.nivo-slice').first().css({
'-webkit-border-bottom-left-radius': '5px',
'-webkit-border-top-left-radius': '5px',
'-moz-border-radius-bottomleft': '5px',
'-moz-border-radius-topleft': '5px',
'border-bottom-left-radius': '5px',
'border-top-left-radius': '5px'
});
//round top right corner and bottom right corner of lastslice
$('.nivo-slice').last().css({
'-webkit-border-bottom-right-radius': '5px',
'-webkit-border-top-right-radius': '5px',
'-moz-border-radius-bottomright': '5px',
'-moz-border-radius-topright': '5px',
'border-bottom-right-radius': '5px',
'border-top-right-radius': '5px'
});
})
});
» Add css declaration to class .nivoSlider and img like below
.nivoSlider,.nivoSlider img{
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
Of course you need jQuery for this.
The solution works with Nivo Slider in ver 2.3
hey i have a problem with my nivoslider. i want to make a border radius but only in the topright and the bottomleft corners. actually i sucssed to do it like this; /* The Nivo Slider styles */ .nivoSlider { position:relative; height:420px; width:920px; -moz-border-radius-bottomLeft: 20px; -moz-border-radius-topRight: 20px; -webkit-border-bottom-left-radius: 20px; -webkit-border-top-right-radius: 20px; border-bottom-left-radius: 20px; border-top-right-radius: 20px; overflow:hidden; z-index: 8; } but my problem is that with the (overflow:hidden) i can not put my arrows outside the img because they go under the image if you understand what i meaning. in the default setting i can get the result of 4 corner… Read more »
While a nice idea, for modern browsers you can already skip the
vendor prefixes and just use: border-radius: 4px;
For explorer i just use PIE.htc http://css3pie.com/
I have put an online example.
The solution works for NivoSlider in ver 2.3. I think here is a problem. For newer version it’s more complicated and simple css will not work here for example in box transitions where .last() it’s not necessary the corner that should be rounded.
This looked so promising but finaly it didn’t work. Seems that it’s necessery to digg deeper inside the code. I took the mod from this dude:
http://web3o.blogspot.com/2011/02/jquery-nivo-slider-with-css3-round.html
Do you have online example of your code? Ill look at it to see what could causing problem. Maybe its a class name in css? Check in firebug if the proper styles are added in html.
Hi,
i tried your howto, but i still see only the first picture with round corners. All others are normal. Any Idea?