Tuesday, March 31, 2015

Remove hover from named anchors in HTML5

Top of this post - a named anchor with an unintended :hover effect.

I want :hover on links (anchors with a href attribute), but not on named links (anchors with a name attribute).

I use :hover to make links change color when the mouse hovers over them, for example, hover your mouse over this link: link to :hover on w3Schools. However, I also have named anchors on my site (e.g. <a name="top_of_post">Top of this post - etc ...</a>) so that I can link to parts of the page (e.g. click this link to go to the top of this post i.e. to my named anchor). Hover your mouse over the anchor above (at the top of this post - the text that says "Top of this post - etc ...") and you will see that it gets :hover as well, because it is an anchor tag.

Both of these use the anchor tag, but only one of them is an actual link. I want :hover on the links (<a href="http:/www...">) but not on the anchors (<a name="top_of_post">).

The page A:hover and named anchors has a fix for this. Create a CSS rule that will reverse :hover for anchor tags with a name attribute:

a:hover {text-decoration: underline; color: red; background: yellow}
a[name]:hover {text-decoration: inherit; color: inherit; background: inherit}

This works nicely, except that in HTML 5, the name attribute on anchor elements is marked as obsolete. It is recommended that you use the ID attribute instead of NAME. I could change that CSS rule to use a[id]:hover instead of a[name]:hover, but that presents a new problem. I will use ID in anchor tags for many reasons, not just to create named anchors. I certainly do not want to remove :hover effects from all anchor tags that I might give an ID to.

So, the fix I now use for HTML 5 is to create a class for named anchors. It isn't as nice because I have to modify my code, but at least I can easily do a global find all <a name=" and replace with <a class="namedAnchor" id=".

a:hover {text-decoration: underline; color: red; background: yellow}
a.namedAnchor {text-decoration: inherit; color: inherit; background: inherit}

And now I have named anchors with no :hover.

Bottom of this post - a named anchor with no :hover effect.

Monday, March 02, 2015

Using historical data to determine how long local maven builds take

As part of an exercise in putting together a business case for JRebel licences, a colleague asked me how long do my builds take on average. Well, because I have been using my own wrapper around maven (bash shell or Windows batch) to store the build logs, I was able to say exactly how long each particular build command had taken on average.

The longest builds, for example:

Average Time in Seconds Number of Runs Command
682.09 23 mvn -T1C -Plocal clean compile deploy
518.68 31 mvn -T1C -Plocal -DdisableDojoProdBuild -DdisableGWTBuild -DdisableJspCompile clean deploy

I generate my results from this Maven utility class I wrote: MavenBuildTimes.java, available within the same git repo that the maven wrappers are within. All you need to do is adjust the path to the log directory and you can run it across your own build logs too!