3

问题: 我有一个响应式设计和一个 2 列的链接集。每组链接都是一个列表。它们居中对齐。当您悬停时,应该在文本旁边出现一个箭头,但我无法流畅地定位它。我想出的最好的方法是将箭头绝对定位在悬停上,这样它就可以与我的所有列表项“工作”。虽然看起来很垃圾。我希望它位于每个列表中每个 h3 的左侧。我只是还没有想出一个聪明的方法来做到这一点。

<div class="contentLeft">
        <ul class="ca-menu">
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>  
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
        </ul>
    </div>
    <div class="contentRight">
        <ul class="ca-menu">
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>  
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
            <li>
                <a href="#">
                    <div class="ca-content">
                        <h3 class="ca-main"><img src="<?php bloginfo('template_url') ?>/images/arrow-hover.jpg" class="arrow" width="61" height="29" alt="Arrow Hover">This is the link</h3>
                        <p class="ca-sub">This is the subheading</p>
                    </div>
                </a>
            </li>
        </ul>
        </div>

这是我的CSS:

    .arrow {
  display: none;
  width: 61px;
     }
.ca-menu li:hover .arrow {
  display: inline;
  width: 61px;
  position: absolute;
  top: 10px;

}
.ca-menu {
  margin-left: 0;
  padding-left: 0;
  z-index: 1;
}
.ca-menu li {
  height: 100px;
  overflow: hidden;
  position: relative;
  display: block;
  margin-bottom: 4px;
  -webkit-transition: all 300ms linear;
  -moz-transition: all 300ms linear;
  -o-transition: all 300ms linear;
  -ms-transition: all 300ms linear;
  transition: all 300ms linear;
}
.ca-menu li:last-child {
  margin-bottom: 0px;
}
.ca-menu li a {
  text-align: center;
  width: 100%;
  height: 100%;
  display: block;
  color: #333;
  position: relative;
  text-decoration: none;
}
.ca-content {
  height: 60px;
}
.ca-main {
  font-size: 26px;
  color: #666;
  margin-bottom: 10px;
  text-decoration: none;
  line-height: 29px;
  -webkit-transition: all 300ms linear;
  -moz-transition: all 300ms linear;
  -o-transition: all 300ms linear;
  -ms-transition: all 300ms linear;
  transition: all 300ms linear;
}
.ca-sub {
  color: #999 !important;
  -webkit-transition: all 300ms linear;
  -moz-transition: all 300ms linear;
  -o-transition: all 300ms linear;
  -ms-transition: all 300ms linear;
  transition: all 300ms linear;
}
.ca-menu li:hover .ca-icon {
  color: #e3721e;
  opacity: 0.8;
  text-shadow: 0px 0px 13px #fff;
}
.ca-menu li:hover .ca-main {
  opacity: 1;
  color: #e3721e;
  -webkit-animation: moveFromTop 300ms ease-in-out;
  -moz-animation: moveFromTop 300ms ease-in-out;
  -ms-animation: moveFromTop 300ms ease-in-out;
}
.ca-menu li:hover .ca-sub {
  opacity: 1;
  -webkit-animation: moveFromBottom 300ms ease-in-out;
  -moz-animation: moveFromBottom 300ms ease-in-out;
  -ms-animation: moveFromBottom 300ms ease-in-out;
  color: #333 !important;
}

任何帮助表示赞赏。谢谢!

4

2 回答 2

0

开始了一个 jsfiddle 来开始这方面的工作,因为它绝对值得关注。现在我不确定我是否得到了你想要的东西,但我很肯定这需要更多的工作。我得到了起始格式和箭头外观,但是要激活两者,您需要将鼠标特别悬停在链接中的“the”一词上并将鼠标向上滑动一点。我将继续解决这个问题,以便您可以实际使用我提供的内容,但如果您还有其他想要的不同之处,请告诉我。

这是小提琴:在这里链接的jsfiddle :)

于 2012-09-03T03:33:47.033 回答
0

对此的快速解决方法是 -ve 边距。是一个有效的现场演示。但是你必须考虑一些事情。如果您为图像分配高度和宽度,如果它没有改变,并且如果您已经在 CSS 中设置了它,则不需要将它与<img>. 只需在 CSS 中定义图像宽度和高度。

于 2012-09-03T04:00:34.480 回答