Thursday, 2 July 2015

Amazing Bootstrap 3D Buttons Effects in XPages

In this blog post I will show how with a CSS3 stylesheet Bootstrap buttons can be displayed with a 3D effect in XPages. I got this by a former colleague who had seen this on the internet. It is very easy to implement in XPages. I think it looks nice. The end result looks like the example below.


Create Stylesheet
First the following CSS3 file must be created in the XPages Application (Resources - Style Sheets - New Style Sheet).

.btn3d, .btn3d:focus {
position:relative;
top: -6px;
border:0;
-moz-outline-style:none;
outline:medium none;
transition: all 0.04s linear;
margin-top:10px;
margin-bottom:10px;
margin-left:2px;
margin-right:2px;
}
.btn3d:active, .btn3d.active {
top:2px;
}
.btn3d.btn-white {
color: #666666;
box-shadow:0 0 0 1px #ebebeb inset, 0 0 0 2px rgba(255,255,255,0.10) inset, 0 8px 0 0 #f5f5f5, 0 8px 8px 1px rgba(0,0,0,.2);
background-color:#fff;
}
.btn3d.btn-white:active, .btn3d.btn-white.active {
color: #666666;
box-shadow:0 0 0 1px #ebebeb inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,.1);
background-color:#fff;
}
.btn3d.btn-default {
color: #666666;
box-shadow:0 0 0 1px #ebebeb inset, 0 0 0 2px rgba(255,255,255,0.10) inset, 0 8px 0 0 #BEBEBE, 0 8px 8px 1px rgba(0,0,0,.2);
background-color:#f9f9f9;
}
.btn3d.btn-default:active, .btn3d.btn-default.active {
color: #666666;
box-shadow:0 0 0 1px #ebebeb inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,.1);
background-color:#f9f9f9;
}
.btn3d.btn-primary {
box-shadow:0 0 0 1px #417fbd inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #4D5BBE, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#4274D7;
}
.btn3d.btn-primary:active, .btn3d.btn-primary.active {
box-shadow:0 0 0 1px #417fbd inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color:#4274D7;
}
.btn3d.btn-success {
box-shadow:0 0 0 1px #31c300 inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #5eb924, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#78d739;
}
.btn3d.btn-success:active, .btn3d.btn-success.active {
box-shadow:0 0 0 1px #30cd00 inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color: #78d739;
}
.btn3d.btn-info {
box-shadow:0 0 0 1px #00a5c3 inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #348FD2, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#39B3D7;
}
.btn3d.btn-info:active, .btn3d.btn-info.active {
box-shadow:0 0 0 1px #00a5c3 inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color: #39B3D7;
}
.btn3d.btn-warning {
box-shadow:0 0 0 1px #d79a47 inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #D79A34, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#FEAF20;
}
.btn3d.btn-warning:active, .btn3d.btn-warning.active {
box-shadow:0 0 0 1px #d79a47 inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color: #FEAF20;
}
.btn3d.btn-danger {
box-shadow:0 0 0 1px #b93802 inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #AA0000, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#D73814;
}
.btn3d.btn-danger:active, .btn3d.btn-danger.active {
box-shadow:0 0 0 1px #b93802 inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color: #D73814;
}
.btn3d.btn-magick {
color: #fff;
box-shadow:0 0 0 1px #9a00cd inset, 0 0 0 2px rgba(255,255,255,0.15) inset, 0 8px 0 0 #9823d5, 0 8px 8px 1px rgba(0,0,0,0.5);
background-color:#bb39d7;
}
.btn3d.btn-magick:active, .btn3d.btn-magick.active {
box-shadow:0 0 0 1px #9a00cd inset, 0 0 0 1px rgba(255,255,255,0.15) inset, 0 1px 3px 1px rgba(0,0,0,0.3);
background-color: #bb39d7;
}

Add Stylesheet to XPage
The next step is to add the Stylesheet to the XPage or Custom Control.
<xp:this.resources>
<xp:styleSheet href="/3dbutton.css"></xp:styleSheet>
</xp:this.resources>

Setup XPage button
The setup of the XPage button looks like follows:
<xp:button value="Warning" id="button3"
styleClass="btn btn-warning btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-warning-sign"></span>
</xp:button>

The final result looks like this example below.


Code XPage
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.resources>
<xp:styleSheet href="/3dbutton.css"></xp:styleSheet>
</xp:this.resources>
<xc:ccLayoutBootstrap>
<xp:this.facets>
<xp:panel xp:key="facetMiddle">
<div class="container">
<div class="row">
<h2>Bootstrap 3D Button Effects in XPages</h2>          
<xp:button value="Primary" id="button1"
styleClass="btn btn-primary btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-cloud"></span>
</xp:button>      
<xp:button value="Success" id="button2"
styleClass="btn btn-success btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-ok"></span>
</xp:button>      
<xp:button value="Warning" id="button3"
styleClass="btn btn-warning btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-warning-sign"></span>
</xp:button>
<xp:button value="" id="button4"
styleClass="btn btn-primary btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-thumbs-up"></span>
</xp:button>
<xp:button value="" id="button5"
styleClass="btn btn-danger btn-lg btn3d"
style="color:rgb(255,255,255)">
<span class="glyphicon glyphicon-off"></span>
</xp:button>              
</div>
</div>
</xp:panel>
</xp:this.facets>
</xc:ccLayoutBootstrap>
</xp:view>

No comments:

Post a Comment