Reputation: 107
Out of nowhere, my button stopped working. I tried to narrow it down to what was causing the issue, it happens whenever I add the following piece of code in my css
-
#filler{
position:relative;
left:340px;
top:85px
}
It was working all this time and is suddenly non functional, but only when I try to position it. Here is all my code for reference:
function myFunction() {
$('#Asterisk').empty();
for (var i = 0; i < 7; i++) {
for (var a = i; a < 7; a++) {
$('#Asterisk').append("*");
}
$('#Asterisk').append("<br>");
}
}
#Obelix {
border: 8px solid black;
width: 400px;
height: 200px;
position: relative;
left: 250px;
top: 100px
}
#Getafix {
width: 400px;
height: 200px;
position: relative;
left: 75px;
bottom: 126px
}
#Asterisk {
position: relative;
right: 325px;
top: 10px;
transform: rotate(180deg)
}
#mainwrapper {
height: 4000px;
width: 4000px;
position: relative
}
#filler {
position: relative;
left: 340px;
top: 85px
}
#filler {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
#filler:hover {
background-color: #3e8e41
}
#filler:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/looping.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script src="looping.js">
</script>
</head>
<div id="mainwrapper">
<body>
<button id="filler" onclick="myFunction()"> Fill in the box </button>
<div id="imgbox"> </div>
<div id="Obelix">
<div id="Asterisk"> </div>
<div id="Getafix"> </div>
</div>
</div>
</html>
Upvotes: 0
Views: 1185
Reputation: 596
Add top: 100px;
and remove bottom: 126px;
in #Getafix
css.
#Getafix {
width: 400px;
height: 200px;
position: relative;
left: 75px;
/* bottom: 126px; */
top: 100px;
}
Upvotes: 1
Reputation: 414
You have already got your answer. Just a suggestion. Don't wrap your body element inside other div
. The <body></body>
should be the root for your documents body.
Upvotes: 1
Reputation: 5013
The problem is, that your #Getafix div is above the button, as soon as you position it. You may use z-index to change this order. E.g.
button {
z-index: 1;
}
edit: I added a light nearly transparent background-color to #Getafix, so you may see its positioning. In case using z-index is no option for you (as you need it to be visually above the button), you could use pointer-events: none;
on the #Getafix div. This causes all click-events to be ignored by #Getafix and instead passed to the underlying button. Unfortunately the brower support for poiner-events is mediocre (no ie10 or below support): http://caniuse.com/#feat=pointer-events
function myFunction(){
$('#Asterisk').empty();
for(var i =0;i<7;i++) {
for(var a=i;a<7;a++) {
$('#Asterisk').append("*");
}
$('#Asterisk').append("<br>");
}
}
#Obelix{
border:8px solid black;
width:400px;
height:200px;
position:relative;
left:250px;
top:100px}
#Getafix{
width:400px;
height:200px;
position:relative;
left:75px;
bottom:126px;
background-color: rgba(0,0,0,.1); /* making the #Getafix div position visible */
}
#Asterisk{
position:relative;
right:325px;
top:10px;
transform:rotate(180deg)
}
#mainwrapper{
height:4000px;
width:4000px;
position:relative}
#filler{
position:relative;
z-index: 1;
left:340px;
top:85px
}
#filler {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
#filler:hover {background-color: #3e8e41}
#filler:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
type="text/css"
href="css/looping.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script src="looping.js"> </script>
</head>
<div id="mainwrapper">
<body>
<button id="filler" onclick="myFunction()"> Fill in the box </button>
<div id="imgbox"> </div>
<div id="Obelix">
<div id="Asterisk"> </div>
<div id="Getafix"> </div>
</div>
</div>
</html>
Upvotes: 1
Reputation: 529
You button is under #Getafix
element, so it can't be pressed.
You can increase z-index
of #Asterisk
element or set pointer-events
of #Getafix
to none
as in snippet below.
function myFunction(){
$('#Asterisk').empty();
for(var i =0;i<7;i++) {
for(var a=i;a<7;a++) {
$('#Asterisk').append("*");
}
$('#Asterisk').append("<br>");
}
}
#Obelix{
border:8px solid black;
width:400px;
height:200px;
position:relative;
left:250px;
top:100px}
#Getafix{
width:400px;
height:200px;
position:relative;
left:75px;
bottom:126px;
pointer-events: none;
}
#Asterisk{
position:relative;
right:325px;
top:10px;
transform:rotate(180deg)
}
#mainwrapper{
height:4000px;
width:4000px;
position:relative}
#filler{
position:relative;
left:340px;
top:85px
}
#filler {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
#filler:hover {background-color: #3e8e41}
#filler:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
type="text/css"
href="css/looping.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<script src="looping.js"> </script>
</head>
<div id="mainwrapper">
<body>
<button id="filler" onclick="myFunction()"> Fill in the box </button>
<div id="imgbox"> </div>
<div id="Obelix">
<div id="Asterisk"> </div>
<div id="Getafix"> </div>
</div>
</div>
</html>
Upvotes: 1
Reputation: 34
Fix div element (#Getafix) position or add a z-index to button element (#filler).
Currently div element (#Getafix) is overlapped width button element and div element catch click event.
Upvotes: 1
Reputation: 8409
You need to change the stack order of the button , I have added z-index:99;
to the #filler
now its working
function myFunction() {
$('#Asterisk').empty();
for (var i = 0; i < 7; i++) {
for (var a = i; a < 7; a++) {
$('#Asterisk').append("*");
}
$('#Asterisk').append("<br>");
}
}
#Obelix {
border: 8px solid black;
width: 400px;
height: 200px;
position: relative;
left: 250px;
top: 100px
}
#Getafix {
width: 400px;
height: 200px;
position: relative;
left: 75px;
bottom: 126px
}
#Asterisk {
position: relative;
right: 325px;
top: 10px;
transform: rotate(180deg)
}
#mainwrapper {
height: 4000px;
width: 4000px;
position: relative
}
#filler {
position: relative;
left: 340px;
top: 85px;
z-index:99;
}
#filler {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
#filler:hover {
background-color: #3e8e41
}
#filler:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<div id="mainwrapper">
<body>
<button id="filler" onclick="myFunction()"> Fill in the box </button>
<div id="imgbox"> </div>
<div id="Obelix">
<div id="Asterisk"> </div>
<div id="Getafix"> </div>
</div>
</body>
</div>
Upvotes: 1