How To Open Dropdown Button By Clicking On Text?
I'm setting a dropdown button on my website, but I get this weird thing. The dropdown part only shows when I click on the box of the button, but not when I click on 'Tools'. What a
Solution 1:
Remove the strong tag from the button.
<body><divclass="column-outlet"><buttononclick="myFunction()"class="dropbtn">Tools</button><divid="myDropdown"class="dropdown-content"><liclass="force-css"><ahref="#">Blok 1</a></li><liclass="force-css"><ahref="#">Blok 1</a></li><liclass="force-css"><ahref="#">Blok 1</a></li></div></div></body>
Solution 2:
Don't use tag into button but text-weight in CSS and use UL tag to create the list
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */functionmyFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of itwindow.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
overflow: auto;
box-shadow: 0px8px16px0pxrgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-contenta {
color: black;
padding: 12px16px;
text-decoration: none;
display: block;
}
button.dropbtn{
font-weight: 700;
background:none;
border:none;
padding:0;
}
.dropdowna:hover {background-color: #ddd;}
.show {display: block;}
<body><divclass="column-outlet"><buttononclick="myFunction()"class="dropbtn">Tools</button><ulid="myDropdown"class="dropdown-content"><liclass="force-css"><ahref="#">Blok 1</a></li><liclass="force-css"><ahref="#">Blok 1</a></li><liclass="force-css"><ahref="#">Blok 1</a></li></ul></div>
Post a Comment for "How To Open Dropdown Button By Clicking On Text?"