Rules to Better UI (Bootstrap)
Twitter Bootstrap & ASP.NET MVC - Intro / Quickstart with Ben Cull
In this video, Ben Cull walks us through Bootstrap, how it impacts your development experience and how to get the most out of it to produce functional and visually pleasing solutions.
Writing CSS is easy. Writing a lot of CSS can become unwieldy and unmanageable. Using CSS pre-processors like LESS or SCSS helps you segment and organize your CSS logically and compiles down to regular CSS so there are extra steps to get up and running.
The key advantage of using CSS pre-processors is nested selectors. Instead line after line of specific CSS selectors you can nest them and they will compile down for you. Check out this example:
- Bad Example: Using regular CSS, you repeat yourself a lot
- Good Example: Using LESS, we can structure our CSS better
The pre-processed CSS then compiles to the regular CSS shown above.
We recommend using SCSS for its slightly more robust language scripting, however, the differences between LESS and SCSS are minor.
Bootstrap provides a powerful, responsive layout with its rows and columns.
When designing a responsive website, you need to make sure that the browser understands how to correctly render your website. Device-Width informs the browser what the size of the viewport should be.
Since we want our website to render corectly for all screen sizes, we specify that it should set the viewport to the size of the device's screen.
<meta name="viewport" content="width=device-width" />
This ensures the browser always renders at the correct resolution for the device.
When designing responsive websites, it's important to consider what content is appropriate for each screen size. Desktops might have large navigation areas and extra content in a sidebar, whereas the phone might focus on other content.
By default, bootstrap will wrap the columns and make them full width on phones. If you want to hide content rather than let it wrap you can use the following classes:
As well as being able to hide content per view, you can also selectively show it. This is helpful to add an extra sidebar for very large screens.
- Bad Example: The mobile view on the right has a large unneccessary title.
Remove the title by adding the .hidden-xs class.
- Good Example: The mobile view is now leaner and cleaner thanks to our .hidden-xs class.
By default, we do not accommodate IE8 or lower, but should it arise as a specific requirement, then you can include Respond JS in your application, after Bootstrap. Respond JS enables responsive web designs in browsers that don't support CSS3 Media Queries.
- Figure: Include respond.js in your bootstrap bundle
Note: Respond JS will be included in a new MVC5 Web Application. If you are working on an existing application, you can get it from NuGet or https://github.com/scottjehl/Respond.
- Figure: A new MVC5 Web Application running in IE8 with Bootstrap and Respond JS
When building a web application, it is common that you will need icons in the UI. Traditionally, this has been done with images (e.g. png, jpg) which leads to a lot of resource management.
- Figure: Bad example - using images for application icons can generate a lot of pain
This is simplified if you are using Bootstrap, as it comes with a font-based icon library you can use in your web application. However, there is an even better third-party font-based icon library you should use when using Bootstrap:
Font Awesome provides scalable vector icons that can be customized purely through CSS and some are completely free for commercial projects. This is great if you’re tight on implementation deadlines and need generic icons in a hurry. In the ideal world, a specifically custom-designed icon set is the way to go.
Using it on your project is easy, just use your email and register on their website: Get Started. Then you will be able to download and serve locally or use a CDN.
There are hundreds of icons. Here are a few commonly used ones:
- Figure: Examples of Font Awesome icons
"Basic Use" documentation