响应式悬停代码

时间:2018-06-01 01:32:02

标签: html css responsive

我正在使用悬停创建地图/平面图,但悬停图像+文字似乎没有响应图像。我使用的是固定值,我知道我应该使用%,但即使我这样做,我也没有足够的经验来使用它。

How it looks when image is not made responsive

How it looks when image is made responsive

CSS:

.hoverinfosupermarket {
    position: absolute;
    top:79%;
    left: 37%;
    font-size: 80%;
    font-family: Arial;
    font-weight: bold;
    color: #6e706f;
    cursor: default;
}

.hoverinfosupermarket p {
    display: none;
    color: #000000;
    font-size:10px;
}

.hoverinfosupermarket:hover p {
    background-color: rgba(255, 255, 255, 0.7);
    display: block;
}

HTML:

<div class="hoverinfosupermarket">
    <span>#B1-01</span>
    <p>
        <img alt="Supermarket" src="/cs/w/img/supermarket.jpg" /><br />
        Supermarket
    </p>
</div>

地图/平面图实际上位于标签内,悬停图像+文字也在此标签内。

<div class="tab">
    <button class="tablinks" onclick="openMap(event, 'B1')">B1</button>
    <button class="tablinks" onclick="openMap(event, 'L1')">L1</button>           
</div>

<script>

function openMap(evt, mapName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }

    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }

    document.getElementById(mapName).style.display = "block";
    evt.currentTarget.className += " active";
}
</script>

CSS:

.tab {
    overflow: hidden;
    border: 1px solid #ccc;
    background-color: #f1f1f1;
}

.tab button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
}

.tab button:hover {
    background-color: #ddd;
}

.tab button.active {
    background-color: #ccc;
}

.tabcontent {
    display: none;
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-top: none;
}

1 个答案:

答案 0 :(得分:0)

您的容器<div class="hoverinfosupermarket">应该有position: relative,然后将position: absolute添加到p代码。指定后,使用像素指定顶部和左侧。它会像魅力一样起作用。