标题栏不包括下拉列表(CSS)

时间:2018-05-26 00:21:03

标签: html css alignment

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

我需要下拉菜单位于栏的右上角。你不必为我做代码,但我想弄清楚是否有两种不同的风格相互交叉并导致这个或我接下来应该做什么?

* {
  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>

2 个答案:

答案 0 :(得分:0)

<div class="headDivider">

     <div style="float:left;">

         <table>
             <tr>
                <td>
                    <button type="button" class="back">Back</button>
                 </td>
                 <td>   
                     <h4 class="title"> Viking Vote + </h4>
                 </td>
             </tr>
         </table>            

     </div>
     <div style="float:right;">

         <table>
             <tr>
                <td>
                     <div>
                         <button class="dropbtn">Dropdown</button>
                     </div> 
                 </td>
                 <td>       
                     <div class="dropdown" style="text-align:right;">

                         <div class="dropdown-content">
                             <a href="#">Link 1</a>
                             <a href="#">Link 2</a>
                             <a href="#">Link 3</a>
                         </div>
                     </div>
                 </td>
             </tr>
         </table>

    </div>
 </div>

答案 1 :(得分:0)

其中一个变种是使用flexbox for headDivider

.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此解决方案和其他元素的小修补程序