Lecture Seven

Images and Things Like Them

Some Exercises to Reinforce Positioning

Turn to pages 367 and 368. The thing to remember is that absolute positioning works with respect to the containing element — and that that containing element has to have a position of relative if not the document. This is the difference between tab 3 and 4 in the demo linked below.

http://www.barelyfitz.com/screencast/html-training/css/positioning

The tooltip styles to override in our style.css

.tooltip {
    display: block;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 12px;
    font-weight: normal;
    line-height: 1.4;
    opacity: 0;
    position: absolute;
    z-index: 1070;
}
.tooltip.in {
    opacity: 0.9;
}
.tooltip.top {
    margin-top: -3px;
    padding: 5px 0;
}
.tooltip.right {
    margin-left: 3px;
    padding: 0 5px;
}
.tooltip.bottom {
    margin-top: 3px;
    padding: 5px 0;
}
.tooltip.left {
    margin-left: -3px;
    padding: 0 5px;
}
.tooltip-inner {
    background-color: #000;
    border-radius: 4px;
    color: #fff;
    max-width: 200px;
    padding: 3px 8px;
    text-align: center;
    text-decoration: none;
}
.tooltip-arrow {
    border-color: transparent;
    border-style: solid;
    height: 0;
    position: absolute;
    width: 0;
}
.tooltip.top .tooltip-arrow {
    border-top-color: #000;
    border-width: 5px 5px 0;
    bottom: 0;
    left: 50%;
    margin-left: -5px;
}
.tooltip.top-left .tooltip-arrow {
    border-top-color: #000;
    border-width: 5px 5px 0;
    bottom: 0;
    margin-bottom: -5px;
    right: 5px;
}
.tooltip.top-right .tooltip-arrow {
    border-top-color: #000;
    border-width: 5px 5px 0;
    bottom: 0;
    left: 5px;
    margin-bottom: -5px;
}
.tooltip.right .tooltip-arrow {
    border-right-color: #000;
    border-width: 5px 5px 5px 0;
    left: 0;
    margin-top: -5px;
    top: 50%;
}
.tooltip.left .tooltip-arrow {
    border-left-color: #000;
    border-width: 5px 0 5px 5px;
    margin-top: -5px;
    right: 0;
    top: 50%;
}
.tooltip.bottom .tooltip-arrow {
    border-bottom-color: #000;
    border-width: 0 5px 5px;
    left: 50%;
    margin-left: -5px;
    top: 0;
}
.tooltip.bottom-left .tooltip-arrow {
    border-bottom-color: #000;
    border-width: 0 5px 5px;
    margin-top: -5px;
    right: 5px;
    top: 0;
}
.tooltip.bottom-right .tooltip-arrow {
    border-bottom-color: #000;
    border-width: 0 5px 5px;
    left: 5px;
    margin-top: -5px;
    top: 0;
}

The syntax to add a tooltip to an element

data-toggle="tooltip" data-placement="top" title="Hooray!"

Finally the script to make it all work.

<script>
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
});
</script>