         if fontSize >= 20
           link.setAttribute linkLargeAttrName, ''
 
-        id = container.getAttribute linkContainerIdAttrName
+        id = container.getAttribute containerIdAttrName
 
         if id
-          linkContainers[id].links.push link
+          containers[id].links.push link
         else
           id = uniqueLinkContainerID()
-          container.setAttribute linkContainerIdAttrName, id
-          linkContainers[id] =
+          container.setAttribute containerIdAttrName, id
+          containers[id] =
+            id: id
             container: container
             links: [link]
 
   styles = ''
 
-  for id, container of linkContainers
+  containersWithPrecedence = sortContainersForCSSPrecendence containers
+
+  for container in containersWithPrecedence
     linkColors = {}
     linkColors[getLinkColor link] = true for link in container.links
 
     backgroundColor = getBackgroundColor container.container
 
     for color of linkColors
-      linkSelector = """[#{ linkContainerIdAttrName }="#{ id }"] a[#{ linkColorAttrName }="#{ color }"]"""
+      linkSelector = """[#{ containerIdAttrName }="#{ container.id }"] a[#{ linkColorAttrName }="#{ color }"]"""
       linkSmallSelector = """#{ linkSelector }[#{ linkSmallAttrName }]"""
       linkLargeSelector = """#{ linkSelector }[#{ linkLargeAttrName }]"""
 

linkColorAttrName = 'data-smart-underline-link-color'
linkSmallAttrName = 'data-smart-underline-link-small'
linkLargeAttrName = 'data-smart-underline-link-large'
linkContainerIdAttrName = 'data-smart-underline-container-id'

performanceTimes = []
time = -> + new Date

destroy = ->
  styleNode.parentNode?.removeChild styleNode

  for attribute in [linkColorAttrName, linkSmallAttrName, linkLargeAttrName, containerIdAttrName]
    Array::forEach.call document.querySelectorAll("[#{ attribute }]"), (node) ->
      node.removeAttribute attribute

