Skip to content

Instantly share code, notes, and snippets.

@phloe
Forked from romannurik/centered_triangle.html
Created May 3, 2011 10:43
Show Gist options
  • Save phloe/953143 to your computer and use it in GitHub Desktop.
Save phloe/953143 to your computer and use it in GitHub Desktop.
A simple CSS trick to create a horizontally- or vertically-centered 'selected' callout triangle using zero images.
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 40px;
}
a {
display: inline-block;
height: 24px;
font-size: 24px;
line-height: 24px;
text-align: center;
font-family: helvetica, sans-serif;
text-decoration: none;
color: #000;
padding: 20px 60px;
background-color: #ddd;
margin-right: 2px;
position: relative;
}
a:target {
background-color: #333;
color: #fff;
}
a:target:after {
content: "";
display: block;
position: absolute;
bottom: 0px;
left: 50%;
margin-left: -10px;
width: 0;
height: 0;
border: 10px transparent solid;
border-top-width: 0;
border-bottom-color: #FFF;
}
</style>
</head>
<body>
<a href="#foo" id="foo">foo</a>
<a href="#bar" id="bar">bar</a>
<a href="#baz" id="baz">baz</a>
</body>
</html>
@romannurik
Copy link

Neat trick to use margin-left... nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment