Beautiful effects for buttons using css. Rounded corners. Describe the CSS styles of the button
Everyone has long been tired of traditional rectangular corners in website design. Rounded corners are in fashion, which are made not using images, but through styles, for which the border-radius property is used. This property can have one, two, three or four values separated by a space, which determine the radius of all corners or each individually.
In table 1 shows a different number of values and the type of block that is obtained in this case.
Code | Description | View |
---|---|---|
div ( border-radius: 10px; ) | Rounding radius for all corners at once. | |
div ( border-radius: 0 10px; ) | The first value sets the radius of the top left and bottom right corners, the second value sets the radius for the top right and bottom left. | |
div ( border-radius: 20px 10px 0; ) | The first value sets the radius of the upper left corner, the second - both the upper right and lower left, and the third value - the lower right. | |
div ( border-radius: 20px 10px 5px 0; ) | Sequentially sets the radius of the upper left, upper right, lower right and lower left corners. |
Example 1 shows how to create a block with rounded corners.
Example 1. Corners of a block
HTML5 CSS3 IE 9+ Cr Op Sa Fx
Result this example shown in Fig. 1.
Rice. 1. Block with rounded corners
An interesting effect can be obtained if you set the rounding radius to be greater than half the height and width of the element. In this case, you will get a circle. Example 2 shows how to create a round button with a picture.
Example 2: Round button
HTML5 CSS3 IE 9+ Cr Op Sa Fx
The result of this example is shown in Fig. 2.
Rice. 2. Round button
IN Opera browser rounding to
The border-radius property can be combined with other properties, for example, adding a shadow to an element. In example 3, a set of circles is made, one of which is highlighted using box-shadow . This set can be used to navigate through pages or photos.
Example 3. Glow
HTML5 CSS3 IE 9+ Cr Op Sa Fx
The result of this example is shown in Fig. 3.
Rice. 3. Glow around the circle
Using border-radius you can create not only a circle, but also an ellipse, as well as an elliptical rounding for a block. To do this, you need to write not one value, but two, separated by a slash. Writing 20px/10px means that the horizontal radius of the fillet will be 20 pixels, and the vertical radius will be 10 pixels. Example 4 shows how to create elliptical corners to add a comic-book style caption to a photo.
Example 4: Ellipses
HTML5 CSS3 IE 9+ Cr Op Sa Fx
The result of this example is shown in Fig. 4.
Rice. 4. Using elliptical corners
You can also change the appearance of the corners on images by adding the border-radius property to the img selector, as shown in Example 5.
Example 5: Images
HTML5 CSS3 IE 9+ Cr Op Sa Fx
- Translation
Hello, dear habrafriend! Today we will learn how to create CSS3 3D buttons! These are based on Orman Clark's popular Freebie PSD for his Premium Pixels website. We will try to create a copy of these buttons with using CSS With minimum quantity HTML code.
Step 1: Create an HTML document
We'll start by creating a new HTML document. It will be based on the HTML5 boilerplate so that we have an easy starting point. Now we will add a list with links. That's basically it, thanks to CSS3 for not having to use additional divs and spans.We will assign a class 'buttons' to each list item. And since Orman used different colors, we'll assign each button its own color as a class.
That's all we need at this stage.
Step 2: Basic CSS rules
Before you get into gradients, rounded corners, etc., there are some basic rules to take care of. Nothing special, just regular CSS2:Ul ( list-style: none; ) a.button ( display: block; float: left; position: relative; height: 25px; width: 80px; margin: 0 10px 18px 0; text-decoration: none; font: 12px" Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: bold; line-height: 25px; text-align: center; )
Now let's apply the rules for different colors. For example, for gray. All other colors can be viewed in the demo.
/* GRAY */ .gray, .gray:hover ( color: #555; border-bottom: 4px solid #b2b1b1; background: #eee; .gray:hover ( background: #e2e2e2; ) )
You should end up with something like this. Looks pretty solid, if it's 2008.
Step 3: Double frames!
If you look closely at the final result, you will see that there is a thin line around the perimeter of the entire button. To achieve this effect we will use pseudo elements :before And :after.a.button ( display: block; float: left; position: relative; height: 25px; width: 80px; margin: 0 10px 18px 0; text-decoration: none; font: 12px "Helvetica Neue", Helvetica, Arial, sans -serif; font-weight: bold; line-height: 25px; text-align: center; a.button:before, a.button:after (content: ""; position: absolute; left: -1px; height: 25px; width: 80px; bottom: -1px; ) a.button:before ( height: 23px; bottom: -4px; border-top: 0; )
By adding color the buttons look much better.
/* GRAY */ .gray, .gray:hover ( color: #555; border-bottom: 4px solid #b2b1b1; background: #eee; ) .gray:before, .gray:after ( border: 1px solid #cbcbcb; border-bottom: 1px solid #a5a5a5; .gray:hover ( background: #e2e2e2; )
Step 4: A little bit of CSS3 magic
Now let's get down to the actual CSS3 part. Let's start with the rounded corners:a.button ( display: block; float: left; position: relative; height: 25px; width: 80px; margin: 0 10px 18px 0; text-decoration: none; font: 12px "Helvetica Neue", Helvetica, Arial, sans -serif; font-weight: line-height: 25px; -webkit-border-radius: 3px;
Natural elements :before And :after also need rounded corners.
a.button:before, a.button:after ( content: ""; position: absolute; left: -1px; height: 25px; width: 80px; bottom: -1px; -webkit-border-radius: 3px; -moz -border-radius: 3px; border-radius: 3px; ) a.button:before ( height: 23px; bottom: -4px; border-top: 0; -webkit-border-radius: 0 0 3px 3px; -moz- border-radius: 0 0 3px 3px; border-radius: 0 0 3px 3px; -webkit-box-shadow: 0 1px 1px 0px #bfbfbf; -moz-box-shadow: 0 1px 1px 0px; 0 1px 1px 0px #bfbfbf;
Finally we will apply gradients, inner shadow and text shadow. To avoid bugs in IE6, let's add state:visited.
/* GRAY */ a.gray, a.gray:hover, a.gray:visited ( color: #555; border-bottom: 4px solid #b2b1b1; text-shadow: 0px 1px 0px #fafafa; background: #eee; background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#e2e2e2)); background: -moz-linear-gradient(top, #eee, #e2e2e2); inset 1px 1px 0 #f5f5f5; ) .gray:before, .gray:after ( border: 1px solid #cbcbcb; border-bottom: 1px solid #a5a5a5; ) .gray:hover ( background: #e2e2e2; background: -webkit- gradient(linear, left top, left bottom, from(#e2e2e2), to(#eee)); background: -moz-linear-gradient(top, #e2e2e2, #eee )
Our end result isn't too bad!
Step 5: Have we forgotten anything?
Orman also included the:active state in his design. Therefore, we simply have to add it to our code.We'll place this part of the code below the rules for the different colors.
/* ACTIVE STATE */ a.button:active ( border: none; bottom: -4px; margin-bottom: 22px; -webkit-box-shadow: 0 1px 1px #fff; -moz-box-shadow: 0 1px 1px #fff; box-shadow: 1px 1px 0 #fff, inset 0 1px 1px rgba(0, 0, 0, 0.3); webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none)
This is what we get:
Step 6 (optional): Old browsers
So we've created some nice CSS3 buttons that work in all modern browsers. But what about Internet Explorer 8 and below. These browsers do not support text shadows or gradients.To solve this problem, we can use the javascript library Modernizr, which can detect whether your browser supports CSS3 and HTML5. The library doesn't fix the problem, it just offers an alternative style.
First, we will create our own version of Modernizr so as not to carry around a huge javascript. This can be done on their website. Once we've inserted javascript into our document, we need to define different class rules for the alternate style. We will use images for those browsers that do not support border-radius and gradients.
/* MODERNIZR FALLBACK */ .no-cssgradients a.button, .no-cssgradients a.button:visited, .no-borderradius a.button, .no-borderradius a.button:visited, .no-generatedcontent a.button, .no-generatedcontent a.button:visited ( background: url(images/sprite.png) no-repeat 0 0px; height: 32px; width: 82px; ) .no-cssgradients a.button:hover, .no-borderradius a .button:hover, .no-generatedcontent a.button:hover ( background: url(images/sprite.png) no-repeat 0 -32px; ) .no-cssgradients a.button:active, .no-borderradius a.button :active, .no-generatedcontent a.button:active ( background: url(images/sprite.png) no-repeat 0 -64px; bottom: 0; line-height: 35px; ) .no-cssgradients a.gray, . no-cssgradients a.gray:visited, .no-cssgradients a.gray:hover ( background-position-x: 0; ) .no-cssgradients a.pink, .no-cssgradients a.pink:visited, .no-cssgradients a.pink:hover ( background-position-x: -82px; ) .no-cssgradients a.blue, .no-cssgradients a.blue:visited, .no-cssgradients a.blue:hover ( background-position-x: -164px; ) .no-cssgradients a.green, .no-cssgradients a.green:visited, .no-cssgradients a.green:hover ( background-position-x: -246px; ) .no-cssgradients a.turquoise, .no- cssgradients a.turquoise:visited, .no-cssgradients a.turquoise:hover ( background-position-x: -328px; ) .no-cssgradients a.black, .no-cssgradients a.black:visited, .no-cssgradients a .black:hover ( background-position-x: -410px; ) .no-cssgradients a.darkgray, .no-cssgradients a.darkgray:visited, .no-cssgradients a.darkgray:hover ( background-position-x: - 492px; ) .no-cssgradients a.yellow, .no-cssgradients a.yellow:visited, .no-cssgradients a.yellow:hover ( background-position-x: -574px; ) .no-cssgradients a.purple, . no-cssgradients a.purple:visited, .no-cssgradients a.purple:hover ( background-position-x: -656px; ) .no-cssgradients a.darkblue, .no-cssgradients a.darkblue:visited, .no- cssgradients a.darkblue:hover ( background-position-x: -738px; ) .no-cssgradients a.button, .no-cssgradients a.button:visited, .no-cssgradients a.button:hover, .no-cssgradients a .button:before, .no-cssgradients a.button:after, .no-borderradius a.button, .no-borderradius a.button:visited, .no-borderradius a.button:hover, .no-borderradius a.button :before, .no-borderradius a.button:after, .no-generatedcontent a.button, .no-generatedcontent a.button:visited, .no-generatedcontent a.button:hover, .no-generatedcontent a.button:before , .no-generatedcontent a.button:after ( border: 0; )
Conclusion
This way we have some nice cross-browser CSS3 buttons. This might seem like a lot of code for 10 buttons, but it's just a demonstration of what CSS3 can and can't do. You can do whatever you want with it! I hope my tutorial was useful, thanks for your attention!Today I want to tell you how to make stylish buttons using pure CSS. We will create 4 styles, these are buttons filled with one color, buttons that are surrounded by a border, a button style with a shadow and fill, and the last 4 style is buttons with a click effect. We will do all this goodness without using any scripts, using only CSS.
Demo Ι
HTML code for buttons
The HTML code we will use is very simple. For each of the buttons we will define separate classes. We will also set classes for applying the effect when hovering and activating our future button. In general, here is the code itself:
CSS styles for all buttons
Different browsers display some standard CSS rules slightly differently. Therefore, in the following CSS code we will reset all styles, and add some default values. This is what the code looks like:
Button ( display: inline-block; margin: 0 10px 0 0; padding: 15px 45px; font-size: 48px; font-family: "Bitter",serif; line-height: 1.8; appearance: none; box-shadow: none; border-radius: 0; ) button:focus ( outline: none )
It's not difficult at all. Well, now let's take a closer look at each of the 4 styles of our stylish buttons.
Flat buttons filled with background
This type of button is very popular nowadays, as it meets all modern web design trends. In other words, this is a flat style or Flat design. Moreover, people are accustomed to such buttons and willingly click on them.
This image shows the button's three states, normal (default), on hover, and on click or action:
The CSS code for these buttons is very simple. This seems to me to be a huge plus:
Section.flat button ( color: #fff; background-color: #6496c8; text-shadow: -1px 1px #417cb8; border: none; ) section.flat button:hover, section.flat button.hover ( background-color: #346392; text-shadow: -1px 1px #27496d; ) section.flat button:active, section.flat button.active ( background-color: #27496d; text-shadow: -1px 1px #193047; )
Style buttons with borders or borders
This style of buttons is in the same class as flat buttons. The only difference is that here we remove the fill, and instead set rules for displaying the border of the buttons. This image shows everything clearly:
And as usual the CSS code is very simple, we just add rules for the border to appear:
Section.border button ( color: #6496c8; background: rgba(0,0,0,0); border: solid 5px #6496c8; ) section.border button:hover, section.border button.hover ( border-color: # 346392; color: #346392; ) section.border button:active, section.border button.active ( border-color: #27496d; color: #27496d; )
Buttons with shadow and gradient in CSS
This style of buttons can easily be called outdated, but even now it can be found on the Internet. If these buttons fit the style of your site, then they are just for you. They are also very easy to make, here is an image:
In CSS we will use shadow and gradient fill rules. When hovering, a shadow will appear around the button and when clicked inside.
Section.gradient button ( color: #fff; text-shadow: -2px 2px #346392; background-color: #ff9664; background-image: linear-gradient(top, #6496c8, #346392); box-shadow: inset 0 0 0 1px #27496d; border: none; border-radius: 15px; ) section.gradient button:hover, section.gradient button.hover ( box-shadow: inset 0 0 0 1px #27496d,0 5px 15px #193047; ) section.gradient button:active, section.gradient button.active ( box-shadow: inset 0 0 0 1px #27496d,inset 0 5px 30px #193047; )
Stylish click effect
This style is also very popular now and is widely used in website design. It seems to the user that the button is actually being pressed. Here you can see the details in the image:
The CSS here is a little more complex and requires a bit of math. But this can be easily understood. In general, it's not all that scary. We will place a non-blurred shadow under the button so that it gives the effect of a 3D button or appears to stick out a little. When we hover over the buttons we will make the background darker. And when the user clicks on the button, we will change the position of the button itself in the styles. And to make it all look more impressive and smooth, we will add a CSS3 transformation (translateY). This way the button will smoothly move down. And here is the CSS code itself:
Section.press button ( color: #fff; background-color: #6496c8; border: none; border-radius: 15px; box-shadow: 0 10px #27496d; ) section.press button:hover, section.press button.hover ( background-color: #417cb8 ) section.press button:active, section.press button.active ( background-color: #417cb8; box-shadow: 0 5px #27496d; transform: translateY(5px); )
Demo Ι
Conclusion
That's it! Now you have stylish and modern buttons that you can use for your needs. Naturally, you can change them until they are unrecognizable, this is only the simplest example of the implementation of this kind of buttons. I hope you enjoyed this lesson. See you soon!
Hello dear readers. We have already studied many of the properties that appeared in CSS3, but just knowing them is not enough. You definitely need to practice! And today I will show you...
Let's open the file index.html and create a simple structure
Nothing special. Just 3 block with class .button Let's move on to styles now.
Body (
}
Button (
display: inline-block;
margin: 40px;
width: 100px;
height: 100px;
background: url(http://subtlepatterns.com/patterns/extra_clean_paper.png);
cursor: pointer;
border-radius: 50%;
inset 0 2px 0 rgba(255,255,255,.6),
0 2px 0 rgba(0,0,0,.1),
inset 0 0 20px rgba(0,0,0,.1);
}
I took the background for the document and our buttons from the site subtlepatterns.com.
We do ours div line-block, so that they line up horizontally, we set their height, width, indent from the edges of the browser, rounding 50% to get a circle, and when hovering the cursor we do pointer. There is nothing complicated here, but it was not for nothing that I separated the shadow in the styles, because This is exactly the part that can cause difficulties, although everything is simple there too, and you will see this now.
Having set the first shadow, we will already see the outline of our circle:
Box-shadow: 0 3px 20px rgba(0,0,0,.25);
Then we ask inner shadow, so that we have such a window on top, and the button becomes more voluminous.
Box-shadow: 0 3px 20px rgba(0,0,0,.25),
inset 0 2px 0 rgba(255,255,255,.6);
The next outer shadow is needed to slightly darken the area under the button below, and the next inner one darkens the space inside the button for greater effect)
Box-shadow: 0 3px 20px rgba(0,0,0,.25),
inset 0 2px 0 rgba(255,255,255,.6),
0 2px 0 rgba(0,0,0,.1),
inset 0 0 20px rgba(0,0,0,.1);
As you can see, at first it seems complicated, there are many properties, but if you look into it, everything turns out to be much simpler. So here is our final result:
Now let's implement the behavior on hover per block
Button:hover (
box-shadow: inset 0 0 20px rgba(0,0,0,.2),
0 2px 0 rgba(255,255,255,.4),
inset 0 2px 0 rgba(0,0,0,.1);
}
We have already dealt with shadows in the block, now try to figure out for yourself what happens when you hover. Likewise, leave just one shadow and see what happens, and then add a second one and see what changes, and so on.
Finally, let's add icons to our buttons so it doesn't get too boring. To do this, let's change a little html
Btn-photo (
background: url(http://defaulticon.com/sites/default/files/styles/icon-front-page-32x32-preview/public/field/image/MD-camera-photo_0.png) center center no-repeat;
}
Btn-settings (
background: url(http://defaulticon.com/sites/default/files/styles/icon-front-page-32x32-preview/public/field/image/settings.png) center center no-repeat;
}
Btn-tag (
background: url(http://defaulticon.com/sites/default/files/styles/icon-front-page-32x32-preview/public/field/image/tag.png) center center no-repeat;
}
Here we simply add a second background for each button, taking the icons from the site defaulticon.com.
That's it. Today we looked at how to create round buttons in css3.
Hello, dear friends. Today I will tell you about two ways that will help you create an animated button for your websites. You've probably seen a lot of these buttons and clicked on them. So, on my blog I periodically recommend affiliate courses and trainings, only those that I have tried myself. And of course I'm interested in statistics, and statistics say that people click on attractive buttons 48% more often than on regular links.
The principle of creating animated buttons using CSS is as follows, there are three provisions. 1 - Initial, 2 - when hovering the cursor and 3 - when pressing the mouse button. Some services have all three provisions, while others have only two. But the main thing is that you are satisfied with the end result.
Video tutorial on the second method of creating animated buttons:
As an example, let's look at the CSS3 ButtonGenerator service; it has just two provisions. But the effects look very good. Who is confused by the lack of Russian language, use the last generator given in the list.
So let's begin.
Opening home page service. Initially, you will see a preliminary view of the button and tools that allow you to make all kinds of settings.
The first section, Text&Font, is responsible for text, font size, font color, font shadow. This is where you write the label on the button, set its size, color, and shadow.
The next section, Background, refers to the background. Here you can specify the button color, button gradient, button size, and background blend.
The Border section is responsible for setting the shadow and borders of the button. You can easily adjust the thickness of the border, the rounding of corners, and the shadow of the button.
The next section, Transform, is responsible for transforming the button - rotation, displacement, distortion.
The next section, Transition, is responsible for the smoothness of the animation. You set these settings in accordance with your button. Actions can be applied to the entire button or to individual layers.
After trying several times, experimenting with the settings and you will understand what's what.
After the initial appearance of the button is configured, you can move on to the next stage. This is a modification of the button when hovering the mouse cursor. To do this, click on the checkbox indicated in the screenshot.
Mouseover options
Now all the changes you make to the settings are for the button that will be displayed when you hover the mouse over it. And these settings depend individually on each button. As an example, I changed the rotation, gradient and shadow color settings.
When the button is ready, you can proceed to installing the button in the article. To do this, install the code in the required place in the article:
Here's our example:
Well, now you know how to easily and quickly make an animated button for a website or blog. Try and implement, it's worth it. If you have any questions, write in the comments, I will try to help.
That's all for today, I wish you good luck. And I’m always glad to see you on the pages of my blog.
P.S. And here is an example of an animated button for Denis Gerasimov’s training “Setting up cold traffic to promote affiliate links.” I completed this training and recommend it to everyone - this is without unnecessary exaggeration, real way making money on affiliate programs. Which is basically what I do.