35

339 Bytes of Responsive CSS

 5 years ago
source link: https://www.tuicool.com/articles/hit/RFjQzqN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

7 CSS declarations and a/an (optional) font import is all it takes to change a drab basic website to a minimalistic easy to read piece of beauty.

@import url('https://fonts.googleapis.com/css?family=Fira+Sans:300');
body {
  font-family: 'Fira Sans', sans-serif;
  line-height: 1.6;
  color: #222;
  max-width: 40rem;
  padding: 2rem;
  margin: auto;
  background: #fafafa;
}

Let’s go over this.

  • font-family sets a font for your webpage. In this case, it sets ‘Fira Sans’. Incase, ‘Fira Sans’ is unavailable, the page would take the standard sans-serif font.
  • line-height gives us some room between the lines, preventing it from looking like a wall of text and enhances readability.
  • color and background together reduce the text-to-background contrast making it easier on the eyes.
  • max-width with padding and margin restrict the content to a maximum of 640px, aligns it in the middle and makes sure that the text never hits the edges of the screen. And its even responsive. Looks good on mobile too!

Let’s add some flavor with some colors and making images fit in with the text.

img {
  max-width: 100%;
}
a {
  color: #2ECC40;
  text-decoration: none;
}
h1, h2, strong {
  color: #111;
}

These 4 CSS rule-sets together form a base for a simple, readable website. The best part about this code is that its completely class free and works well with default browser styles. It puts in perspective how much overengineering goes into building websites when people use Bootstrap for their blogs.

Browsers and CSS engines in them have come a long way since 2011 when Bootstrap was introduced. CSS styles are standard and consistent across browsers today and require minimal tweaking to work flawlessly. Bootstrap, Foundation, Semantic-UI etc. are great CSS frameworks and they have their own use cases. However, people tend to overuse them and that has led to websites being laden with ton of unnecessary CSS.

With just 339 Bytes and 20 lines of CSS, a reasonably good looking text heavy website can be designed. See it at work:Baserock.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK