Utilizing plain HTML, I constructed a button based on the jQuery output shown below. The code for the static HTML button is as follows:
<a id="button1" title="Reset" style="padding: .5em .5em .5em .5em;"
class="ctkit-button-light-gray
ctkit-button-rounded-light-gray
ctkit-button-enabled-light-gray">
<div style="display: table; width: 100%;">
<div style="display: table-cell; text-align: center;vertical-align: middle;">
<img src="/Images/reset.png" title="Reset" style="border: 0px; width: 1.5em; height: 1.5em;">
</div>
<div style="display: table-cell; text-align: center; vertical-align: middle;">
<span style="padding-left: 2px;"> Reset</span>
</div>
</div>
</a>
Styling the button with CSS:
.ctkit-button-light-gray
{
font-size: 12px;
font: "Arial, Helvetica, sans-serif";
display: inline-block;
text-decoration:none;
text-shadow: 0px 1px 1px rgba(0,0,0,0.3);
}
.ctkit-button-rounded-light-gray
{
-webkit-border-radius:.4em;
-moz-border-radius:.4em;
border-radius:0.4em;
}
.ctkit-button-enabled-light-gray
{
cursor: pointer;
cursor: hand;
color:#474747;
border: solid 1px #bcbcbc;
background:-webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#e3e2e2));
background:-moz-linear-gradient(top, #ffffff, #e3e2e2);
background: -ms-linear-gradient(top, #ffffff, #e3e2e2);
opacity:1;
filters.alpha.opacity:100;
}
It's important to note the vertical alignment of the image and text in the button.
However, upon attempting to create the button dynamically using jQuery with the provided code:
var settings = $(this).data('ctkit-button').data;
var id = $(this)[0].id;
var style = '';
var css = 'ctkit-button-' + settings.theme + ' ';
if(settings.rounded)
css += 'ctkit-button-rounded-' + settings.theme + ' ';
else
css += 'ctkit-button-normal-' + settings.theme + ' ';
if(settings.enabled)
css += 'ctkit-button-enabled-' + settings.theme + ' ';
else
css += 'ctkit-button-disabled-' + settings.theme + ' ';
var div1 = $('<div />',
{
}).attr('style', 'display: table; width: 100%; ');
var div2 = $('<div />',
{
}).attr('style', 'display: table-cell; text-align: center; vertical-align: middle; ');
style = 'border: 0px;';
if(settings.width.length > 0)
style += 'width: ' + settings.width + '; ';
if(settings.height.length > 0)
style += 'height: ' + settings.height + ';' ;
var img = $('<img />',
{
src : settings.image
}).prop('title', settings.tooltip).attr('style', style);
$(div1).append($(div2).append(img));
var div3 = $('<div />',
{
}).attr('style', 'display: table-cell; text-align: center; vertical-align: middle; ');
var span = $('<span />',
{
}).attr('style', 'padding-left: 2px;').html(settings.text);
$(div1).append($(div3).append(span));
$(this).append(div1);
$(this).prop('title', settings.tooltip);
$(this).attr('style', settings.padding);
$(this).addClass(css);
where the value of the settings object is:
var settings = {
_instance: "",
theme: "light-gray",
tooltip: "",
image: "",
padding: "padding: .5em .5em .5em .5em;",
text: "",
enabled: true,
rounded: true,
width: "",
height: ""
}
Unfortunately, the dynamically created button is not properly vertically aligned and appears larger than expected.
This issue arises despite the fact that the static HTML code provided above renders correctly when viewed in a static HTML file after creation using:
var html = $('html').html();
I am currently puzzled by this discrepancy and am seeking a solution to rectify it.