繁体   English   中英

如何结合JavaScript和PHP和CSS的条件

[英]How to Combine the Condition of PHP and CSS with JavaScript

我为移动版本制作了一个页面。 我根据标题和屏幕尺寸确定了条件。 这是条件:

If the Title > 17 characters and screen size < 392px
then do:
.postContent img {
  bottom: 65px;
}

else and screen size > 391px
.postContent img {
  bottom: 50px;
}

这是图片预览: http : //i.imgur.com/59IG7UG.png (对不起,我至少需要10个信誉才能发布图片)

第一篇文章应将图片定位为第二篇文章的图像。

如何结合使用PHP和JavaScript来更改CSS:

<?php if (strlen(trim($post->getTitle())) > 17): ?>
<script type="text/javascript">
    //do something
</script>
<?php else: ?>
<script type="text/javascript">
    //do something
</script>   
<?php endif; ?>

我读过这篇文章: PHP条件取决于窗口宽度(媒体查询?),但不知道如何实现。

也许尝试将类添加到您的.postContent? 通过使用PHP将其打印到div中。

<div class="postContent <?php  
     if (strlen(trim($post->getTitle())) > 17) print 'bot65';
     else print 'bot50'; ?>
"> 
    // content
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM