Why does this button element have different 'click' behavior than a div?Floating elements within a div, floats outside of div. Why?Click through div to underlying elementsWhy does jQuery or a DOM method such as getElementById not find the element?Why is there an unexplainable gap between these inline-block div elements?Why does CSS work with fake elements?Cannot display HTML stringUsing Javascript and JQuery to alter CSS properties: JQuery cannot alter properties that Javascript has already altered?Change font color via button clickHow to get mix-blend-mode scroll effect using javascript?vertically center text in two inline-block div

Why does the leading tone (G#) go to E rather than A in this example?

We are on WHV, my boyfriend was in a small collision, we are leaving in 2 weeks what happens if we don’t pay the damages?

Is a PWM required for regenerative braking on a DC Motor?

Difference between types of yeast

How can this Stack Exchange site have an animated favicon?

Plotting curves within a foreach loop and attributing colors from a colormap

Can my former employer sue me if I don't give them the photos I took (taking pictures was not part of my job description)?

How to check if my quadrature encoder is broken or not?

What did Jesse Pinkman mix into Walt's coffee?

What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?

Which lens has the same capability of lens mounted in Nikon P1000?

With an option to reduce any pair satisfying a relation, repeatedly reduce a collection.

What secular civic space would pioneers build for small frontier towns?

Is differentiation as a map discontinuous?

Why was LOGO created?

Subverting the emotional woman and stoic man trope

Does every piano need tuning every year?

Need Improvement on Script Which Continuously Tests Website

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

What happens to a net with the Returning Weapon artificer infusion after it hits?

What is the difference between an astronaut in the ISS and a freediver in perfect neutral buoyancy?

I reverse the source code, you reverse the input!

Interchange `colon` and `:`

How do you program Babbage's Difference Engine?



Why does this button element have different 'click' behavior than a div?


Floating elements within a div, floats outside of div. Why?Click through div to underlying elementsWhy does jQuery or a DOM method such as getElementById not find the element?Why is there an unexplainable gap between these inline-block div elements?Why does CSS work with fake elements?Cannot display HTML stringUsing Javascript and JQuery to alter CSS properties: JQuery cannot alter properties that Javascript has already altered?Change font color via button clickHow to get mix-blend-mode scroll effect using javascript?vertically center text in two inline-block div






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








5















I am modifying the UI code per our analytics teams request. All clickable elements must be either an a or button.



I've overridden the button and a styles so they do not appear to be any different. In a desktop browser they don't appear to behave differently either.



But open the chrome "device emulation" from dev tools, and you can see that the button and a elements have different behaviors. Their respective target click areas seem to be smaller, and you must directly hit the svg "X" instead of any part of the block level element.



I've tried both an a and button element. I've also recreated the issue inside of a jsfiddle.



This jsfiddle reproduces the issue (test in mobile device emulator mode in chrome) https://jsfiddle.net/8jze13t0/1/






// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>





Here is an screenshot of the issue (w/ annotations):



enter image description here



I expect to be able to click anywhere within the block level element within the mobile emulator and trigger the event handler.










share|improve this question


























  • Side note, <p> elements can't contain <div>s

    – j08691
    Mar 28 at 18:27











  • It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

    – Huangism
    Mar 28 at 18:49












  • @Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

    – Charlie Hoover
    Mar 28 at 18:54












  • @CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

    – Huangism
    Mar 28 at 18:57


















5















I am modifying the UI code per our analytics teams request. All clickable elements must be either an a or button.



I've overridden the button and a styles so they do not appear to be any different. In a desktop browser they don't appear to behave differently either.



But open the chrome "device emulation" from dev tools, and you can see that the button and a elements have different behaviors. Their respective target click areas seem to be smaller, and you must directly hit the svg "X" instead of any part of the block level element.



I've tried both an a and button element. I've also recreated the issue inside of a jsfiddle.



This jsfiddle reproduces the issue (test in mobile device emulator mode in chrome) https://jsfiddle.net/8jze13t0/1/






// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>





Here is an screenshot of the issue (w/ annotations):



enter image description here



I expect to be able to click anywhere within the block level element within the mobile emulator and trigger the event handler.










share|improve this question


























  • Side note, <p> elements can't contain <div>s

    – j08691
    Mar 28 at 18:27











  • It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

    – Huangism
    Mar 28 at 18:49












  • @Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

    – Charlie Hoover
    Mar 28 at 18:54












  • @CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

    – Huangism
    Mar 28 at 18:57














5












5








5








I am modifying the UI code per our analytics teams request. All clickable elements must be either an a or button.



I've overridden the button and a styles so they do not appear to be any different. In a desktop browser they don't appear to behave differently either.



But open the chrome "device emulation" from dev tools, and you can see that the button and a elements have different behaviors. Their respective target click areas seem to be smaller, and you must directly hit the svg "X" instead of any part of the block level element.



I've tried both an a and button element. I've also recreated the issue inside of a jsfiddle.



This jsfiddle reproduces the issue (test in mobile device emulator mode in chrome) https://jsfiddle.net/8jze13t0/1/






// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>





Here is an screenshot of the issue (w/ annotations):



enter image description here



I expect to be able to click anywhere within the block level element within the mobile emulator and trigger the event handler.










share|improve this question
















I am modifying the UI code per our analytics teams request. All clickable elements must be either an a or button.



I've overridden the button and a styles so they do not appear to be any different. In a desktop browser they don't appear to behave differently either.



But open the chrome "device emulation" from dev tools, and you can see that the button and a elements have different behaviors. Their respective target click areas seem to be smaller, and you must directly hit the svg "X" instead of any part of the block level element.



I've tried both an a and button element. I've also recreated the issue inside of a jsfiddle.



This jsfiddle reproduces the issue (test in mobile device emulator mode in chrome) https://jsfiddle.net/8jze13t0/1/






// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>





Here is an screenshot of the issue (w/ annotations):



enter image description here



I expect to be able to click anywhere within the block level element within the mobile emulator and trigger the event handler.






// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>





// script.js
let i = 0;
const closeBtns = document.querySelectorAll('.close');
const clickCount = document.querySelector('.click-count');

Array.from(closeBtns).forEach(btn => btn.addEventListener('click', (e) =>
e.preventDefault();
i++;
clickCount.innerText = i;
))


clickCount.innerText = i;

body 
background: darkBlue;
color: white;
font-family: sans-serif;


.close
margin-top: 10px;
white-space: nowrap;
text-indent: 100%;
overflow: hidden;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M10.4809 10.0128L19.9119 0.579492C20.0423 0.479492 20.0423 0.246029 19.9119 0.112695C19.7819 -0.020638 19.5709 -0.020638 19.4406 0.112695L10.0096 9.54564L0.578599 0.112695C0.448599 -0.020638 0.237599 -0.020638 0.107266 0.112695C-0.0227344 0.246029 -0.0227344 0.479492 0.107266 0.579492L9.53826 10.0128L0.107266 19.4457C-0.0227344 19.5794 -0.0227344 19.8128 0.107266 19.9128C0.172599 19.9795 0.257599 20.0128 0.342933 20.0128C0.428266 20.0128 0.513599 19.9795 0.578599 19.9128L10.0096 10.5128L19.4406 19.9128C19.5059 19.9795 19.5909 20.0128 19.6763 20.0128C19.7616 20.0128 19.8469 19.9795 19.9119 19.9128C20.0423 19.8128 20.0423 19.5794 19.9119 19.4457L10.4809 10.0128Z' fill='white'/%3E%3C/svg%3E");
width: 20px;
height: 20px;
margin-right: 16px;
display: block;


button
outline: 0;
border: 0;
background: none;
padding: 0;
font-family: inherit;
font-style: inherit;
cursor: pointer;

<p>
Click Count:
<span class="click-count">
</span>
</p>

<p>
First Example With `div:`
<div class="close">
Close me
</div>
</p>


<p>
Second Example With `button`
<button class="close">
Close me
</button>
</p>

<p>
Third Example With `a`
<a href="#close" class="close">
Close me
</a>
</p>






javascript html css button dom-events






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 18:26









j08691

173k22 gold badges207 silver badges223 bronze badges




173k22 gold badges207 silver badges223 bronze badges










asked Mar 28 at 18:24









Charlie HooverCharlie Hoover

263 bronze badges




263 bronze badges















  • Side note, <p> elements can't contain <div>s

    – j08691
    Mar 28 at 18:27











  • It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

    – Huangism
    Mar 28 at 18:49












  • @Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

    – Charlie Hoover
    Mar 28 at 18:54












  • @CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

    – Huangism
    Mar 28 at 18:57


















  • Side note, <p> elements can't contain <div>s

    – j08691
    Mar 28 at 18:27











  • It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

    – Huangism
    Mar 28 at 18:49












  • @Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

    – Charlie Hoover
    Mar 28 at 18:54












  • @CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

    – Huangism
    Mar 28 at 18:57

















Side note, <p> elements can't contain <div>s

– j08691
Mar 28 at 18:27





Side note, <p> elements can't contain <div>s

– j08691
Mar 28 at 18:27













It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

– Huangism
Mar 28 at 18:49






It has something to do with the way you are hiding your text. Remove the text, remove text-indent and overflow, works like normal. Why put text in it if you are not going to use it

– Huangism
Mar 28 at 18:49














@Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

– Charlie Hoover
Mar 28 at 18:54






@Huangism the text is for screen readers and search engines. I can remove it in place of a aria-label attribute... but I'm not sure why it has a different impact on button than on div.

– Charlie Hoover
Mar 28 at 18:54














@CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

– Huangism
Mar 28 at 18:57






@CharlieHoover I thought so (screenreader) but there are other options for that, see my answer. As for why, I am not sure, mobile browser must have some kind of rule that makes it weird. Also we are on chrome dev tools, it may or may not behave the same on a real device

– Huangism
Mar 28 at 18:57













4 Answers
4






active

oldest

votes


















3
















Remove the text and the styles associated with it



remove these extra rules



white-space: nowrap;
text-indent: 100%;
overflow: hidden;


Also remove the text from the html, why have it if you are not going to use it



If you want the text for screenreader, you can use aria-label="whatever" on the element



<a href="whatever" aria-label="whatever label">





share|improve this answer
































    0
















    As soon as I removed text-indent: 100%; from the .close items, the odd behavior in mobile went away.



    What is that rule attempting to do? Could padding-left work better? (I assume you are trying to avoid the text laying on top of the background image X icon)






    share|improve this answer

























    • It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

      – Charlie Hoover
      Mar 28 at 20:02











    • I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

      – BugsArePeopleToo
      Mar 28 at 20:09



















    0
















    Trying to figure out the specific question. Not sure what you want to achieve visually - although i did notice this part:




    Their respective target click areas seem to be smaller, and you must
    directly hit the svg "X" instead of any part of the block level
    element.




    Part of this is that "a" and "button" elements are what are referred to as (by default) "inline" display elements. Maybe try adding a style definition like this:



    a, button 
    display: block;



    This should allow for the a/button elements to take up more space and have more of a clickable area then just having a clickable area that is equal to the contents inside the a/button element. You might also want to set something like this if you want to force a minimum width:



    a, button 
    display: block;
    min-width: 100px;



    Other then that maybe providing an example of what it looked like before - or what you want it to look/behave like? This is all also assuming you aren't using any CSS framework (vanilla CSS)?






    share|improve this answer

























    • You should read the entire question and try the fiddle

      – Huangism
      Mar 28 at 19:02











    • true that - my bad

      – user1507627
      Mar 28 at 21:03


















    0
















    It looks like your text-indent:100% is causing that. Instead of doing that, you can remove it and make your text invisible with css like this color: rgba(0,0,0,0);. Once I made that change it seemed to make the whole surface area clickable.



    If you do it that way, make sure you add color: rgba(0,0,0,0); to the hover state as well. Or you can just remove the text out of the html if that's an option.






    share|improve this answer

























    • Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

      – Charlie Hoover
      Mar 28 at 20:04











    • Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

      – Matthew T Rader
      Mar 28 at 20:08













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404502%2fwhy-does-this-button-element-have-different-click-behavior-than-a-div%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3
















    Remove the text and the styles associated with it



    remove these extra rules



    white-space: nowrap;
    text-indent: 100%;
    overflow: hidden;


    Also remove the text from the html, why have it if you are not going to use it



    If you want the text for screenreader, you can use aria-label="whatever" on the element



    <a href="whatever" aria-label="whatever label">





    share|improve this answer





























      3
















      Remove the text and the styles associated with it



      remove these extra rules



      white-space: nowrap;
      text-indent: 100%;
      overflow: hidden;


      Also remove the text from the html, why have it if you are not going to use it



      If you want the text for screenreader, you can use aria-label="whatever" on the element



      <a href="whatever" aria-label="whatever label">





      share|improve this answer



























        3














        3










        3









        Remove the text and the styles associated with it



        remove these extra rules



        white-space: nowrap;
        text-indent: 100%;
        overflow: hidden;


        Also remove the text from the html, why have it if you are not going to use it



        If you want the text for screenreader, you can use aria-label="whatever" on the element



        <a href="whatever" aria-label="whatever label">





        share|improve this answer













        Remove the text and the styles associated with it



        remove these extra rules



        white-space: nowrap;
        text-indent: 100%;
        overflow: hidden;


        Also remove the text from the html, why have it if you are not going to use it



        If you want the text for screenreader, you can use aria-label="whatever" on the element



        <a href="whatever" aria-label="whatever label">






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 18:53









        HuangismHuangism

        13.3k5 gold badges39 silver badges61 bronze badges




        13.3k5 gold badges39 silver badges61 bronze badges


























            0
















            As soon as I removed text-indent: 100%; from the .close items, the odd behavior in mobile went away.



            What is that rule attempting to do? Could padding-left work better? (I assume you are trying to avoid the text laying on top of the background image X icon)






            share|improve this answer

























            • It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

              – Charlie Hoover
              Mar 28 at 20:02











            • I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

              – BugsArePeopleToo
              Mar 28 at 20:09
















            0
















            As soon as I removed text-indent: 100%; from the .close items, the odd behavior in mobile went away.



            What is that rule attempting to do? Could padding-left work better? (I assume you are trying to avoid the text laying on top of the background image X icon)






            share|improve this answer

























            • It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

              – Charlie Hoover
              Mar 28 at 20:02











            • I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

              – BugsArePeopleToo
              Mar 28 at 20:09














            0














            0










            0









            As soon as I removed text-indent: 100%; from the .close items, the odd behavior in mobile went away.



            What is that rule attempting to do? Could padding-left work better? (I assume you are trying to avoid the text laying on top of the background image X icon)






            share|improve this answer













            As soon as I removed text-indent: 100%; from the .close items, the odd behavior in mobile went away.



            What is that rule attempting to do? Could padding-left work better? (I assume you are trying to avoid the text laying on top of the background image X icon)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 18:57









            BugsArePeopleTooBugsArePeopleToo

            2,4311 gold badge9 silver badges14 bronze badges




            2,4311 gold badge9 silver badges14 bronze badges















            • It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

              – Charlie Hoover
              Mar 28 at 20:02











            • I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

              – BugsArePeopleToo
              Mar 28 at 20:09


















            • It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

              – Charlie Hoover
              Mar 28 at 20:02











            • I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

              – BugsArePeopleToo
              Mar 28 at 20:09

















            It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

            – Charlie Hoover
            Mar 28 at 20:02





            It's pretty common practice for image replacement of text. In this case the text is not visible, but should still be read by screen-readers, and search engines.

            – Charlie Hoover
            Mar 28 at 20:02













            I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

            – BugsArePeopleToo
            Mar 28 at 20:09






            I thought that is what aria-label is for. developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/… . Maybe something to consider if the text-indent property is producing undesirable side effects.

            – BugsArePeopleToo
            Mar 28 at 20:09












            0
















            Trying to figure out the specific question. Not sure what you want to achieve visually - although i did notice this part:




            Their respective target click areas seem to be smaller, and you must
            directly hit the svg "X" instead of any part of the block level
            element.




            Part of this is that "a" and "button" elements are what are referred to as (by default) "inline" display elements. Maybe try adding a style definition like this:



            a, button 
            display: block;



            This should allow for the a/button elements to take up more space and have more of a clickable area then just having a clickable area that is equal to the contents inside the a/button element. You might also want to set something like this if you want to force a minimum width:



            a, button 
            display: block;
            min-width: 100px;



            Other then that maybe providing an example of what it looked like before - or what you want it to look/behave like? This is all also assuming you aren't using any CSS framework (vanilla CSS)?






            share|improve this answer

























            • You should read the entire question and try the fiddle

              – Huangism
              Mar 28 at 19:02











            • true that - my bad

              – user1507627
              Mar 28 at 21:03















            0
















            Trying to figure out the specific question. Not sure what you want to achieve visually - although i did notice this part:




            Their respective target click areas seem to be smaller, and you must
            directly hit the svg "X" instead of any part of the block level
            element.




            Part of this is that "a" and "button" elements are what are referred to as (by default) "inline" display elements. Maybe try adding a style definition like this:



            a, button 
            display: block;



            This should allow for the a/button elements to take up more space and have more of a clickable area then just having a clickable area that is equal to the contents inside the a/button element. You might also want to set something like this if you want to force a minimum width:



            a, button 
            display: block;
            min-width: 100px;



            Other then that maybe providing an example of what it looked like before - or what you want it to look/behave like? This is all also assuming you aren't using any CSS framework (vanilla CSS)?






            share|improve this answer

























            • You should read the entire question and try the fiddle

              – Huangism
              Mar 28 at 19:02











            • true that - my bad

              – user1507627
              Mar 28 at 21:03













            0














            0










            0









            Trying to figure out the specific question. Not sure what you want to achieve visually - although i did notice this part:




            Their respective target click areas seem to be smaller, and you must
            directly hit the svg "X" instead of any part of the block level
            element.




            Part of this is that "a" and "button" elements are what are referred to as (by default) "inline" display elements. Maybe try adding a style definition like this:



            a, button 
            display: block;



            This should allow for the a/button elements to take up more space and have more of a clickable area then just having a clickable area that is equal to the contents inside the a/button element. You might also want to set something like this if you want to force a minimum width:



            a, button 
            display: block;
            min-width: 100px;



            Other then that maybe providing an example of what it looked like before - or what you want it to look/behave like? This is all also assuming you aren't using any CSS framework (vanilla CSS)?






            share|improve this answer













            Trying to figure out the specific question. Not sure what you want to achieve visually - although i did notice this part:




            Their respective target click areas seem to be smaller, and you must
            directly hit the svg "X" instead of any part of the block level
            element.




            Part of this is that "a" and "button" elements are what are referred to as (by default) "inline" display elements. Maybe try adding a style definition like this:



            a, button 
            display: block;



            This should allow for the a/button elements to take up more space and have more of a clickable area then just having a clickable area that is equal to the contents inside the a/button element. You might also want to set something like this if you want to force a minimum width:



            a, button 
            display: block;
            min-width: 100px;



            Other then that maybe providing an example of what it looked like before - or what you want it to look/behave like? This is all also assuming you aren't using any CSS framework (vanilla CSS)?







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 19:00









            user1507627user1507627

            264 bronze badges




            264 bronze badges















            • You should read the entire question and try the fiddle

              – Huangism
              Mar 28 at 19:02











            • true that - my bad

              – user1507627
              Mar 28 at 21:03

















            • You should read the entire question and try the fiddle

              – Huangism
              Mar 28 at 19:02











            • true that - my bad

              – user1507627
              Mar 28 at 21:03
















            You should read the entire question and try the fiddle

            – Huangism
            Mar 28 at 19:02





            You should read the entire question and try the fiddle

            – Huangism
            Mar 28 at 19:02













            true that - my bad

            – user1507627
            Mar 28 at 21:03





            true that - my bad

            – user1507627
            Mar 28 at 21:03











            0
















            It looks like your text-indent:100% is causing that. Instead of doing that, you can remove it and make your text invisible with css like this color: rgba(0,0,0,0);. Once I made that change it seemed to make the whole surface area clickable.



            If you do it that way, make sure you add color: rgba(0,0,0,0); to the hover state as well. Or you can just remove the text out of the html if that's an option.






            share|improve this answer

























            • Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

              – Charlie Hoover
              Mar 28 at 20:04











            • Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

              – Matthew T Rader
              Mar 28 at 20:08















            0
















            It looks like your text-indent:100% is causing that. Instead of doing that, you can remove it and make your text invisible with css like this color: rgba(0,0,0,0);. Once I made that change it seemed to make the whole surface area clickable.



            If you do it that way, make sure you add color: rgba(0,0,0,0); to the hover state as well. Or you can just remove the text out of the html if that's an option.






            share|improve this answer

























            • Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

              – Charlie Hoover
              Mar 28 at 20:04











            • Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

              – Matthew T Rader
              Mar 28 at 20:08













            0














            0










            0









            It looks like your text-indent:100% is causing that. Instead of doing that, you can remove it and make your text invisible with css like this color: rgba(0,0,0,0);. Once I made that change it seemed to make the whole surface area clickable.



            If you do it that way, make sure you add color: rgba(0,0,0,0); to the hover state as well. Or you can just remove the text out of the html if that's an option.






            share|improve this answer













            It looks like your text-indent:100% is causing that. Instead of doing that, you can remove it and make your text invisible with css like this color: rgba(0,0,0,0);. Once I made that change it seemed to make the whole surface area clickable.



            If you do it that way, make sure you add color: rgba(0,0,0,0); to the hover state as well. Or you can just remove the text out of the html if that's an option.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 19:16









            Matthew T RaderMatthew T Rader

            1168 bronze badges




            1168 bronze badges















            • Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

              – Charlie Hoover
              Mar 28 at 20:04











            • Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

              – Matthew T Rader
              Mar 28 at 20:08

















            • Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

              – Charlie Hoover
              Mar 28 at 20:04











            • Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

              – Matthew T Rader
              Mar 28 at 20:08
















            Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

            – Charlie Hoover
            Mar 28 at 20:04





            Not a bad strategy... Although I'm still not sure why clicking any part of the block level element wouldn't trigger the event handler. This is a pretty common practice for replacing text with an image.

            – Charlie Hoover
            Mar 28 at 20:04













            Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

            – Matthew T Rader
            Mar 28 at 20:08





            Well this is a browser specific issue, it's more about how Chrome is interpreting text-indent. As a front end developer we deal weird behaviors in various browsers all the time. It looks like if you want that area to be clickable on Chrome then you will have to do a workaround like we suggested otherwise leave it how you have it.

            – Matthew T Rader
            Mar 28 at 20:08


















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404502%2fwhy-does-this-button-element-have-different-click-behavior-than-a-div%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현