Friday 22 April 2016

Styling Links with IDs and Classes

As mentioned recently in Project 01: Recreating the Telegraph, I've been struggling to wrap my head around the CSS behind using the <a> tag in conjunction with id and class attributes. I was able to get the functionality to work (somewhat) flawlessly when using the id, but with a class, I had no such luck when trying to apply the same methodology. The thing is, they don't work the same way one bit.


Well, they do kind of work the same way, just a tiny bit backwards. 

Referencing from within an id

When referencing an <a> element within an id, you need to put the id first. For example:

  #navigation a:link, #navigation a:visited {
  color: red
  }

Add a space between the id and the element selector and separate multiple selections with a comma and a space. This will work because the chain for id's is:

  #id > element selector > decoration

The catch is, the id tag must not be placed within an <a> element, it needs to be coded within a parent tag. The code simply doesn't run if the id is placed within the <a> tag because it is then referencing and invalidating itself. 

Referencing from within a class

When referencing an <a> element within a class, you need to put the class name second. For example:

  a:link.navigation, a:visited.navigation {
  color: red
  }

There should be no spaces between the element selector and the class name. Multiple selections should be separated with a comma and a space. My best guess for why the specificity has to be ordered this way is to account for syntax errors if the values were reversed, or had spaces, it would change their meaning entirely. The chain for classes is:

   element selector > .class > decoration

With this approach, the class must be defined within the <a> tag, as to correctly reference itself. 


While perhaps still a bit blurry around the edges, ordering the syntax in the manner does call correctly. For anyone interested in seeing these methods in action, you can simply copy this code here:

Sunday 17 April 2016

Project 01: Recreating the Telegraph - The Results Are In

While I am under no illusion that this is a perfect mimicry of the actual Telegraph site design, I feel comfortable enough here, to hang up my hat and call it a day on this project. Working by eye (besides the use of the Photoshop colour-picker tool) is never easy, even more so when it comes to sizes, positioning, widths, etc. As you can see, there are some clear alignment errors - the majority of which, I tried to fix and failed.

Original article: The Telegraph - 15 Maps That Will Change the Way You See the World
For me, padding, border, margin is the clincher. W3Schools has a very clear diagram of this here, but I'm still struggling to visualise this in practice. I have most clearly failed in this area in with the ordered list within the article. 

position and float are also two concepts I'm struggling to apply. The distraction of the content definitely isn't helping, so it's probably worth making a playground where I can test all the function of these elements correctly.

Designing and formatting the list numbers in CSS was the most fun part, as it gave the richest reward. To think up a method of creating circular borders (using the border-radius tag with a high value), see it work, then inspect the actual CSS and find it was originally created using a similar method is very rewarding indeed. While mine may be a little rough round the edges, it is fit for purpose. 

Once again I'm supplying the HTML/CSS here. I think it's always worth sharing for the shake of learning and evolving. Even if it is learning through not what to do. I haven't seen any good HTML/CSS to know if mine is well-written, well-formatted, correct use of specificity, or class/id overload, but I can safely say that it's probably not. If it's bad, it's bad, but these are all skills to develop.

Friday 15 April 2016

Project 01: Fighting the Link Formatting

As mentioned previously, I found the task of styling elements that doubled up as an <a> tag to be a tricky task indeed. I still feel that way, so instead of taking on the whole beast with one swing, I decided to extract the "Read More" section of The Telegraph and work on that singularly. It definitely helps, and what I came up with wasn't perfect, but it was definitely a lot more manageable.
While I'm sure any untrained eye can spot the difference (mimicking formatting is proving hard) the key task of getting these links to colour and hover correctly worked like a charm. Using specificity seemed key to success here (thank you, Khan Academy CSS Specificity). While I'm sure it would be more beneficial to up my class game, using definitions such as ol li { } gave me the right amount of control.

I've pasted the code I made for this into a Paste Bin (also included below) for anyone to nosey at. I'm happy enough for now, but that's still not happy enough. I will integrate this mini-project into my main code and go from there.
 

Thursday 14 April 2016

Project 01: Recreating The Telephraph

While I'm not one to be found nose-deep in a broadsheet, let alone The Telegraph, I have to admire the simplicity of their site design, especially when learning to recreate existing CSS content. At least that what I expected this project to be like, but when I finally got pen to paper, I realised just how wrong I was.


A job like this takes a lot of planning, and the nuances within the design have proven to be unexpectedly complex. I've struggled with defining the number of <div> elements I require, scared to add more as the list of classes and tags extends longer and longer. Editing headings and other elements that also double up with the <a> tag has also been difficult - having to style a:link, a:visted, a:hover sometimes individually and sometimes not picking up changes at all. Furthermore, trying to style the numbers in a list seemed near impossible until I found this nifty tutorial which instead utilised the <span> tag (Design Shack - 5 Simple and Practical CSS List Styles You Can Copy and Paste).

While I haven't looked around yet, it would also be nice to have a colour-picker desktop app - no more copying images into Photoshop, thank you very much. I suspect there might be a tool out there for this, if not, hold that thought!

The article in particular that I'm trying to mimic is the 15 maps that will change the way you see the world travel piece. It contains a lot of images, lists, links and interesting formatting qualities. I thought it would prove an interesting challenge while not been beyond my range.
At first glance, I'm not sure if my current attempt would fool anyone, but the building blocks are definitely in place. As you can clearly see, I'm struggling with the positioning, trying to wrap my head around absolute and relative, margin and padding in particular. 

There are also the colouring issues I mentioned when dealing with an element that is both a heading/p element and a <a> tag. For reasons I don't yet understand, their style only applies correctly on hover. 

As a first pass, I'm happy to keep banging my head against the wall until I get to the bottom of this. I hope, by the next major update, to have fixed the positioning and link colouring issues. 

Tuesday 12 April 2016

Hello World

I recently uncovered that I started coding in my teenage years. Coding is a loose term for it, but it was using code nonetheless. Specifically HTML. It all started with an Avril Lavigne fan-page, which featured far more animated .gifs than is ever necessary. I would make a lot of little sites and blogs within different hosting sites and append, modify and implement my own code.

While it hardly stretched beyond copy and paste and adding a few of my own <strike> and <button> tags here and there, I was still playing with advanced tools to help reconstruct my websites to how I wanted them to be. 

Never once did I realise that the tools I were using were HTML. I've recently reinitialised that fire for web development and wish to study HTML and CSS, eventually moving on to JavaScript and whatever next.

This blog is designed to document my progress, learnings and findings. Having just completed the Intro to HTML/CSS: Making Web Pages on Khan Academy, I feel like I'm just about equipped enough to try my hand at evaluating and reconstructing existing websites. Just. 

The Khan Academy course is an amazing course to kickstart your HTML/CSS education.