gpt4 book ai didi

html - 标题栏不包含下拉菜单 (CSS)

转载 作者:行者123 更新时间:2023-11-28 01:38:50 25 4
gpt4 key购买 nike

我无法让下拉菜单与栏的其余部分(下面的代码)对齐在同一行中。我尝试使用边距和填充,但这也无济于事。任何指导将不胜感激。

我需要下拉菜单位于栏的右上角。您不必为我编写代码,但我正在尝试确定是否有两种不同的样式相互交叉并导致此问题或者我接下来应该做什么?

* {
margin: 0;
}

body {
background-color: #f2f2f2;
font-family: "Verdana";
}

.headDivider {
background-color: #ff7200;
color: #ffffff;
font-size: 30px;
line-height: 50px;
height: 63px;
vertical-align: middle;
padding-top: 3px;
}

.back {
border-radius: 13px;
font-family: "Verdana";
text-align: left;
color: #ffffff;
float: left;
font-size: 16px;
background: #7c7c7c;
padding: 10px 26px 10px 26px;
border: none;
display: inline-block;
margin-top: 10px;
margin-left: 10px;
}

.title {
text-align: center;
margin-right: 95px;
}

h1 {
text-align: center;
}

.topText {
font-size: 38px;
line-height: 270px;
color: #ff7200;
}

.bottomText {
line-height: 280px;
font-size: 38px;
color: #ff7200;
}


/* Dropdown Button */

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


/* The container <div> - needed to position the dropdown content */

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


/* Dropdown Content (Hidden by Default) */

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


/* Links inside the dropdown */

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


/* Change color of dropdown links on hover */

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


/* Show the dropdown menu on hover */

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


/* Change the background color of the dropdown button when the dropdown content is shown */

.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
<!DOCTYPE html>
<html>

<head>
<script type="text/javascript" src="test.js"></script>
<link rel="stylesheet" type="text/css" href="test.css">
</head>

<body>
<div class="headDivider">
<button type="button" class="back">Back</button>
<h4 class="title"> Viking Vote + </h4>

<div class="dropdown" style="text-align:right;">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>

</div>


</body>

</html>

最佳答案

其中一种变体是对 headDivider 使用 flexbox

.headDivider {
background-color: #ff7200;
color: #ffffff;
font-size: 30px;
line-height: 50px;
height: 63px;
vertical-align: middle;
padding-top: 3px;
display: flex;
justify-content: space-between;
align-items: center;
}

这是 fiddle使用此解决方案和对其他元素的小修复

关于html - 标题栏不包含下拉菜单 (CSS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50538256/

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