【问题标题】:make div menu shrink with window使 div 菜单随窗口缩小
【发布时间】:2017-01-30 03:30:20
【问题描述】:

我正在尝试制作一个缩小窗口大小的菜单,我已经通过使用 % 来调整宽度,但是,我似乎无法让它适用于高度。

我尝试使用最大宽度/高度并将它们设置为自动。每当我将高度从 px 更改为 % 时,它都会完全消失。

代码笔:http://codepen.io/mikegr/pen/WRdNqo

HTML

    <ul class="ch-grid">
        <li>
            <div class="ch-item ch-img-1">
                <div class="ch-info">
                    <h3>Games</h3>
                    <p>
                        by Bill Hicks <a href="http://www.iristimes.com">Quickly! go there now</a>
                    </p>
                </div>
            </div>
        </li>
        <li>
            <div class="ch-item ch-img-2">
                <div class="ch-info">
                    <h3>Illustration</h3>
                    <p>
                        by Steven Wright <a href="http://www.independent.ie ">Captain Semantics</a>
                    </p>
                </div>
            </div>
        </li>
        <li>
            <div class="ch-item ch-img-3">
                <div class="ch-info">
                    <h3>Characters</h3>
                    <p>
                        by Johnny Vegas <a href="http://www.examiner.ie ">Lovable Mentalist</a>
                    </p>
                </div>
            </div>
        </li>
        <li>
            <div class="ch-item ch-img-4">
                <div class="ch-info">
                    <h3>Modelling</h3>
                    <p>
                        by Benedict Cumberbatch <a href="http://www.dribbble.com">Smartypants Himself</a>
                    </p>
                </div>
            </div>
        </li>
    </ul>

CSS

.ch-grid {
    margin: auto 0 0 0;
    padding: 0;
    text-align: center;
}

.ch-grid li {
    width: 12%;
    height: 220px;
    display: inline-block;
    margin: 0 auto;


}
.ch-item {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    cursor: default;
    box-shadow: inset 0 0 0 16px rgba(255,255,255,0.6), 0 1px 2px rgba(0,0,0,0.1);
    transition: all 0.4s ease-in-out;
}
.ch-img-1 {
    background-image:    url(http://images.clipartpanda.com/smiley-face-clip-art-ncEepeEcA.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 

}

.ch-img-2 {
    background-image:    url(http://i.ebayimg.com/images/a/T2eC16VHJHgE9n0yFjGLBP+DueFzkQ~~/s-l300.jpg);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 
}

    .ch-img-3 {
        background-image:    url(http://images.clipartpanda.com/smiley-face-png-happy_face_Clip_Art.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 

}
.ch-img-4 {
    background-image:    url(http://pix.iemoji.com/images/emoji/apple/ios-9/256/extraterrestrial-alien.png);
    background-size:     cover;                     
    background-repeat:   no-repeat;
    background-position: center center; 
}
.ch-info {
    position: absolute;

    width: inherit;
    height: inherit;
    border-radius: 50%;
    opacity: 0;
    transition: all 0.4s ease-in-out;
    transform: scale(0);
    -webkit-backface-visibility: hidden;
}
.ch-info h3 {
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 20px;
    margin: 0 30px;
    padding: 45px 0 0 0;
    height: 140px;
    font-family: 'Open Sans', Arial, sans-serif;
    text-shadow: 0 0 1px #fff, 0 1px 2px rgba(0,0,0,0.3);
}
.ch.info p {
    color: #fff;
    padding: 10px 5px;
    font-style: italic;
    font-size: 12px;
    border-top:1px solid rgba(255,255,255,0.5);
    opacity: 0;
    transition:all 1s ease-in-out 0.4s;
}
.ch-info p a {
    display: block;
    text-decoration: none;
    color: #fff;
    color: rgba(255,255,255,0.7);
    font-style: normal;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 9px;
    letter-spacing: 1px;
    padding-top: 4px;
    font-family: 'Open Sans', Arial, sans-serif;
}
.ch-info p a:hover {
    color: #fff222;
    color: rgba(255,242,34, 0.8);
}
.ch-item:hover .ch-info {
    transform: scale(1);
    opacity: 1;
}
ch-item:hover .ch-info p {
    opacity: 1;
    }

【问题讨论】:

    标签: html css


    【解决方案1】:

    您的.ch-grid li 需要一个可伸缩的高度,例如视口单位vh

    .ch-grid li {
        width: 12%;
        height: 50vh;
        display: inline-block;
        margin: 0 auto;
    }
    

    Updated codepen

    如果你想使用百分比,你需要给所有.ch-grid li父母一个高度,像这样

    html, body {
        height: 100%;
    }
    .ch-grid {
        margin: auto 0 0 0;
        padding: 0;
        text-align: center;
        height: 100%;
    }
    
    .ch-grid li {
        width: 12%;
        height: 50%;
        display: inline-block;
        margin: 0 auto;
    }
    

    Updated codepen 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多