Git Product home page Git Product logo

js-dom-and-events-css-libraries-readme-cb-000's Introduction

Introduction to Basscss

Objectives

  1. Explain how classes guide our approach to styles
  2. Describe the main components of Basscss

An empty canvas

When creating an application, we sometimes start our styling from scratch. Another way of styling our application, though, would be to use frameworks โ€” CSS that has already been written for us. By doing so, we don't have to write any (or much, at least) CSS ourselves. This is both a blessing and a curse: we save a lot of time by following the conventions and styling of the framework, but we give up customizability.

Usually, CSS frameworks are used to either quickly mock up a front-end for an application prototype, or if the developer isn't particularly inclined to write their own CSS. Since CSS is kind of out of scope for this course, we'll stick to using frameworks for now. This will allow us to completely focus on our JavaScript, instead of fiddling too much with HTML and CSS. This lesson focuses on showing the high-level features of Basscss โ€” feel free to use the links below to explore at your own pace.

Staying classy

Classy Tom Hanks

Frameworks provide us with a whole slew of classes that we can use to style our application. Classes allow us to reuse styling across several components. There are usually also utility classes that provide us with handy styles, like aligning text, rounding corners, and so on.

Basscss

Basscss is a very lightweight CSS framework that focuses on sane defaults and more complex layout possibilities. It's not an all-in-one framework like Bootstrap or Foundation, but it will help us to help lay out the application in a better way. It doesn't make our buttons look fancy or anything like that, but we're not concerned with that right now.

Typography

Basscss has default styles for all typographic elements (<p>, <h1>, <h2>, <ul>, and so on). Less styling to worry about!

Grid

The grid in Basscss uses a standard 12-column layout system that can also be found in Bootstrap, Foundation and other frameworks. Since we're trying to stay ahead of the curve though, we'll forego this grid in favor of the flexbox layout, which will solve most of our problems.

Flexbox

Flexbox is a relatively new concept that more and more developers are starting to use. It allows for powerful layout solutions that can't be achieved using traditional layouting techniques (that use floats, much like the grid found in Basscss). Basscss provides us with handy layout classes that we can use to quickly create any kind of layout we want. In a nutshell, we can tell elements using flexbox to stretch or shrink, or to align themselves if needed. This abstraction is very powerful, and was super complicated to do before the arrival of Flexbox. Welcome to the (almost) golden age of web layout!

Scooby Doo's Nametag

Let's play around with Basscss a bit! Scooby Doo needs a new nametag, and we just happen to need some practice with our new CSS framework. A match made in heaven! This is what our end result will look like:

Scooby Doo's nametag

First of all, let's add Basscss to our project. We can include a link tag directly to the source in between <head> and </head>:

<link href="https://npmcdn.com/[email protected]/css/basscss.min.css" rel="stylesheet">

That was easy. Now let's add a div to the body with a capped width at 300px. Usually we don't have to do this, but since we're starting from scratch, we need to cheat a little to get going. Otherwise, our nametag would take up all available width (i.e. the entire browser)!

<body>
  <div style="width: 300px">

  </div>
</body>

Now that that's done, we'll add the container for our nametag that holds all other components:

<body>
  <div style="width: 300px">
    <div class="flex">

    </div>
  </div>
</body>

Yay, flexbox! Next, we'll add Scooby Doo's image, as well as his name and job title.

<div style="width: 300px">
  <div class="flex">
    <img src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">
    <div>
      <h1>Scooby Doo</h1>
      <small>Pet Detective</small>
    </div>
  </div>
</div>

step 1

Hmm... well, we're slowly getting there, but not quite yet. First things first, let's add a rounded border to our flex container:

<div style="width: 300px">
  <div class="flex border rounded">
    <img src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">
    <div>
      <h1>Scooby Doo</h1>
      <small>Pet Detective</small>
    </div>
  </div>
</div>

step 2

Now we'll remove any existing margins on the title, and align items in the center:

<div style="width: 300px">
  <div class="flex items-center border rounded">
    <img src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">
    <div>
      <h1 class="m0">Scooby Doo</h1>
      <small>Pet Detective</small>
    </div>
  </div>
</div>

step 3

We don't want the image to take up more space than it should, so let's add a flex-none class to make it shrink:

<img class="flex-none" src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">

The text is kind of pushed up against the image... Let's fix that by adding a bit of right margin to the image:

<img class="flex-none mr1" src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">

step 4

Great! As a finishing touch, we'll use one of Basscss' typographic utilities, .caps, to make our job title appear in uppercase letters:

<small class="caps">Pet Detective</small>

step 5

And that's it! Here's the full code for the nametag:

<div style="width: 300px">
  <div class="flex items-center border rounded">
    <img class="flex-none mr1" src="http://i.imgur.com/KveOp9g.png" alt="Scooby Doo">
    <div>
      <h1 class="m0">Scooby Doo</h1>
      <small class="caps">Pet Detective</small>
    </div>
  </div>
</div>

We just created a visual component that looks kind of custom, without writing any CSS ourselves. Pretty neat, huh? Feel free to dive into Basscss' documentation to learn even more, so your applications can take on a whole new look!

Resources

js-dom-and-events-css-libraries-readme-cb-000's People

Contributors

drakeltheryuujin avatar maxwellbenton avatar pletcher avatar gj avatar lizbur10 avatar rrcobb avatar thomastuts avatar

Watchers

James Cloos avatar  avatar  avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Matt avatar Antoin avatar  avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.