Posts tagged with ‘development’

Things about CSS that make me want to put my face in a blender

Tags:

Padding

When you enter a margin value such as:

margin: 12% 24%;

the vertical value is taken as a percentage of the height of the parent and the horizontal value is taken as a percentage of the width of the parent. This makes sense.

If I enter the same values as padding:

padding: 12% 24%;

the vertical value is taken from the width of the element (horizontal), and the horizontal value is taken from the height of the element (vertical). This is stupid.

The only time this has ever been of any use to me whatsoever in four years of writing CSS has been when forcing the aspect ratio of an element like so:

height: 0;
padding: 0 0 50%;  /* Forces a 2:1 aspect ratio. */

You know what would be far more useful? Make the horizontal and vertical the right way around, and give us an aspect ratio property. Not only would this make aspect ratios an actualproperthing™ rather than a hack, it also allow us to finally vertically center things properly.

/* 25% of the element's height will be
    whitespace above and below its children,
    making them vertically centered (Hurrah!) */
padding: 25% 0;

/* The elements width will be double that
    of its height, which is determined by
    the flow of content. */
height: auto;
width: auto;
aspect-ratio: 1 2;

Exes and Whys?

margin: Y X;
padding: Y X;
border: Y X;
outline: Y X;
background-position: X Y;
transform: translate(X, Y);
transform: scale(X, Y);

Why, dear God, Why???

Fixed positioned elements

I set some elements at a certain size.

.parent {
  width: 50%;
}
    .parent .child {
      width: 30%;
    }

.child is 30% of the width of it’s parent. Nice and easy. Then I add position: fixed; to the child.

.parent {
  width: 50%;
}
    .parent .child {
      width: 30%;
      position: fixed;
    }

Boom! .child has now doubled in width. That makes sense doesn’t it? No.

Borders

I only ever use solid borders, because anything else is harder to see than a true word in the Daily Mail.

I want to write

border: blue;

and have it give me a 1px wide, solid blue border.

border: 5px blue;

gives me a 5px, solid blue border. Easy peasy.

Posititioning

background-position: top center;

is a nice easy way to position a background. At the moment, to absolutely position an element in this way, I have to do this:

width: 300px;
position: absolute;
top: 0;
left: 50%;
margin-left: -150px;

If the width is dynamic, the above is impossible without a javascript hack. This would be better:

position: top center;  /* Boom! */

I build my own tools, and you should too

Tags:

Originally published on Everyday Designer

Sharing makes the web a better place. Thousands of hours of design and development time are put in each week, creating resources for the community to use; and use them they do. You can’t visit a site nowadays that isn’t using a free, open-source tool of some sort. Bootstrap? Check. jQuery? Check. WordPress? You betcha.

They’re all great resources, that allow you to throw yourself into a new project without having to think too much about the technical aspects of what you’re doing – as such, beginners love them. But what happens when you want to stop being a beginner and start taking control of the code you’re writing?

Last year I released a CSS grid framework called Melody. As I’m now working on version 2, I wanted to explain my experiences building and releasing a resource that other people now use, and why I think it’s something you should do yourself.

Why bother?

There are thousands of other frameworks out there, so why did I decide to build my own?

First of all, I was jumping between frameworks the second a new one came out. Why? Because the ones I was using didn’t really meet my needs, they all involved compromises. I wanted something to allow for really quick prototyping, that was still flexible and robust enough to be used as production code.

Second, rather than relying on something magical to do my work for me, I wanted to really understand what was going on beneath the surface.

And lastly, I wanted to give something back to a community that has happily given away free resources for years, without which I would never have been able to learn my craft.

What did I learn?

I learnt a lot.

I learnt the importance of separating and commenting my code so that it’s easily accessible to others – something I’d always been terrible with. Developers are a fussy bunch and if your code is not up to scratch, they’ll tell you. This kind of feedback is invaluable for a rookie.

I learnt about specificity, and finding better ways to write non-invasive code so that the framework doesn’t interfere with the code of the app or site that’s built on it. If you’re having to modify a framework to get it to work for you, or implement hacks to override portions of it, you’d be better off not using a framework in the first place.

I learnt about proper typesetting using a baseline in order to add some useable typographic styles to the framework. The rules I used can be applied to design of all kinds, not just the web, and using them has hugely increased the quality of my work.

And finally, I learnt about optimisation, and trying to do as much as possible with as little code as possible. The current version of Melody is just 8kb before minification. The new version is even smaller. The small file size makes a huge difference when you’re serving content over a slow connection.

What else is good?

Aside from the great learning opportunity, there have been other benefits too. It’s got me some valuable exposure, and it looks great in my portfolio. I’ve had one client tell me outright that it was the deciding factor in me getting a job – creating a tool rather than just using one shows that you really understand what you’re doing.

Developing the framework has also sped up my workflow. Because I built it, I know the best ways to implement it. I very rarely wireframe any more – in the traditional sense at least – instead opting to whip up a layout in CSS just as quickly, which gives me a real, responsive prototype to show to my clients.

And by far the best part is that I’ve met some great people, who having used Melody, want to show me the sites and apps that they’ve built with it, and to say thanks. It feels great to know you’re helping people make awesome stuff.

It’s not all rosy though…

As with any released tool there’s the inevitable wave of support requests. Generally, I enjoy dealing with these but on days when I’ve already got a full inbox to deal with, it does add to the pressure.

There’s also the risk of complacency. Having spent time developing the framework, I now jump straight into using it, even for those projects where it may not be the best fit. No matter how good a developer you are, there’s no such thing as a one-size-fits-all solution. You’ll still have to compromise or modify your tool occasionally, but having built it yourself, you’ll know straight away how and where to do it.

So what’s next?

Since taking the plunge, I’ve built and released a number of other tools. Whereas before I’d look for a tool or a plugin to solve a problem, I now try and develop my own solutions first.

If you can think of anything you need, no matter how small, find the time, and build it.

It doesn’t matter whether you release it to the public, because most of all, it’s about taking control of the code you’re writing. When you’re working on a project with a tight deadline, you don’t want to be wasting time filing bug reports or support requests. Use code that you’ve written yourself, and therefore understand, and instead of relying on a third party to help you get out of a problem you can just dive in and fix it yourself.

You’ll learn a ton of new stuff and make your life a lot easier in future.


Frameworks

Tags:

There are plenty of programming languages out there. Everyone has their favourite, and many, like me, probably have a list as long as their arm of languages they’d like to learn. Every language has a selection of frameworks, designed to make them easier to build apps with. Many are incredibly useful. jQuery for instance, has taken the web design world by storm, and it’s quite rare to see a site nowadays that doesn’t make use of it. Laravel and CodeIgniter for PHP are very highly regarded, as is Rails for Ruby development.

The problem is, with many of these, it’s easier to learn and use the framework than it is to use the base language itself. I myself was guilty of this when I first started learning jQuery many years ago. It’s only within the last year that I’ve taken the time to actually learn and understand the JavaScript code underneath it. And you know what? Since doing that I’ve found that in a number of instances, where before I would have jumped straight into jQuery without thinking, I now use vanilla JavaScript as much as possible.

The same can be said for other languages. The best way to learn how to use a language is to learn the vanilla language first. With PHP, if you jump straight into Laravel or CodeIgniter, you’ll likely be lost when looking at vanilla PHP and trying to use one of the additional functions from the framework. All my PHP and Ruby development is done vanilla, no framework. I simply don’t currently work on applications on the sort of scale at which a framework would give me any benefit. That doesn’t make me a bad person.

Learn the language first, and any of the frameworks will be almost second nature, and you can choose the right tool for the job, rather than relying on a huge framework when all you need are a few simple server-side calls.

Frameworks should be a tool allowing you to do the best job you can, not a mandated starting point.