Create Our Own CSS Frameworks part-5

in utopian-io •  7 years ago  (edited)

What Will I Learn?

  • Make Button
  • Make Flexible Color
  • Create Button Variations

Requirements

Difficulty

  • Intermediate

Tutorial Contents

Make Button

Buttons are very important in user interaction on our website. We will make our own button. The first step that we should do we must create a default button.

  • Default Button
    Before we create a button, we should create a variable to store the size of the font and the base color of the default button.

Why we must declaration variable?

When we build CSS frameworks, we have to think flexibly so that our CSS can be modified easily, so we must save important properties that we can change the value at any time. so if there is a change we do not need to change it one by one. we only need to change the variable where the property is stored

Variable declaration:


$font-default: 14px
$grey: #bebebe

  • $font-default: This the name of variable and the 14px is the value of font size. You can change the value you want.
  • $grey: This the name of variable and the #bebebe is the value of hexa color. You can change the color and change the variable name but keep relevant with the name of the variable.

SASS :


.button
    font-size: $font-default
    border: 1px solid $grey
    background: white
    padding: 10px
    border-radius: 5px
    &:hover
        cursor: pointer
        color: white
        background: $grey

  • .button: This is the class name we will use for the button .
  • border: 1px solid $grey: Because we have declared the variable. we can use it like this.
  • &:hover: We can use hover effect like this &: hover, and write down the css under &: hover.

HTML:

<button type="button" class="button">Default</button>

We can use the class .button in the element < button >.

Result:

Button Default

Screenshot_16.png

Button Default Hover

Screenshot_19.png

Create button variations

To create some button variations. we need to use variables to store the values of each variable.
I will create 3 background colors to represent the button type.

  • type success: background-color #73c000
  • type warning: background-color #ffe249
  • type danger: background-color #ba3838

Variable declaration:


$success: #73c000
$warning: #ffe249
$danger: #ba3838

SASS:


.success
    background: $success
        color: white
.warning
    background: $warning
        color: white
.danger
    background: $danger
        color: white

  • .success: This is the class name that we will use in the element < button >. and the value we save in variable $success.
  • .warning: This is the class name that we will use in the element < button >. and the value we save in variable $warning.
  • .danger: This is the class name that we will use in the element < button >. and the value we save in variable $danger.
  • color: white: The color of text in button is white.

HTML:

<button type="button" class="button success">Success</button>
<button type="button" class="button warning">Warning</button>
<button type="button" class="button danger">Danger</button>

We can add a class with the class name class="button classname" we have created in SASS.

Result:

Screenshot_20.png

Create button size variations

Button size variation is also an important thing. we will make the size into 2 types.

  • type small: font-size 14px
  • type large: font-size24px

Variable declaration:


$large: 24px
$small: 14px

SASS:


.small
    font-size: $small
.large
    font-size: $large

  • .small: This is the class name that we will use in the element < button >. and the value we save in variable $small.
  • .large: This is the class name that we will use in the element < button >. and the value we save in variable $large.

HTML:

<button type="button" class="button large">Large</button>
<button type="button" class="button small">Small</button>

We can add a class with the class name class="button classname" we have created in SASS.

Result:

Screenshot_21.png

We have made the element button become more flexible and can be modified easily in the future. you can adjust the color or size of your own button. Hopefully this tutorial useful for you. Thank you.

Curiculum



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for your contribution, yet it cannot be accepted.

  • While I like the ideas you are presenting, yet please make sure to include more detailed concepts in each of your tutorial sessions.
  • You can also improve on some of the concepts you already mentioned, or some of the code that you just went through quickly. For example referring to the "&:hover" part. You could have explained this and given an example in the same session
  • Also improve some of the language you use in your tutorials, as some of it has mistakes or incorrect language usage.
  • And try to include in the title of your tutorial what the session will be about, this will make things easier for anyone checking your sessions to know what to check.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Could i edit my contribution?