【问题标题】:Issue with aligning back arrow with dropdown将后退箭头与下拉菜单对齐的问题
【发布时间】:2015-06-30 10:54:52
【问题描述】:

在下拉菜单旁边放置后退箭头时遇到问题。问题是它使箭头居中,就好像下拉菜单处于活动状态一样。我希望它在下拉列表的左侧未对齐。

我包含了一个 jsfiddle 显示显示。

HTML

<div id="portfolio">
 <table>
 <tr>
 <td>
    <a href="index.html"><div class="back-arrow-left" ></div></a>
 </td>
 <td>
 <dropdown>
    <input id="toggle2" type="checkbox">
    <label for="toggle2" class="animate">Portfolio<i class="fa fa-list float-right"></i></label>
    <ul class="animate">
       <li class="animate">Websites</li>
       <li class="animate">Computer Animations</li>
       <li class="animate">C/C++ Programs</li>
    </ul>
 </dropdown>
 </td>
 </tr>
 </table>
 </div>

CSS

.back-arrow-left {
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-right:30px solid gray;
vertical-align: top;
}

.back-arrow-left:hover {
border-right:30px solid #1ABC9C;
}

#portfolio{
width: 400px;
float: right;
}

*{
 padding: 0;
 margin: 0;
 font-family: 'Lato', sans-serif;
 box-sizing: border-box;
   }
   .float-right{
 float: right;
   }
   .fa{
    font-size: .8em;
  line-height: 22px !important;
    }
    dropdown{
   display: inline-block;
   margin: 0px 50px;
    }
    dropdown label, dropdown ul li{
    display: block;
    width: 200px;
    background: #ECF0F1;
    padding: 15px 20px;
     }
   dropdown label:hover, dropdown ul li:hover{
   background: #1ABC9C;
   color: white;
   cursor: pointer;}

   dropdown label{
   color: #1ABC9C;
   border-left: 4px solid #1ABC9C;
   border-radius: 0 5px 0 0; 
  position: relative;
   z-index: 2;
}
  dropdown input{
  display: none;
}
dropdown input ~ ul{
position: relative;
 visibility: hidden;
 opacity: 0;
 top: -20px;
 z-index: 1;
}
dropdown input:checked + label{
 background: #1ABC9C;
 color: white;
 }

dropdown input:checked ~ ul{
 visibility: visible;
 opacity: 1;
 top: 0;
 }
  $colors: #E74C3C, #0072B5, #2C3E50;

@for $i from 1 through length($colors) {
 dropdown ul li:nth-child(#{$i}) {
  border-left: 4px solid nth($colors, $i);
  .fa{
    color: nth($colors, $i);
  }
  &:hover {
    background: nth($colors, $i);
    color: white;
    .fa{
    color: white; 
    }
  }
  }
 }

.animate{
-webkit-transition: all .3s;
-moz-transition: all .3s;
-ms-transition: all .3s;
-ms-transition: all .3s;
transition: all .3s;  
backface-visibility:hidden;
-webkit-backface-visibility:hidden; /* Chrome and Safari */
-moz-backface-visibility:hidden; /* Firefox */
-ms-backface-visibility:hidden; /* Internet Explorer */

http://jsfiddle.net/e1nuabgs/

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以为持有后退箭头的表格数据赋予一个类,并更改顶部的垂直对齐方式。

    .arrow_box{
        vertical-align: top;
    }
    

    Updated jsFiddle

    【讨论】:

      【解决方案2】:

      您使用这张桌子有什么特别的原因吗?这不符合 HTML 5 标准,以后可能会导致问题。

      事实上,它是导致您的问题的表。您有围绕数据的表格,应该将其定向到您想要的顺序,但是您已经使用 css 将其与表格对齐!

      如果您取出表格并在您的 css 中添加一行,它就可以完美地工作。

      .back-arrow-left {
             float: left;
             width: 0;
             height: 0;
             border-top: 30px solid transparent;
             border-bottom: 30px solid transparent;
             border-right:30px solid gray;
             vertical-align: top;
      }
      
      <div id="portfolio">
          <a href="index.html"><div class="back-arrow-left" ></div></a>
          <dropdown>
            <input id="toggle2" type="checkbox">
            <label for="toggle2" class="animate">Portfolio<i class="fa fa-list float-right"></i></label>
               <ul class="animate">
                 <li class="animate">Websites</li>
                 <li class="animate">Computer Animations</li>
               <li class="animate">C/C++ Programs</li>
            </ul>
         </dropdown>
       </div>
      

      I've updated your JSFiddle

      【讨论】:

      • 我最初尝试了一个 div 并提出了一个错误,所以我只是尝试不同的方法让它工作并制作一个表格。我在这里提交的不是干净的代码。谢谢,虽然这很好用。
      • 很公平。 :) 如果它再次发生,请注意浮动在正确的位置并且您的 div 宽度不重叠。你有它! :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多