Category Archives: Web Development Wilmington NC

A Sass Mixin for CSS Triangles

There is a very popular CSS trick consisting on using a mix of solid and transparent borders on a 0 width, 0 height element in order to fake a triangle. If you don’t know technique yet, you can find more information about it in the following articles:

While it comes with some quirks, it actually does the job well and has the benefit of being very compatible across the wide range of browsers we have to support.

Now the thing is, I never completely remember how to use this little piece of code. Which borders need to be transparent? Which one should be solid? I just can’t figure this out and I bet it’s the same for many of you as well. So this is typically the kind of thing you would like to automate using Sass.

There are probably as many CSS triangle Sass mixins as there are Sass developers. What if I showed you my own mixin to deal with CSS triangles/arrows in CSS?

What Do We Need?

Before digging into the code, it would be a good idea to check what we need in order to make a triangle out of CSS. First: a direction. We need to define a direction for our arrow, either top, right, bottom, or left. Also, what about a position? Like at 1.5em from the top, 100% from the left, for instance. Also we could define a color, and perhaps a size as well, although those 2 arguments could have defaults.

So in the end, our mixin is a short way for us to say Generate a triangle pointing to this direction, at this spot, in this color, and in the following dimensions. Sounds good, right?

Note that in order to avoid using extra markup, I like to use pseudo-elements for triangles. For instance:

.element {
  /* Container of some kind */

  &::before {
    /* Including triangle mixin */
  }
}

Using Our Toolbox

Last week, I wrote about some functions and mixins to kickstart your project. In case you haven’t read that article yet, go ahead. I’ll wait.

Okay, done? What if we reused some of our mixins in order to make this triangle mixin as sharp and clean as possible? For instance, we could use the size() mixin so we don’t have to define both the width and the height. We could also keep a consistent API for positioning stuff and make use of the absolute() mixin (more about that mixin here).

Continue reading %A Sass Mixin for CSS Triangles%

Advertisements

X509 Certficate Reading

Hi,

I’m attempting to read a clients certificate using the following c# code:

            var store = new X509Store(StoreLocation.CurrentUser);

            store.Open(OpenFlags.ReadOnly);

            var certificates = store.Certificates;
            foreach (var certificate in certificates)
            {
                var friendlyName = certificate.FriendlyName;
                var xname = certificate.GetName(); //obsolete
                Console.WriteLine(friendlyName);
            }

            store.Close();

The problem is that it is giving details for the certificate on the server that the ASP code is running.

Any ideas? I’ve tried changing the constructor to

            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
but I still can’t access it.

Learning to Hack – Part 4: End of Week 3

Kerry Mui is a student participating in the March cohort of the Web Development Immersive program. This article was originally posted on his blog. It is Part Four of his ongoing series documenting the Bitmaker Labs experience.

This week, we built our first web application using Ruby on Rails. The application was a simpler version of imgur, and allowed for basic functionality with photos: view, upload, edit details, and delete. Here are the things I learned this week.

Layers of Complexity

I was speaking with a classmate and we were amazed at how far we’ve come along. Concepts from a few weeks ago are now applied abstractly. It’s exhilarating to realize how quickly your mind can learn a new concept, then use it properly in a wider context. It’s a testament to the course material structure, by layering concepts carefully, so that the weekly climb is smooth. For example:

  • first, we focused on functions individually: what is this function?
  • next, we studied each function, learned its rules, and practiced in exercises: how do I use this function?
  • now, each function plays an individual role in the bigger picture of a web application: what can I do with this function?

In addition, understanding individual functions’ frees me to learn the Rails structure more holistically. I’m a visual learner  and learn best by understanding how concepts work in relation to each other, how a function “flows” through code, resulting in a program. It’s similar to how I no longer stop and think about each word when writing  a sentence; I focus on whether a sentence provides function and flow, resulting in a paragraph.

Attention to Detail

Sunset from a Bitmaker Labs Study Room.

Sunset from a Bitmaker Labs Study Room.

A painful part of learning to use Rails was the new syntax. Specifically, the bugs that come with unfamiliar syntax. There was a lot of re-reading my code and discovering a missed comma or something similar that was causing a program error. But, it’s all part of the learning process, and I managed to avoid the same errors when I redid an assignment. Practice, practice, practice!

I am reminded of a passage from Zed Shaw’s, Learn Ruby the Hard Way:

The one skill that separates bad programmers from good programmers is attention to detail. In fact, it’s what separates the good from the bad in any profession. Without paying attention to the tiniest details of your work, you will miss key elements of what you create. In programming, this is how you end up with bugs and difficult-to-use-systems.

Coding is Mainstream

This week, 4 friends (backgrounds in sales, business analysts, and medicine) told me they were learning how to code. Their interest levels varied: one was taking night courses in PHP & Javascript, another had taught herself some Python, and the remaining were dabbling with HTML/CSS. The dabblers sounded like me only a month or so ago: “I’m learning HTML & CSS, what should I tackle next?” It’s incredible seeing people learning programming as a hobby. Particularly since the perception of programming wasn’t the most positive, if only a few years ago. Again, here’s a passage from Zed’s Ruby course:

Finally, I’ll say that learning to create software changes you and makes you different. Not better or worse, just different. You may find that people treat you harshly because you can create software, maybe using words like “nerd.” Maybe you’ll find that because you can dissect their logic that they hate arguing with you. You may even find that simply knowing how a computer works makes you annoying and weird to them.

To this I have just one piece of advice: they can go to hell. The world needs more weird people who know how things work and who loves to figure it all out. When they treat you like this, just remember that this is your journey, not theirs. Being different is not a crime, and people who tell you it is are just jealous that you’ve picked up a skill they never in their wildest dreams could acquire.

You can code. They cannot. That is pretty damn cool.

Times have changed. Coding is mainstream. And it’s here to stay.

Curriculum covered this week: Ruby on Rails, Rails forms, SQL, ActiveRecord Associations, Testing

The Definitive Guide to Form Label Positioning

When it comes to the design and development of forms, one of the most popular topics is the positioning of labels. There are a range of different options, but many articles on the subject touch on only some of the advantages and disadvantages of some of these options.

How do you put all that disparate information together to make a good decision, especially if you’re in a hurry?

It was clearly time to bring everything together in one place. Read on for the different options for form label positioning, and the complete list of advantages and disadvantages for each.

If you haven’t got time for that, the main thing you need to know is: the most usable and accessible option is to have labels always visible, and located above or beside the field. There’s also a handy guide to choosing between these three options.

Options for positioning form labels

For English-based forms, the main options1 are:

  • label on top of the field:
  • label to the left of the field, and flush left:
  • label to the left of the field, and flush right:
  • label inside the field:
  • label as a tool tip:

Some of these choices are much better than others. Here’s the complete list of advantages and disadvantages for each approach.

Label on top of the field

Continue reading %The Definitive Guide to Form Label Positioning%

Prototype Mobile Apps Easily with Ratchet

It is difficult to prototype native Mobile applications using responsive web design technologies as they do not simulate native behavior. Developers often need to write tons of JavaScript to create single page architecture or use technologies such as Angular.js and Ember.js. There were a few developers who took this issue seriously and started working on […]

Continue reading %Prototype Mobile Apps Easily with Ratchet%

Using GNU Make as a Front-end Development Build Tool

The popularity of CSS preprocessors like Sass, and task runners like Grunt have made a build process an accepted part of front-end development. There’s no shortage of options or opinions in the task-runner/build-tool space, with the most popular being Grunt and Gulp. I write a decent amount of JavaScript at work and in personal projects, […]

Continue reading %Using GNU Make as a Front-end Development Build Tool%

Sass Mixins to Kickstart Your Project

Mixins are great, aren’t they? They are like functions that output CSS. According to the Sass docs:

Mixins allow you to define styles that can be re-used throughout the stylesheet without needing to resort to non-semantic classes like .float-left. Mixins can also contain full CSS rules, and anything else allowed elsewhere in a Sass document. They can even take arguments which allows you to produce a wide variety of styles with very few mixins.

Mixins are really convenient, especially when working on a large project. How many times have you had to define width and height values in your last project? How many times have you Googled how to do a triangle in CSS? Or haven’t you ever wished there was a shorthand for top, right, bottom, left when using CSS positioning?

You can solve all those problems with mixins. Even better: you won’t have to write them since I’ve already done that for you. Here we go guys, a couple of Sass mixins to kickstart your projects!

Sizing

I bet you already know this one. I use it as a mixin 101 in all my projects: a size() mixin defining both the width and the height. First argument is the width, second one is the height. If height is omitted, it falls back to the width value.

@mixin size($width, $height: $width) {
      width: $width;
      height: $height;
}

Simple enough.

Example Usage

Sass:

.element {
  @include size(100%);
}

.other-element {
  @include size(100%, 1px);
}

CSS output:

.element {
  width: 100%;
  height: 100%;
}

.other-element {
  width: 100%;
  height: 1px;
}

Positioning

If there is one shorthand I really think CSS misses, it’s a shortcut for offsets: top, right, bottom and left. We have shorthands for everything: padding, margin, background, even text-decoration! But we still don’t have one for offsets… So I built my own.

Continue reading %Sass Mixins to Kickstart Your Project%