gpt4 book ai didi

javascript - 带有下拉菜单效果的单按钮 - 帮助优化

转载 作者:行者123 更新时间:2023-11-28 05:41:49 25 4
gpt4 key购买 nike

我在一个客户网站上工作,他们希望在网站的主横幅上有一个下拉按钮。

我能够编写代码并让它工作,但它似乎有点喜怒无常。该按钮有效,但不是每次单击它时都不会,而且肯定不会顺利。有人可以看看这个并让我知道他们是否与此代码有其他冲突,或者我可以做些什么来微调它并让它更好地工作?

我正在使用以下 CSS:

  /* Dropdown Button */
.dropbtn {
background-color: rgba(102, 146, 255, 0.87);
color: white;
padding: 9px 15px 14px 15px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 6px;
}

/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #6692FF;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 9px 32px;
text-decoration: none;
display: block !important;
border-bottom: 1px solid #4A5056;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f9f9f9}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

以下 HTML:

<div class="dropdown">
<button onclick="myFunction()" class="dropbtn"><span style=" vertical-align: bottom;font-size: 24px; ">LISTEN</span> <i class="fa fa-volume-up fa-4x"></i></button>
<div id="myDropdown" class="dropdown-content">
<a href="http://lonebeacondevelopment.com/financialexchange/listen-live/" class="popup" data-height="300" data-width="300" data-scrollbars="0" alt="LISTEN LIVE">
LISTEN LIVE</a>
<a href="http://lonebeacondevelopment.com/financialexchange/on-demand/">ON DEMAND</a>
</div>
</div>

以及以下 JS:

/* When the user clicks on the button, 
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
window.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');
}
}
}
}

链接是http://lonebeacondevelopment.com/financialexchange/是横幅右上角的蓝色“收听”按钮。

如有任何帮助,我们将不胜感激。

非常感谢!

最佳答案

好的,您可以删除按钮内的 span 并像这样在按钮类中粘贴 span 样式

CSS

/* Dropdown Button */
.dropbtn {
background-color: rgba(102, 146, 255, 0.87);
color: white;
padding: 9px 15px 14px 15px;
font-size: 16px;
border: none;
cursor: pointer;
border-radius: 6px;

vertical-align: bottom;font-size: 24px; /*HERE The CODE of SPAN*/

}

/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #6692FF;
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 9px 32px;
text-decoration: none;
display: block !important;
border-bottom: 1px solid #4A5056;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f9f9f9}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

HTML

<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">LISTEN <i class="fa fa-volume-up fa-4x"></i></button>
<div id="myDropdown" class="dropdown-content">
<a href="http://lonebeacondevelopment.com/financialexchange/listen-live/" class="popup" data-height="300" data-width="300" data-scrollbars="0" alt="LISTEN LIVE">
LISTEN LIVE</a>
<a href="http://lonebeacondevelopment.com/financialexchange/on-demand/">ON DEMAND</a>
</div>
</div>

关于javascript - 带有下拉菜单效果的单按钮 - 帮助优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37841647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com