Download Demo
A tutorial about creating good-looking context menu by using jQuery and css.
How to Use
Html
<link href=”//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css” rel=”stylesheet”>
<ul class=”contextMenu” hidden>
<li><a href=”#”><i class=”fa fa-home”></i> Homepage</a></li>
<li><a href=”#”><i class=”fa fa-sitemap”></i> Sitemap</a></li>
<li><a href=”#”><i class=”fa fa-envelope”></i> Contact</a></li>
<li>
<a class=”fa fa-facebook” href=”#”></a>
<a class=”fa fa-twitter” href=”#”></a>
<a class=”fa fa-google-plus” href=”#”></a>
<a class=”fa fa-linkedin” href=”#”></a>
</li>
</ul>
<span class=”demo”>
<i class=”fa fa-angle-right”></i> Right-click to see Context Menu</span>
CSS
@import url(http://fonts.googleapis.com/css?family=Roboto:400,300&subset=latin,latin-ext);
body {
background-color: #ffc107;
}
ul.contextMenu{
list-style:none;
margin:0;padding:0;
font: 300 15px ‘Roboto’, sans-serif;
position: absolute;
color: #333;
box-shadow: 0 12px 15px 0 rgba(0, 0, 0, 0.2);
}
ul.contextMenu *{
transition:color .4s, background .4s;
}
ul.contextMenu li{
min-width:150px;
overflow: hidden;
white-space: nowrap;
padding: 12px 15px;
background-color: #fff;
border-bottom:1px solid #ecf0f1;
}
ul.contextMenu li a{
color:#333;
text-decoration:none;
}
ul.contextMenu li:hover{
background-color: #ecf0f1;
}
ul.contextMenu li:first-child{
border-radius: 5px 5px 0 0;
}
ul.contextMenu li:last-child{
background:#ecf0f1;
border-bottom:0;
border-radius: 0 0 5px 5px
}
ul.contextMenu li:last-child a{width:26%;}
ul.contextMenu li:last-child:hover a{color:#2c3e50}
ul.contextMenu li:last-child:hover a:hover{color:#2980b9}
/* DEMO STYLES */
span.demo{
font: 300 35px ‘Roboto’, sans-serif;
display:table;
margin:30px auto;
color:#212121;
}
JS
$(document).bind(“contextmenu”, function(event) {
event.preventDefault();
$(“ul.contextMenu”)
.show()
.css({top: event.pageY + 15, left: event.pageX + 10});
});
$(document).click(function() {
isHovered = $(“ul.contextMenu”).is(“:hover”);
if (isHovered == false){
$(“ul.contextMenu”).fadeOut(“fast”);
}
});
code examples to make your html website
ReplyDeleteHeader tag color font-family in html