【问题标题】:Show <div> on certain <td>在某些 <td> 上显示 <div>
【发布时间】:2018-06-28 22:47:43
【问题描述】:

我想在某个表的某个&lt;td&gt; 上显示某个&lt;div&gt;。这是我在 HTML 中尝试的内容:

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td width="10%" valign="middle">{$avatar}{$change_avatar}</td>
        <td class="trow1" width="90%" valign="top">
            {$online_status}<span class="largetext"><strong>{$formattedname}</strong></span>
            <div class="smalltext">{$groupimage}</div>
        </td>
    </tr>
</table>

在这段代码上,我有这个:

$change_avatar = '<div class="change_avatar"><a href="usercp.php?action=avatar">Change Avatar</a></div>';

当鼠标移到表格的第一个 &lt;td&gt; 时,我想在鼠标悬停时显示 {$change_avatar},代码如上所示。

这是我使用的 CSS;

.change_avatar{
    display: none;
    font-size: 11px;
    background: #363737;
    color: #FFF;
    opacity: 0.8;
    border-radius: 2px;
    padding: 3px 5px;
}

.change_avatar a:link, .change_avatar a:visited, .change_avatar a:active{
    color: #FFF !important;
    text-decoration: none;
}

td:hover .change_avatar{
    display: inline;
    margin-top: 50px;
    margin-left: -70px;
    position: absolute;
}

请帮忙。

【问题讨论】:

标签: php css html-table


【解决方案1】:

试试这个:

CSS:

.change_avatar{
    display: none;
    font-size: 11px;
    background: #363737;
    color: #FFF;
    opacity: 0.8;
    border-radius: 2px;
    padding: 3px 5px;
}

.change_avatar a:link, .change_avatar a:visited, .change_avatar a:active{
    color: #FFF !important;
    text-decoration: none;
}

td #change_avatar:hover .change_avatar{
    display: inline;
    margin-top: 50px;
    margin-left: -70px;
    position: absolute;
}

HTML:

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td width="10%" valign="middle" id="change_avatar">{$avatar}{$change_avatar}</td>
        <td class="trow1" width="90%" valign="top">
            {$online_status}<span class="largetext"><strong>{$formattedname}</strong></span>
            <div class="smalltext">{$groupimage}</div>
        </td>
    </tr>
</table>

【讨论】:

    【解决方案2】:

    您可以使用 JQuery 来实现这一点。例如你有 id="avatarTD"

    $("#avatarTD").mouseover(function(){
        $(".change_avatar").show();
    });
    
    $("#avatarTD").mouseout(function(){
        $(".change_avatar").hide();
    });
    

    【讨论】:

    • 我真的不想在这么小的事情上使用 jQuery,谢谢你的尝试
    猜你喜欢
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多