gpt4 book ai didi

html - 使下拉宽度适应其内容

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:58 25 4
gpt4 key购买 nike

我有以下 CSS 和 HTML:

.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: inline-block;
width: auto;
}

.dropdown-content a:hover {
background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
display: inline-block;
}

.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<body>
<div class="dropdown" style="float:left;">
<button class="dropbtn">Left</button>
<div class="dropdown-content" style="left:0;">
<a href="#">Make this phrase appear on one line.</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>

</body>

我希望下拉列表中的所有菜单项都在线显示 - 无论它们有多长。人们说 display: inline-block 让这一切发生了。仍然没有成功。你能给个提示吗?

最佳答案

一个不错的老式 white-space: nowrap; 怎么样?

.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
position: absolute;
left: 0;
display: none;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
white-space: nowrap;
}

.dropdown-content a:hover {
background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
display: inline-block;
}

.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<body>
<div class="dropdown" style="float:left;">
<button class="dropbtn">Left</button>
<div class="dropdown-content" style="left:0;">
<a href="#">Make this phrase appear on one line.</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>

</body>

关于html - 使下拉宽度适应其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42885013/

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