【问题标题】:Child element only covering parent image子元素仅覆盖父图像
【发布时间】:2014-05-14 07:48:50
【问题描述】:

我有一个菜单,我希望菜单项处于活动状态和悬停状态。我的问题在两张图片中得到了最好的说明。绿色背景颜色应仅覆盖深橙色区域(即图像)。

这是我现在的菜单:

这就是我想要的样子:

哪种方式最好切掉绿色元素的底部以获得这种效果?

到目前为止我在 JSFIDDLE 中的代码:

http://jsfiddle.net/HC5qC/

CSS:

nav ul {
    padding: 0;
    list-style-type: none;
    position: absolute;
    right: 96px;
    top: 37px;
}

nav li {
    float: left;
}

nav a {
    text-decoration: none;
    font-weight: 400;
    font-size: .9375em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fff;
    padding: 54px 15px 65px 15px;
    overflow: hidden;

}

.current-menu-item a,
.current-menu-item a:hover {
    background: #79bd8f; /* Old browsers */
    background: -moz-linear-gradient(top,  #79bd8f 30%, #00a388 99%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(30%,#79bd8f), color-stop(99%,#00a388)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #79bd8f 30%,#00a388 99%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #79bd8f 30%,#00a388 99%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #79bd8f 30%,#00a388 99%); /* IE10+ */
    background: linear-gradient(to bottom,  #79bd8f 30%,#00a388 99%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#79bd8f', endColorstr='#00a388',GradientType=0 ); /* IE6-9 */

}

nav a:hover {
    background: #6b1600;
    background: rgba(107, 22, 0, 0.2);
}

【问题讨论】:

  • 请在您的问题中发布您的 html 标记和 css。
  • 这是<img>..?这是背景..?那是渐变..?我们怎么知道..?
  • @HerrNilsson 为 .nav a 减少 css 中的填充底部。
  • 问题已更新
  • 我相信这是不可能的......我走了这么远:jsfiddle.net/HC5qC/7 但这不是你问题的答案

标签: html css


【解决方案1】:

我想知道像 FIDDLE 这样的东西是否可以帮助您入门。

我会多尝试一下,看看我们离你想要的结果有多近。

但概念是放置一个 :after 或 :before,或一个绝对定位的“叠加层”,并且能够点击后面的框。

CSS

.selector {
    width: 295px;
    height: 100px;
    overflow: hidden;
    background-color: transparent;
    position: relative;
}
.button1 {
    float: left;
    width: 32%;
    height: 100%;
    border: 1px solid white;
    background-color: blue;
}
.selector:after {
    content: '';
    width: 300px;
    height: 30px;
    position: absolute;
    top: 85px;
    left: 0px;
    transform: rotate(-3deg);
    background-color: red;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-29
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 1970-01-01
    • 2014-02-21
    相关资源
    最近更新 更多