M
M
Michael R.2015-10-02 13:18:54
PHP
Michael R., 2015-10-02 13:18:54

What is the best way to write this condition?

Hello!
There is the following block in the layout:

<p class="fileDescription">%'file_description'%</p>
. We need to make it so that we can determine how many characters (total number) will appear between the tags <p></p>, and if there are no characters at all, then assign this one <p> display=none.
Thank you!
udp
------------
Let's complicate the task.
There is
<p class="fileDescription">Описание: <span>%'file_description'%</span></p>

We need to understand if there are any characters between the given span, and if they are not there, then in P display display=none ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
EvgeniyKonstantinov, 2015-10-02
@EvgeniyKonstantinov

p:empty {
   display: none;
}

https://css-tricks.com/almanac/selectors/e/empty/

D
Dmitry, 2015-10-02
@mytmid

jQuery:

$(function(){
     $(".fileDescription span:empty").parent().hide();
});

C
Cat Anton, 2015-10-02
@27cm

It is possible like this:

<?php $description = 'file_description'; ?>
<p class="fileDescription"<?php if (!strlen($description)) echo ' style="display: none"'; ?>>
    Описание: <span><?php echo $description; ?></span>
</p>

Or like this:
<style>
    .hidden {
        display: none;
    }
</style>
<?php $description = 'file_description'; ?>
<p class="fileDescription<?php if (!strlen($description)) echo ' hidden'; ?>">
    Описание: <span><?php echo $description; ?></span>
</p>

Or wait until :has() appears in CSS and browsers start supporting it:
.fileDescription:has(span:empty) {
    display: none;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question