CSS How to align checkbox image - css

I trying to style my checkbox with custom image, but what I have tried so far is the tick image stick with the text, this doesn't look good, how to make the tick image and text align nicely ?
JS Fiddle
What I want it look like this ✔ mango
CSS
.label{
margin:5px;
color: #ccc;
font-size:12px;
cursor:pointer;
}
.label:hover{
color:#444;
}
input[type=checkbox]{
display:none;
}
input[type=checkbox] + .label {
padding:5px;
}
input[type=checkbox]:checked + .label {
color: #444;
position:relative;
margin:2px;
background-image:url(http://icons.iconarchive.com/icons/custom-icon-design/mini/16/Accept-icon.png);
background-repeat:no-repeat;
background-color:#ccc;
}

Note: From a usability point of view:
when only a single option should be selected, use radio buttons and not ticks.
currently you have to click the label twice to make a different selection; clicking on another option should deselect a previously checked option.
Use padding for the left of the label. In this example, padding-left: 10px
Position the background images x and y position. In this example I have placed it all in the background property:
background: url(urlPath) 10px center no-repeat
That gives us this:
Example
var PG = {
divid: "",
multiselection: "",
optionitem: [],
init: function(divid, multiselection, optionitem) {
PG.divid = divid;
PG.multiselect = multiselection;
PG.optionitem = optionitem;
},
test: function() {
for (var i = 0; PG.optionitem.length > i; i++) {
alert(PG.optionitem[i].name);
}
},
render_1: function() {
$.each(array, function(i, obj) {
var selection = "<input class='the_checkbox' type='checkbox' id=" + obj.value + " name=" + obj.name + " value=" + obj.value + ">" +
"<label class='label' for=" + obj.value + ">" + obj.value + "</label>" +
"<div class='pbar'><div class='pbarinner' style='width:75%;'></div></div>";
$("#" + PG.divid).append(selection);
if ($('input#' + obj.value).is(':checked')) {
$('.pbar').css('display', 'block');
}
});
$("#survey_title").append("What is your favorite fruit??");
$("#choose").append("Please select 1 fruit only:");
$('.the_checkbox').on('change', function(evt) {
if ($(this).siblings(':checked').length >= PG.multiselect) {
this.checked = false;
}
});
},
render_2: function() {
$.each(w_array, function(i, obj) {
var selection = "<input class='the_checkbox' type='checkbox' id=" + obj.value + " name=" + obj.name + " value=" + obj.value + ">" +
"<label class='label' for=" + obj.value + ">" + obj.value + "</label>";
$("#" + PG.divid).append(selection);
});
$("#survey_title").append("item??");
$("#choose").append("Please select 3 item :");
$('.the_checkbox').on('change', function(evt) {
if ($(this).siblings(':checked').length >= PG.multiselect) {
this.checked = false;
}
});
},
save: function() {}
}
var array = [];
array[0] = {
"name": "fruit",
"value": "mango"
};
array[1] = {
"name": "fruit",
"value": "apple"
};
array[2] = {
"name": "fruit",
"value": "orange"
};
array[3] = {
"name": "fruit",
"value": "banana"
};
var w_array = [];
w_array[0] = {
"name": "com",
"value": "RAM"
};
w_array[1] = {
"name": "com",
"value": "DISK"
};
w_array[2] = {
"name": "com",
"value": "BOOK"
};
w_array[3] = {
"name": "com",
"value": "PEN"
};
PG.init("popupfoot", "1", array);
PG.render_1();
/*PG.init("survey_question", "3", w_array);
PG.render_2();*/
.label {
margin: 5px;
color: #ccc;
font-size: 12px;
cursor: pointer;
}
.label:hover {
color: #444;
}
input[type=checkbox] {
display: none;
}
input[type=checkbox] + .label {
padding: 5px;
}
input[type=checkbox]:checked + .label {
color: #444;
position: relative;
margin: 2px;
background: url(http://icons.iconarchive.com/icons/custom-icon-design/mini/16/Accept-icon.png) 10px center no-repeat;
background-color: #ccc;
padding-left: 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="popupfoot">
<p id="survey_title"></p>
<h5 id="choose"></h5>
<div id="survey_question"></div>
</div>

Try using the background position property
For e.g.
In your case
background-position: center left;
I've modified the padding left too. Here is the fiddle.
http://jsfiddle.net/8190zjvf/9/
Here I have changed padding-left of the list to 20 px;
And to place the tick in the left I've used the background-position property. Hope it is clear.

Related

Text underlined by a single line of two colors

Good morning. Hello,
I'm looking to underline a title with a line of two colors. Half blue, half black, for example.
I imagine it's done by CSS, but I haven't figured out how to do it.
Does anyone have the solution?
Thank you all, happy holidays.
You can use :before and :after pseudo-elements for each half of the line. If you want to increase line height you also need to increase negative margin on :after pseudo-element for the same amount. Demo
h1 {
display: inline-flex;
flex-direction: column;
}
h1:after,
h1:before {
content: '';
border-bottom: 1px solid green;
order: 2;
width: 50%;
}
h1:after {
margin-left: auto;
margin-top: -1px;
border-color: red;
}
<h1>Lorem ipsum dolor sit.</h1>
If you have multi-line title then you can split text into two spans and use text-decoration instead.
h1 {
max-width: 400px;
}
h1 span:first-child {
text-decoration: red underline;
}
h1 span:last-child {
text-decoration: green underline;
}
<h1><span>Lorem ipsum dolor </span><span>sit amet, consectetur.</span></h1>
You could use some js to create more dynamic solution.
class Title {
constructor(text, parts = []) {
this.text = text;
this.parts = parts;
return this.create()
}
checkLength() {
let l = this.parts.reduce((r, e) => r + e.width, 0);
if (l > 100) {
throw new Error('Sum of all parts width must be under 100%')
}
}
create() {
this.checkLength();
let title = this.createTitle();
this.addLines(title);
return title;
}
createTitle() {
let h1 = document.createElement('h1');
h1.textContent = this.text;
h1.style.display = 'inline-block';
h1.style.position = 'relative';
return h1;
}
createLine(input) {
let {color,width} = input;
let line = document.createElement('span');
line.style.position = 'absolute';
line.style.bottom = 0;
line.style.border = '1px solid ' + color;
line.style.width = width + '%';
return line;
}
addLines(title) {
let that = this;
this.parts.forEach(function(part) {
let line = that.createLine(part);
line.style.left = this.prev + '%';
this.prev += part.width;
title.appendChild(line)
}, {prev: 0})
}
}
let title = new Title('Random Title', [
{color: 'red', width: 60},
{color: 'blue', width: 20},
{color: 'green', width: 20}
])
let title2 = new Title('Lorem ipsum dolor.', [
{color: 'black', width: 80},
{color: 'green', width: 20}
])
document.body.appendChild(title)
document.body.innerHTML += '<br>'
document.body.appendChild(title2)

How to resolve d3js tree graph getting clipped

I am trying to create a collapsible tree graph in d3. Although there are many examples around the web, I am not expert in JS or d3 coming from java background, and couldn't find any that perfectly suited my needs and hence made this from different templates that I found across many blogs and gists.
The problem is the lower part of my graph getting clipped. If I increase the svg size, that just elongates the graph and it still gets clipped. I am posting the link to plunkr where I have put the code. Please scroll to the right in plunkr to see the graph.
Below is the javascript to render tree
var CollapsibleTree = function(elt) {
var m = [20, 120, 20, 120],
w = 1280 - m[1] - m[3],
h = 780 - m[0] - m[2],
i = 0,
root;
var tree = d3.layout.tree()
.size([w, h]);
var parentdiagonal = d3.svg.diagonal()
.projection(function(d) { return [d.x, -d.y]; });
var childdiagonal = d3.svg.diagonal()
.projection(function(d) { return [d.x, d.y]; });
var vis = d3.select(elt).append("svg:svg")
.attr("width", w + m[1] + m[3])
.attr("height", h + m[0] + m[2])
.append("svg:g")
.attr("transform", "translate("+w/6+","+h/2+")"); // bidirectional-tree
var that = {
init: function(url) {
var that = this;
var json = {
"name":"A",
"elementType":"ACTION",
"elementSubType":"ACTION-A",
"isparent":false,
"parents":[
{
"name":"B",
"elementType":"RESOURCE",
"elementSubType":"RESOURCE-A",
"isparent":true
}
],
"children":[
{
"name":"C",
"elementType":"RESOURCE",
"elementSubType":"RESOURCE-C",
"isparent":false,
"children":[
{
"name":"D",
"elementType":"ACTION",
"elementSubType":"ACTION-A",
"isparent":false,
"children":[
{
"name":"E",
"elementType":"RESOURCE",
"elementSubType":"RESOURCE-A",
"isparent":false,
"children":[
{
"name":"F",
"elementType":"ACTION",
"elementSubType":"ACTION-C",
"isparent":false,
"children":[
{
"name":"G",
"elementType":"RESOURCE",
"elementSubType":"RESOURCE-C",
"isparent":false
}
]
}
]
}
]
}
]
}
]
};
root = json;
root.x = w / 2;
root.y = h / 2;
that.updateBoth(root);
},
updateBoth: function(source) {
var duration = d3.event && d3.event.altKey ? 5000 : 300;
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse();
// Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 0.5*h/4; });
// Update the nodes…
var node = vis.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append("svg:g")
.attr("class", "node")
.attr("transform", function(d) {
if( that.isParent(d) ) {
return "translate(" + source.x + "," + -source.y + ")";
} else {
return "translate(" + source.x + "," + source.y + ")";
}
})
.on("click", function(d) { that.toggle(d); that.updateBoth(d); });
// Add images to node
nodeEnter.append("svg:image")
.attr("xlink:href", "img/file.png")
.attr("width", 35)
.attr("height", 35)
.attr("x",function(d) { return -20; }) // position the images
.attr("y",function(d) { return -20; });
nodeEnter.append("text")
// .attr("x", function(d) { return d.children || d._children ? -10 : 10; })
.attr("x", function(d) {
return -10;
})
.attr("y", 20)
.attr("dy", ".35em")
.attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
.attr("text-anchor", function(d) {
return "middle";
})
.text(function(d) {
if (d.name.length > 10){
return d.name.substring(0,10)+d.name.substring(10,d.name.length);
}
else {
return d.name;
}
})
.style("fill", "black")
.style("fill-opacity", 1e-6);
// Transition nodes to their new position.
var nodeUpdate = node.transition()
.duration(duration)
.ease("linear")
.attr("transform", function(d) {
if( that.isParent(d) ) {
return "translate(" + d.x + "," + -d.y + ")";
} else {
return "translate(" + d.x + "," + d.y + ")";
}
});
nodeUpdate.select("text")
.style("fill-opacity", 1)
.attr("class", function(d){
if (d.status==="incomplete" || d.status === "failed"){
return "blink";
} else {
return "non-blink"
}
});
// Transition exiting nodes to the parent's new position.
var nodeExit = node.exit().transition()
.duration(duration)
// .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
.attr("transform", function(d) { // custom code to fix error in node exit
if (that.isParent(d)){
return "translate(" + source.x + "," + -source.y + ")"; // controls exit of parents
}
else{
return "translate(" + source.x + "," + source.y + ")"; // controls exit of children
}
})
.remove();
nodeExit.select("text")
.style("fill-opacity", 1e-6);
// Update the links…
var link = vis.selectAll("path.link")
.data(tree.links_parents(nodes).concat(tree.links(nodes)), function(d) { return d.target.id; });
// Enter any new links at the parent's previous position.
link.enter().insert("svg:path", "g")
.attr("class", "link")
.style("stroke", function(d) {
return "black";
})
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
if( that.isParent(d.target) ) {
return parentdiagonal({source: o, target: o});
} else {
return childdiagonal({source: o, target: o});
}
})
.transition()
.duration(duration)
.attr("d", function(d) {
if( that.isParent(d.target) ) {
return parentdiagonal(d);
} else {
// return parentdiagonal(d);
return childdiagonal(d);
}
})
// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", function(d) {
if( that.isParent(d.target) ) {
return parentdiagonal(d);
} else {
return childdiagonal(d);
}
})
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
// return parentdiagonal({source: o, target: o});
if( that.isParent(d.target) ) {
return parentdiagonal({source: o, target: o});
} else {
return childdiagonal({source: o, target: o});
}
})
.remove();
// Stash the old positions for transition.
nodes.forEach(function(d) {
d.x = d.x;
d.y = d.y;
});
},
isParent: function(node) {
if( node.parent && node.parent != root ) {
return this.isParent(node.parent);
} else
if( node.isparent ) {
return true;
} else {
return false;
}
},
// Toggle children or parents (one level).
toggle: function(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
if (d.parents) {
d._parents = d.parents;
d.parents = null;
} else {
d.parents = d._parents;
d._parents = null;
}
},
// Toggle successors or aancestors (multiple level)
toggleAll: function(d) {
if (d.children) {
d.children.forEach(that.toggleAll);
that.toggle(d);
}
if (d.parents) {
d.parents.forEach(that.toggleAll);
that.toggle(d);
}
}
}
return that;
}
and here are the css
body {
overflow: hidden;
margin: 0;
font-size: 14px;
font-family: "Helvetica Neue", Helvetica;
}
#chart, #header, #footer {
position: absolute;
top: 0;
}
#header, #footer {
z-index: 1;
display: block;
font-size: 36px;
font-weight: 300;
text-shadow: 0 1px 0 #fff;
}
#header.inverted, #footer.inverted {
color: #fff;
text-shadow: 0 1px 4px #000;
}
#header {
top: 80px;
left: 140px;
width: 1000px;
}
#footer {
top: 680px;
right: 140px;
text-align: right;
}
rect {
fill: none;
pointer-events: all;
}
pre {
font-size: 18px;
}
line {
stroke: #000;
stroke-width: 1.5px;
}
.string, .regexp {
color: #f39;
}
.keyword {
color: #00c;
}
.comment {
color: #777;
font-style: oblique;
}
.number {
color: #369;
}
.class, .special {
color: #1181B8;
}
a:link, a:visited {
color: #000;
text-decoration: none;
}
a:hover {
color: #666;
}
.hint {
position: absolute;
right: 0;
width: 1280px;
font-size: 12px;
color: #999;
}
.node circle {
cursor: pointer;
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node text {
font-size: 11px;
}
path.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}
/*svg {
border: 1px;
border-style: solid;
border-color: black;
}*/
#foo {
border: 5px;
border-style: dashed;
border-color: black;
background-color: pink;
}
#categoryHierarchy{
margin: 5px;
height: 700px;
width: auto;
border: 2px;
border-style: solid;
border-color: #000;
overflow: scroll;
/*padding: 10px;*/
}
and html files
<body>
<div id="categoryHierarchy"></div>
<script type="text/javascript">
$(document).ready(function(event) {
var tree = CollapsibleTree("#categoryHierarchy");
tree.init('sample.json');
});
</script>
</body>
You could try reducing the distance between each of the 'nodes'.
E.g. line 98 try playing around with h - 'x', I've tried using 300.
nodes.forEach(function(d) { d.y = d.depth * 0.5*(h-300)/4; });

Custom cursor not supported in Edge?

if(!CSS.supports('cursor', 'url(cursor.png), pointer')) {
var myCursor = document.createElement('img');
myCursor.src = 'cursor.png';
myCursor.style.position = 'absolute';
document.body.appendChild(myCursor);
document.addEventListener('mousemove', function(e) {
myCursor.style.left = e.pageX+'px';
myCursor.style.top = e.pageY+'px';
}, false);
}
body{
padding:0;
margin:0;
background-color: #19321D;
color: #53CC66;
line-height: 1.5;
font-family: FreeMono, monospace;
cursor: url(cursor.png), pointer;
}
a{
text-decoration: none;
color: #53CC66;
}
ul{
text-decoration: none;
list-style-type: none;
}
#header{
text-align: center;
border-bottom: 3px solid #53CC66;
margin-bottom: 100px;
width: 90%;
margin-left: auto;
margin-right: auto;
margin-top: 25px;
line-height: 1;
}
h1, h2, h3{
color: #53CC66;
font-family: FreeMono, monospace;
font-size: 15px;
}
a{
cursor: url(cursor.png), pointer;
}
a:hover {
cursor: url(cursor.png), pointer;
color: #19321D;
}
li:hover{
background-color:#53CC66;
color: #19321D;
}
li:hover a{
color: #19321D;
}
<html>
<head>
<title>Getrate|Command promph </title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="styles15.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>DAVID SECRET INDUSTRIES UNVERIFIED SYSTEM</h1>
<h2>COPYRIGHT 2015 - 2050 ALL RIGHT RESERVED</h2>
<h3>- SERVER #1 -</h3>
</div>
<ul>
<li>[CONZOLE] > -TOP SECRET- . PAGE //stripslash 1.3.8.9.84.113.21.73</li>
<li>[CONZOLE] > -TOP SECRET- . PAGE //stripslash 1.4.8.9.84.113.21.74</li>
<li>[CONZOLE] > -TOP SECRET- . PAGE //stripslash 1.5.8.9.84.113.21.75</li>
<li>[CONZOLE] > -TOP SECRET- . PAGE //stripslash 1.6.8.9.84.113.21.76</li>
<li>[CONZOLE] > -TOP SECRET- . PAGE //stripslash 1.7.8.9.84.113.21.77</li>
</ul>
</div>
</body>
<script src="wow.js"></script>
</html>
I just thought, is there any possible way, to make custom cursor, that works on microsoft edge? On my website, i used this:
body{ cursor: url(cursor.png), pointer;}
but in microsoft edge, it is not working...
Any ideas how to solve this?/Is there any other way?
So.... after small recode, my website looks like this, see the fiddle and try, it is not working yet...
This property is not supported yet : http://caniuse.com/#search=cursor
This property is now supported : caniuse.com:cursor:url()
As Charaf mentioned: the property isn't yet supported in Edge. If your project requires a solution, you can sort of mimic the behavior with JavaScript.
JavaScript:
if(!CSS.supports('cursor', 'url(cursor.png), pointer')) {
var myCursor = document.createElement('img');
myCursor.src = 'cursor.png';
myCursor.style.position = 'absolute';
document.body.appendChild(myCursor);
document.addEventListener('mousemove', function(e) {
myCursor.style.left = e.pageX+'px';
myCursor.style.top = e.pageY+'px';
}, false);
}
I made a library called CursorJS for you. You can check it out here. If you scroll to the bottom of the JavaScript code, you can find initializing code:
/* Enable lib with cursor image src */
CursorJS.enable('http://files.softicons.com/download/toolbar-icons/plastic-mini-icons-by-deleket/png/32x32/Cursor-01.png');
CursorJS.addEl(document.querySelector('.myElement1'));
CursorJS.addEl(document.querySelector('.myElement3'));
In your case just do the following:
/* Enable lib with cursor image src */
CursorJS.enable('./cursor.png');
CursorJS.addEl(document.body);
Customization
CursorJS has a mouseOffset variable. It repesents difference of mouse position and position of image. For example, if I set it to
mouseOffset: {
x: 50,
y: 50
},
The mouse will be 50px off. The reason why I made this variable is that custom mouse was kind of "blinking", try to set it to {x:1,y:1} ;)
Live example
var CursorJS = {
img: new Image(),
els: [],
mouseOffset: {
x: 5,
y: 5
},
addedImg: false,
checkForIE: function() {
return (/MSIE/i.test(navigator.userAgent)
|| /rv:11.0/i.test(navigator.userAgent));
},
setDisplay: function() {
this.img.style.display =
this.els.indexOf(true) > -1 ? null : 'none';
},
getMouseCoords: function(e) {
var mx = 0, my = 0;
if (this.checkForIE())
mx = event.clientX + document.body.scrollLeft,
my = event.clientY + document.body.scrollTop;
else
mx = e.pageX,my = e.pageY;
if (mx < 0) mx = 0;
if (my < 0) my = 0;
return [mx, my];
},
mouseOver: function(e, id) {
this.els[id] = true;
this.setDisplay();
var coords = this.getMouseCoords(e);
this.img.style.left =
(coords[0]+this.mouseOffset.x) + 'px';
this.img.style.top =
(coords[1]+this.mouseOffset.y) + 'px';
},
mouseOut: function(e, id) {
this.els[id] = false;
this.setDisplay();
},
mouseMove: function(e) {
var coords = this.getMouseCoords(e);
this.img.style.left =
(coords[0]+this.mouseOffset.x) + 'px';
this.img.style.top =
(coords[1]+this.mouseOffset.y) + 'px';
},
addEvent: function(el, name, func, bool) {
if (el == null || typeof name != 'string'
|| typeof func != 'function'
|| typeof bool != 'boolean')
return;
if (el.addEventListener)
el.addEventListener(name, func, false);
else if (el.attachEvent)
el.attachEvent('on' + name, func);
else
el['on' + name] = func;
},
addEl: function(el) {
var evts = ['over','out','move'],
id = this.els.length;
this.els.push(false);
this.el = el;
this.addEvent(el, 'mouseover', function(e) {
this.mouseOver(e, id) }.bind(this), false);
this.addEvent(el, 'mouseout', function(e) {
this.mouseOut(e, id) }.bind(this), false);
this.addEvent(el, 'mousemove', function(e) {
this.mouseMove(e) }.bind(this), false);
if (typeof el['style'] != 'undefined')
el.style.cursor = 'none';
},
enable: function(src) {
this.img.src = src;
this.img.style.display = 'none';
this.img.style.position = 'absolute';
this.img.style.cursor = 'none';
this.addEvent(this.img, 'mousemove', function(e) {
this.mouseMove(e) }.bind(this), false);
if (!this.addedImg)
document.body.appendChild(this.img),
this.addedImg = true;
}
}
/*** INITIALIZE ***/
CursorJS.enable('http://files.softicons.com/download/toolbar-icons/plastic-mini-icons-by-deleket/png/32x32/Cursor-01.png');
CursorJS.addEl(document.querySelector('.myElement1'));
CursorJS.addEl(document.querySelector('.myElement3'));
.myElement1, .myElement2, .myElement3 {
width: 150px;
height: 150px;
border: 1px solid gray;
display: inline-block;
}
<div class="myElement1">added</div>
<div class="myElement2">not added</div>
<div class="myElement3">added</div>
Hope that worked! Have a nice day :)

css moving div below text results

I am trying to move a div below auto complete search results. But i am unable to push the div below autocomplete results after user starts typing. I am trying to implement searchbox similar to www.microsoft.com. Any help would be highly appreciated.
Here is my Fiddle code
<input name="query" id="pageSearchField" type="text" maxlength="50" value="" class="ui-autocomplete-input" autocomplete="off">
var availableTags = [
"Details",
"Project ",
"Release ",
"Property ",
"Application",
"Last Modified By",
"Last Modified Date",
"Tagged by"
];
$("#pageSearchField").autocomplete({
source: availableTags
});
$("#pageSearchField").click(function () {
$('#bottom-div').show("slow");
});
$('#pageMainRegion').click(function () {
$('#bottom-div').hide("slow");
});
$('#bottom-div>div').css("background-color", "white");
var firstFilterText = "Search Data Centers";
var secondFilterText = "Search Projects";
var thirdFilterText = "Search Orders";
$("#pageSearchField").after("" +
"<div id=" + "bottom-div" + "><div>" + firstFilterText + "</div>" +
"<div>" + secondFilterText + "</div>" +
"<div>" + thirdFilterText + "</div></div>");
$('#bottom-div>div').click(function () {
$('#bottom-div>div').css("background-color", "white");
$('#bottom-div>div').css("color", "black");
$(this).css("background-color", "gray");
$(this).css("color", "white");
});
#bottom-div {
z-index: 999;
position: absolute;
min-width: 290px;
background: #fff;
padding: 10px;
border: 1px solid #ccc;
height: 80px;
cursor: pointer;
display: none;
border-top-color: #000;
}
#bottom-div > div {
padding-bottom: 5px;
}
Since Ui-Autocomplete has position:absolute, it will not affect page layout in the normal way and it will not push elements below it.
One approach is to extend the ui autocomplete to render with your div at the bottom of the autocomplete (jsFiddle)
$.widget( "custom.autocompletePlus", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var original = this._super(ul, items);
$(ul).append(
"<p>Your Html goes here</p>"
);
}
});
$("#pageSearchField").autocompletePlus({
source: availableTags,
});
change your jQuery like this:
$(".ui-autocomplete").after("" +
"<div id=" + "bottom-div" + "><div>" + firstFilterText + "</div>" +
"<div>" + secondFilterText + "</div>" +
"<div>" + thirdFilterText + "</div></div>");
remove position:absolute from your bottom-div and add this class to your CSS:
.ui-autocomplete{
position:relative;
top:0;
left:0;
}
DEMO
with some style you can create what you want.

Javascript or CSS hover not working in Safari and Chrome

I have a problem with a script for a image gallery. The problem seems to only occur on Safari and Chrome, but if I refresh the page I get it to work correctly - weird!
Correct function:
The gallery has a top bar, which if you hover over it, it will display a caption. Below sits the main image. At the bottom there is another bar that is a reversal of the top bar. When you hover over it, it will display thumbnails of the gallery.
The problem:
In Safari and Chrome, the thumbnail holder will not display. In fact, it doesn't even show it as an active item (or a rollover). But oddly enough, if you manually refresh the page it begins to work correctly for the rest of the time you view the page. Once you have left the page and return the same error occurs again and you have to go through the same process.
Here's one of the pages to look at:
link text
Here's the CSS:
#ThumbsGutter {
background: url(../Images/1x1.gif);
background: url(/Images/1x1.gif);
height: 105px;
left: 0px;
position: absolute;
top: 0px;
width: 754px;
z-index: 2;
}
#ThumbsHolder {
display: none;
}
#ThumbsTable {
left: 1px;
}
#Thumbs {
background-color: #000;
width: 703px;
}
#Thumbs ul {
list-style: none;
margin: 0;
padding: 0;
}
#Thumbs ul li {
display: inline;
}
.Thumbs ul li a {
border-right: 1px solid #fff;
border-top: 1px solid #fff;
float: left;
left: 1px;
}
.Thumbs ul li a img {
filter: alpha(opacity=50);
height: 104px;
opacity: .5;
width: 140px;
}
.Thumbs ul li a img.Hot {
filter: alpha(opacity=100);
opacity: 1;
}
Here is the javascript:
//Variables
var globalPath = "";
var imgMain;
var gutter;
var holder;
var thumbs;
var loadingImage;
var holderState;
var imgCount;
var imgLoaded;
var captionHolder;
var captionState = 0;
var captionHideTimer;
var captionHideTime = 500;
var thumbsHideTimer;
var thumbsHideTime = 500;
$(document).ready(function() {
//Load Variables
imgMain = $("#MainImage");
captionHolder = $("#CaptionHolder");
gutter = $("#ThumbsGutter");
holder = $("#ThumbsHolder");
thumbs = $("#Thumbs");
loadingImage = $("#LoadingImageHolder");
//Position Loading Image
loadingImage.centerOnObject(imgMain);
//Caption Tab Event Handlers
$("#CaptionTab").mouseover(function() {
clearCaptionHideTimer();
showCaption();
}).mouseout(function() {
setCaptionHideTimer();
});
//Caption Holder Event Handlers
captionHolder.mouseenter(function() {
clearCaptionHideTimer();
}).mouseleave(function() {
setCaptionHideTimer();
});
//Position Gutter
if (jQuery.browser.safari) {
gutter.css("left", imgMain.position().left + "px").css("top", ((imgMain.offset().top + imgMain.height()) - 89) + "px");
} else {
gutter.css("left", imgMain.position().left + "px").css("top", ((imgMain.offset().top + imgMain.height()) - 105) + "px");
}
//gutter.css("left", imgMain.position().left + "px").css("top", ((imgMain.offset().top + imgMain.height()) - 105) + "px");
//gutter.css("left", imgMain.offset().left + "px").css("top", ((imgMain.offset().top + imgMain.height()) - gutter.height()) + "px");
//Thumb Tab Event Handlers
$("#ThumbTab").mouseover(function() {
clearThumbsHideTimer();
showThumbs();
}).mouseout(function() {
setThumbsHideTimer();
});
//Gutter Event Handlers
gutter.mouseenter(function() {
//showThumbs();
clearThumbsHideTimer();
}).mouseleave(function() {
//hideThumbs();
setThumbsHideTimer();
});
//Next/Prev Button Event Handlers
$("#btnPrev").mouseover(function() {
$(this).attr("src", globalPath + "/Images/GalleryLeftButtonHot.jpg");
}).mouseout(function() {
$(this).attr("src", globalPath + "/Images/GalleryLeftButton.jpg");
});
$("#btnNext").mouseover(function() {
$(this).attr("src", globalPath + "/Images/GalleryRightButtonHot.jpg");
}).mouseout(function() {
$(this).attr("src", globalPath + "/Images/GalleryRightButton.jpg");
});
//Load Gallery
//loadGallery(1);
});
function loadGallery(galleryID) {
//Hide Holder
holderState = 0;
holder.css("display", "none");
//Hide Empty Gallery Text
$("#EmptyGalleryText").css("display", "none");
//Show Loading Message
$("#LoadingGalleryOverlay").css("display", "inline").centerOnObject(imgMain);
$("#LoadingGalleryText").css("display", "inline").centerOnObject(imgMain);
//Load Thumbs
thumbs.load(globalPath + "/GetGallery.aspx", { GID: galleryID }, function() {
$("#TitleHolder").html($("#TitleContainer").html());
$("#DescriptionHolder").html($("#DescriptionContainer").html());
imgCount = $("#Thumbs img").length;
imgLoaded = 0;
if (imgCount == 0) {
$("#LoadingGalleryText").css("display", "none");
$("#EmptyGalleryText").css("display", "inline").centerOnObject(imgMain);
} else {
$("#Thumbs img").load(function() {
imgLoaded++;
if (imgLoaded == imgCount) {
holder.css("display", "inline");
//Carousel Thumbs
thumbs.jCarouselLite({
btnNext: "#btnNext",
btnPrev: "#btnPrev",
mouseWheel: true,
scroll: 1,
visible: 5
});
//Small Image Event Handlers
$("#Thumbs img").each(function(i) {
$(this).mouseover(function() {
$(this).addClass("Hot");
}).mouseout(function() {
$(this).removeClass("Hot");
}).click(function() {
//Load Big Image
setImage($(this));
});
});
holder.css("display", "none");
//Load First Image
var img = new Image();
img.onload = function() {
imgMain.attr("src", img.src);
setCaption($("#Image1").attr("alt"));
//Hide Loading Message
$("#LoadingGalleryText").css("display", "none");
$("#LoadingGalleryOverlay").css("display", "none");
}
img.src = $("#Image1").attr("bigimg");
}
});
}
});
}
function showCaption() {
if (captionState == 0) {
$("#CaptionTab").attr("src", globalPath + "/Images/CaptionTabHot.jpg");
captionHolder.css("display", "inline").css("left", imgMain.position().left + "px").css("top", imgMain.position().top + "px").css("width", imgMain.width() + "px").effect("slide", { "direction": "up" }, 500, function() {
captionState = 1;
});
}
}
function hideCaption() {
if (captionState == 1) {
captionHolder.toggle("slide", { "direction": "up" }, 500, function() {
$("#CaptionTab").attr("src", globalPath + "/Images/CaptionTab.jpg");
captionState = 0;
});
}
}
function setCaptionHideTimer() {
captionHideTimer = window.setTimeout(hideCaption,captionHideTime);
}
function clearCaptionHideTimer() {
if(captionHideTimer) {
window.clearTimeout(captionHideTimer);
captionHideTimer = null;
}
}
function showThumbs() {
if (holderState == 0) {
$("#ThumbTab").attr("src", globalPath + "/Images/ThumbTabHot.jpg");
holder.effect("slide", { "direction": "down" }, 500, function() {
holderState = 1;
});
}
}
function hideThumbs() {
if (holderState == 1) {
if (jQuery.browser.safari) {
holder.css("display", "none");
$("#ThumbTab").attr("src", globalPath + "/Images/ThumbTab.jpg");
holderState = 0;
} else {
holder.toggle("slide", { "direction": "down" }, 500, function() {
$("#ThumbTab").attr("src", globalPath + "/Images/ThumbTab.jpg");
holderState = 0;
});
}
}
}
function setThumbsHideTimer() {
thumbsHideTimer = window.setTimeout(hideThumbs,thumbsHideTime);
}
function clearThumbsHideTimer() {
if(thumbsHideTimer) {
window.clearTimeout(thumbsHideTimer);
thumbsHideTimer = null;
}
}
function setImage(image) {
//Show Loading Image
loadingImage.css("display", "inline");
var img = new Image();
img.onload = function() {
//imgMain.css("background","url(" + img.src + ")").css("display","none").fadeIn(250);
imgMain.attr("src", img.src).css("display", "none").fadeIn(250);
setCaption(image.attr("alt"));
//Hide Loading Image
loadingImage.css("display", "none");
};
img.src = image.attr("bigimg");
}
function setCaption(caption) {
$("#CaptionText").html(caption);
//alert($("#CaptionText").html());
/*
if (caption.length > 0) {
$("#CaptionText")
.css("display", "inline")
.css("left", imgMain.position().left + "px")
.css("top", imgMain.position().top + "px")
.css("width", imgMain.width() + "px")
.html(caption);
$("#CaptionOverlay").css("display", "inline")
.css("height", $("#CaptionText").height() + 36 + "px")
.css("left", imgMain.position().left + "px")
.css("top", imgMain.position().top + "px")
.css("width", imgMain.width() + "px");
} else {
$("#CaptionText").css("display", "none");
$("#CaptionOverlay").css("display", "none");
}
*/
}
Please if anyone could help, it would be greatly appreciated!
Thanks in advance.
Justin
I'm using Chrome 4.1.249.1064 and the top bar works perfect, I see the caption without refreshing the page.
The same in Firefox 3.6.3, all works perfect
Same with Safari 4.0.3, all works perfect

Resources