I'm trying to use the hover option to display an small edit image/button in the top right hand corner of a div. I have a dynamically created table of x by y number of cells. What I would like to do is have a tiny edit button in the top right hand corner that allows me to click on that button and bring up a popup window.
Something similar to the following:
where the user is presented with options over the div on hover. Would this need to be done in javascript or css? I am using javascript to create the table as follows:
var col = document.getElementById("NoColumns").value;
var row = document.getElementById("NoRows").value;
if (col > 0 || row > 0) {
$("#tblDash").show();
$("#NumberOfColumns").val(col);
$("#NumberOfRows").val(row);
for (var x = 1; x <= row; x++)
{
tr = document.createElement('tr');
document.getElementById('table').appendChild(tr);
for (var i = 1; i <= col; i++) {
var td = document.createElement('td');
td.className = "drop";
td.id = x + ', ' + i;
td.setAttribute('onclick', 'clicked(this);')
td.appendChild(document.createTextNode(i));
tr.appendChild(td);
}
}
I'm trying to use the hover option to display an small edit image/button in the top right hand corner of a div. I have a dynamically created table of x by y number of cells. What I would like to do is have a tiny edit button in the top right hand corner that allows me to click on that button and bring up a popup window.
Something similar to the following:
where the user is presented with options over the div on hover. Would this need to be done in javascript or css? I am using javascript to create the table as follows:
var col = document.getElementById("NoColumns").value;
var row = document.getElementById("NoRows").value;
if (col > 0 || row > 0) {
$("#tblDash").show();
$("#NumberOfColumns").val(col);
$("#NumberOfRows").val(row);
for (var x = 1; x <= row; x++)
{
tr = document.createElement('tr');
document.getElementById('table').appendChild(tr);
for (var i = 1; i <= col; i++) {
var td = document.createElement('td');
td.className = "drop";
td.id = x + ', ' + i;
td.setAttribute('onclick', 'clicked(this);')
td.appendChild(document.createTextNode(i));
tr.appendChild(td);
}
}
Share
Improve this question
asked Feb 1, 2019 at 7:43
user1397978user1397978
2651 gold badge8 silver badges25 bronze badges
2 Answers
Reset to default 7Display the button when you hover on the container, else keep it hidden via CSS?
.container {
height: 200px;
width: 200px;
background-color: yellowgreen;
position: relative;
}
.container:hover > .btn {
display: block;
}
.btn {
display: none;
position: absolute;
top: 5px;
right: 5px;
}
<div class="container">
<button class="btn">Edit</btn>
</div>
It will be done with CSS. add "button" class to these three buttons and use the css below.
.button {
display: none;
}
div:hover + .button, .button:hover {
display: inline-block;
}