当显示的内容在数据库中为空值时隐藏div

mdfafbf1  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(376)

我有一个字体awesome div,它漂浮在我的图片的顶部,提供图片的细节,这些细节是从mysql数据库中提取的。
当我将鼠标悬停在这个(info)字体的图标上时,一个很小的内联就会打开,其中包含来自mysql的内容。
现在,当内容为空时,我不希望字体出现。
下面是我的代码。

<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>

此悬停弹出窗口的css是


# 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;
        }

现在,当有空值时,它会按字面意思显示“class='display none'”
我该怎么做才能在空值期间使图标完全消失?
我应该使用js还是jquery?

0mkxixxg

0mkxixxg1#

你用上面的符号混淆了风格和类,也许这样更好?

<div id="hotspot1" class="hotspot" style = "position: fixed;">
    <i class="fa fa-info-circle" style="font-size:48px;color:cyan"></i>

        <?php
            $style=is_null( $details ) ? "style='display:none'" : "";
        ?>
        <div class="hover-popup well" <?php echo $style;?> >

        </div>
</div>

或者,不是添加内联样式,而是按照您最初尝试的方式指定一个类,而是在css中的某个地方定义该类。然后,您可以使用类似的表示法,但可以引用类,例如:

<style>.dispnone{ display:none; }</style>

<?php
    $class=is_null( $details ) ? "class='dispnone'" : "";
?>

<div class="hover-popup well" <?php echo $class;?> >
nhaq1z21

nhaq1z212#

class属性需要在它应用到的元素中,您当前正在 echo 在任何元素之外添加,这就是你在页面上看到它的原因。
我不知道你到底想达到什么目的,但似乎你想显示一些特定的html的时候 $details 不是 null .
这至少能给你一些线索,

<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>

在上述代码中,如果 $details 不是 null 然后输出php块之间的html,否则不输出。您可能需要将所有的html放在php块之间。

相关问题