At the end of this Tutorial you will be able to:
You can view finished versions of the two sample web pages you will update with hyperlinks in this Tutorial by clicking the links below. The finished samples will each open in a new tab of your web browser.
About hyperlinks styled as buttons
Adding a hyperlink button to your sample web page
Adding and styling a second hyperlink button
Hyperlink buttons and inherited styles
Positioning buttons with inline-block
Adding icons with Font Awesome
Adding spacing to icons in your buttons
Links can be styled to look like 'click/tap me' buttons. Such links are styled differently to links within paragraphs of text.
In this section you will add a button-styled hyperlink to the page-11.html sample web page in your websites folder.
<p><a href="#">Start free 14-day trial</a></p>Your web page should now look as shown below.
<p><a href="#" class="btn-solid">Start free 14-day trial</a></p>
/* ===== BUTTON STYLES ===== */ /* All button states */ a.btn-solid { } /* Passive button states */ a.btn-solid:link, a.btn-solid:visited { } /* Interactive button states */ a.btn-solid:focus, a.btn-solid:hover, a.btn-solid:active { }Why three sets of style rules?
color: white; text-decoration: none; padding: 12px 32px; font-weight: bold; text-transform: uppercase;
background-image: linear-gradient(90deg,#e052a0,#f15c41); transition: all 0.2s linear;
background-image: linear-gradient(90deg,#45C4E1,#4595E6);Your complete set of CSS styles for the .btn-solid class should now look as follows.
In your web browser, the passive and interactive button states should now look similar to those below.
You have now added your first hyperlink-styled button to your sample web page.
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
Now you will add and style a second button to your sample web page.
<p><a href="#">Download Whitepaper</a></p>Your HTML should now look as shown below.
<p><a href="#" class="btn-ghost">Download Whitepaper</a></p>
/* ===== BUTTON STYLES ===== */ /* All button states */ a.btn-ghost { } /* Passive button states */ a.btn-ghost:link, a.btn-solid:visited { } /* Interactive button states */ a.btn-ghost:focus, a.btn-ghost:hover, a.btn-ghost:active { }
text-decoration: none; padding: 12px 32px; font-weight: bold; text-transform: uppercase;
color: #fff; border: solid 3px #fff; transition: all 0.2s linear;
color: lightblue; border: solid 3px lightblue;Your complete set of CSS styles for the .btn-ghost class should now look as follows.
In your web browser, the passive and interactive button states for your second button should now look similar to those below.
You have now added a second hyperlink-styled button to your sample web page.
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
In the following steps you will create two new classes in CSS to control the shape of hyperlinks styled as buttons.
<p><a href="#" class="btn-solid btn-soft">Start free 14-day trial</a></p> <p><a href="#" class="btn-ghost btn-rounded">Download Whitepaper</a></p>
a.btn-soft { border-radius: 5px } a.btn-rounded { border-radius: 25px }
In your web browser, the new button styles should look similar to those shown below.
In this section you will apply font-related CSS styles directly to your hyperlink buttons.
<a href="#" class="btn-solid btn-soft">Start free 14-day trial</a> <a href="#" class="btn-ghost btn-rounded">Download Whitepaper</a>
You can see that the text inside the two buttons has now ‘lost’ some of their properties. Specifically:
Here is what has happened:
The solution is to apply font-family and font-size styles directly to the hyperlink buttons.
font-family: 'PT Sans', sans-serif; font-size: calc(16px + (19 - 16) * ((100vw - 320px) / (1600 - 320)));The complete ‘all states’ style rules for the two hyperlink button selectors should now look similar to the following.
Your two hyperlink buttons now have their own CSS properties of font-family and font-size set just for them.
They no longer depend on inheriting these properties from enclosing paragraph <p> ... </p> tags.
You will want to add some margin spacing around your hyperlink buttons. These margins will:
Here are the steps:
margin: 20px 40px 20px 0;This should add a top and bottom margin of 20px to each button, and a right margin of 40px.
As you can see, there is now a margin-right of 40px applied to two buttons. This is what you want.
But your web browser ignores your margin-top and margin-bottom values of 20px.
Here are the steps to correct this:
display: inline-block;The complete ‘all states’ style rules for the two hyperlink button selectors should now look similar to the following.
Success! Your hyperlink buttons are now complete.
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
In the final part of this Tutorial, you will add some icons from Font Awesome to your button-styled hyperlinks.
<!-- Link to icons for Font Awesome 5 --> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" rel="stylesheet" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous">This adds the Font Awesome stylesheet to your web page.
You have now successfully added Font Awesome icons to two of your button-styled hyperlinks.
Within your hyperlink buttons, the single space between the text and the icons, created by pressing the Spacebar key once, is not enough. More spacing is needed.
You could type several spaces simply by pressing the Spacebar multiple times. But the web browser will combine multiple empty spaces into a single space. So that is not a solution.
One option is to type the special HTML code that forces an empty space. This is the non-breaking space character. You type this as follows:
For example, in your page-11.html file, you could type three non-breaking space codes inside your buttons as shown below.
Inside each button, between the text and icon, you have four spaces. One space is the result of pressing the Spacebar; the other three are created by the three codes.
Your buttons will now display as follows in your web browser.
The result will look as follows.
Unfortunately, adding lots of codes to text can cause problems when your web page is displayed on mobile-sized screens.
The better solution is to use CSS to add a margin-left spacing value to your icons. Here are the steps.
a.btn-solid i, a.btn-ghost i { margin-left: 12px; }
That’s it. You have now successfully added spacing to icons within your button-styled hyperlinks.
Click page-11.html to view a finished sample of this web page in a new tab of your web browser.
Upload the following web page and stylesheet to your account on GitHub:
page-11.html
style-11.css
Your web page will be published at web addresses similar to the following:
https://username.github.io/page-11.html
It may take a few minutes for your uploaded files to appear on GitHub.
UI Cheatsheets: Buttons
By Tess Gadd on Medium
Make sense of rounded corners on buttons
By Shan Shen on Medium
30 cool CSS Buttons – with animations!
From the Webdeasy
CSS Buttons
From dev.to
Return to All Tutorials.