1

I am using the CSS display:none to hide divs in my html code. It works fine for divs that hold general html content and hides the content.

However, if the div happens to hold a PHP echo statement it does not hide the contents.

HTML

<span class="paginationFull"><?php echo $paginationCtrls;?></span>
<span class="paginationMini"><?php echo $paginationCtrlsMob;?></span>

CSS

.paginationFull{display:none}

Essentially, I am looking to show full pagination controls if in desktop and mini pagination controls if 320px - 420px. I thought that CSS display:none would be a nice easy way to do this. Does anyone, know how to accomplish this? Thanks for any help. Andy ;-)

7
  • 2
    Those are span tags and not div tags, but php is parsed before html / css so your css should be applied to the content of the echo's regardless if it comes from php or not. - Do you have other classes applied that might interfere? Commented Aug 22, 2016 at 9:30
  • Maybe you have error on .css file, or maybe you didn't include .css file to page header Commented Aug 22, 2016 at 9:32
  • 1
    Inspect your HTML source code, in the browser, does it look like you expect? Commented Aug 22, 2016 at 9:32
  • 1
    Or maybe there's bad HTML in $pageinationCtrls. Open your browser's developer console to examine the DOM and CSS. Commented Aug 22, 2016 at 9:32
  • I really can't tell what you logic is but see this <span class="paginationMini" <?php if(---){echo 'style="display:none"'; }else { ... }?>><?php echo $paginationCtrlsMob;?></span>. This lets you hide the span if a criteria is met. Or better still, try js Commented Aug 22, 2016 at 9:33

2 Answers 2

1

It shouldn't make a difference what is inside the span tag except you have some sort of HTML within span that "destroys" the DOM, so the HTML isn't valid anymore.

Besides that, you should make use of CSS media queries:

https://wiki.selfhtml.org/wiki/CSS/Media_Queries#device-width

Sign up to request clarification or add additional context in comments.

Comments

0

There are some good php libraries that can detect whether the user is on their phone or on a desktop. You can then use this to control which nav is used.

Example using http://mobiledetect.net/

include 'Mobile_Detect.php';
$md = new Mobile_Detect();

if($md->isMobile()){
    echo '<span class="paginationMini">' . $paginationCtrlsMob . '</span>';
}else{
    echo '<span class="paginationFull">' . $paginationCtrls . '</span>';
}

display:none should work regardless of whether you have an echo statement inside the <span> tag. The only explanation as to why its not working in your case is if the php variables contain tags that aren't properly closed.

1 Comment

Cool, thanks for the example, that is what I am looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.