CSS Buttons

Creating Buttons with CSS

Previously, the use of a tag and pseudo classes (hover, active, visited) was explained.

In this topic, we will see how to get links in button view with css. In this way, we will not need to use different programs for button-style objects.

As you can see in the topic examples section, you will be able to prepare linkbuttons in many different styles.

In our next topics, menu making will be explained.

Let's examine the following codes:

a:link, a:visited /* Determines the normal and visited versions of links */
{
display: inline-block;
background-color: #09F;
color: white;
text-align: center;
text-decoration: none;
font-weight: bold;
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
margin-top: 0px;
margin-right: 2px;
margin-bottom: 0px;
margin-left: 2px;
}
 
a:hover, a:active /* Determines the state of the links when hovered and clicked */
{
background-color: #FFF;
padding-bottom: 8px;
color: #09F;
padding-top: 8px;
border: 2px solid #09F;
padding-right: 23px;
padding-left: 23px;
}

In this example, let's pay particular attention to the following points:

  • Since the a tag is an inline element, properties such as width, margin will not work properly in this tag. So it is necessary to convert it to a view like block or inline-block. By making inline-blocks, they are placed side by side. If the block was made, they would be placed one under the other.
  • In the example, since the buttons are used side by side, padding is applied from the sides instead of giving width. In this way, the texts inside will also appear in the middle.
  • Instead of using height, top and bottom padding is preferred. In this way, we can provide the vertical alignment of the text in the link more easily.
  • In hover and active state, border is given, padding is reduced so that the total area of ​​the buttons does not change.
css link button examples, creating links with css button appearance, converting links to buttons with css, making a tag links like buttons

EXERCISES

Example of a button-looking link with shadow effect applied Try It

The transition and box-shadow properties used in this example are explained in our next topics.

Creating Links Button Appereance Try It

The transition property used in this example is explained in our next topics.

Css link button tutorials Try It

Click the Try It Yourself button, review the codes, change them, see the result...

Css link button tutorials Try It

Click the Try It button, review the codes, change them, see the result...



COMMENTS




Read 843 times.

Online Users: 3933



css-buttons