dryb38654 2016-10-06 16:38
浏览 51
已采纳

当显示的内容在数据库中具有NULL值时隐藏DIV

I have a font awesome div which floats on top on my image, to give the image details, which are extracted from the mysql database.

When I hover over this (info) font awesome icon, a tiny inline opens up with the content from mysql.

Now when the content is NULL, I don't want the font awesome to show up at all.

the following is my code.

<div id="hotspot1" class="hotspot" style = "position: fixed;">
                <i class="fa fa-info-circle" style="font-size:48px;color:cyan"></i>
                <div class="hover-popup well">
                <?php 
                    if ($details == null) {
                        echo "class='display-none';";
                    }
                    else {
                        echo $details; 
                    }
                    ?>
                </div>
            </div>

The CSS for this hover pop up is

#hotspot1 {
            right:93%;
            top:3%;
        }

        .hotspot {
            line-height:20px;
            text-align:center;
            position:absolute;
            cursor: pointer;
        }

        .hotspot .text {
            width:80px;
            height:20px;
        }

        .hover-popup {
            display:none;
            z-index:auto;
        }

        .hotspot:hover .hover-popup {
            display:inline;
            position:absolute;
            left:100%;
            top:0;
            width:300px;
            height: auto;
            border:2px solid #000;
            margin: 20px;
            padding: 20px;
            font-size: 16px;
            background: #FBF0D9;
            font-style: oblique;

        .display-none {
            display:none;
        }

Now when there is a null value, it literally displays "class = 'display-none'"

What can I do to vanish the icon totally during null values?

Should I use JS or JQuery?

  • 写回答

2条回答 默认 最新

  • dougan7657 2016-10-06 17:11
    关注

    The class attribute needs to be inside the element it applies to, you are currently echoing outside of any elements, which is why you're seeing it on the page.

    I can't work out exactly what it is you're trying to achieve but it seems that you want to show some particular HTML when $details is not null.

    This should at least give you some clues,

    <div id="hotspot1" class="hotspot" style="position: fixed;">
    
       <?php if ($details != null): ?>
    
          <i class="fa fa-info-circle" style="font-size:48px;color:cyan"></i>
    
          <div class="hover-popup well">
             <?= $details; ?>
          </div>
    
       <?php endif; ?>
    
    </div>   
    

    In the above code, if $details is not null then the HTML between the PHP blocks will be output, otherwise not. You may want to put all the HTML between the PHP blocks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序