How to Create a Button in HTML/CSS 🔘
The navigational system of your website is one of its most important features.
You can use simple hyperlinks.
You can use fancy 'Navbars' built with Javascript.
You can use simple button images with your hyperlinks.
You can also create buttons using CSS and HTML5 code which mimic the mechanical aspects of Js navbars. And these won't slow your pages or create errors in browsers that don't support Js.
Most of the code is set up in the Style Sheets.
The Button
Button
The HTML
<p><a href="#" class="button1">Button</a></p>
Size is determined by size of text and padding.
Us your imagination on the colors and shadow changes.
The CSS
p a.button1 {
text-align:center;
padding: .625rem 1.5rem !important;
background-color: #ff9900;
box-shadow: -4px -4px 8px #000 inset;
border: none;
border-radius: 45px;
}
p a.button1 {
font-family: arial;
font-weight: bold;
font-size: 1.25rem;
color: #fff !important;
text-decoration: none;
text-shadow: 1px 1px 2px #000;
margin: 0 0;
}
p a:hover.button1 {
font-weight:normal;
background : whitesmoke;
color:#000 !important;
text-decoration: none;
box-shadow: 0px 4px 14px #000 inset;
text-shadow:none;
border: none
}
Simple Transition
Want to add animation to your buttons? Learn as much as you can about Transition and Transform
Button
The HTML
<p class="square">Button</p>
Use your imagination and experiment with the colors and size timing changes.
The CSS
p.square {
width: 6rem;
height: 6rem;
color : white;
background : red;
transition: width 2s, height 2s, background-color 3s;
}
p.square:hover {
width: 12rem;
height: 12rem;
background : dodgerblue;
}
The trend in web design today seems to have moved to long scrolling pages rather than multiple pages that require clicking. Some are even telling us that the click is dead. Personally, I believe we'll end up with a combination of the two.
Enter The Top Button and The Up Button
I can't imagine what a nightmare these endlessly scrolling pages of 10000+ words are for SEO!! May be the reason you don't see these Magnificent Masterpieces in the SERPS. Pay Google or sink into the BLACK HOLE!
Top
Very Basic HTML
<p><a href="#" class="top-button">Top</a></p>
💡 Time Out for a teaching Moment
In CSS, the !important declaration is used to give a specific style rule the highest priority, overriding any other conflicting rules, regardless of specificity or source order. It ensures that the style is applied no matter what.(From Copilot)
The CSS
p a.top-button {
/*Button*/
display : flex;
justify-content : center;
align-items: center;
position: fixed; /*Make it Stick to Viewport*/
bottom: 2rem; /* Define Position */
left: 1.5rem;
width: 3rem; /* Define Size */
height: 3rem;
background: dodgerblue;
border: solid 4px #ffff00;
border-radius: 50%;
box-shadow: 1px 1px 4px #000;
/*Button Text*/
font-family: Helvetica , arial, serif;
color: #fff !important ;
font-size: 1.125rem;
font-weight: bolder;
text-decoration: none;
text-indent:0;
text-shadow : 1px 1px 2px #000;
}
p a:hover.top-button {
color: #000 ;
background-color: whitesmoke ;
box-shadow: 1px 1px 4px #000 inset ;
text-shadow:none;
border: solid 1px #000;
}