如果Div为空,则隐藏它并更改另一个div的宽度(If Div is empty, hide it and change width of another div)

编程入门 行业动态 更新时间:2024-10-28 07:18:57
如果Div为空,则隐藏它并更改另一个div的宽度(If Div is empty, hide it and change width of another div)

我是css和php的新手,我试图找到一种方法来隐藏我的.item页面,如果Div是空的。 然后将item-page的宽度更改为100%。 现在,旁边需要85px空或不。 怎么能在我的PHP文件中这样做?

这是我的CSS:

item-page { position:relative; width: 100%; } .item-page aside { float:left; position:absolute; width:85px; } gk-article { font-size:14px; line-height:26px !important; margin:0 0 80px 110px; }

这是我的php文件:

<div id="main"> <jdoc:include type="component" /> </div>

I am new to css and php and am trying to find a way to hide my .item-page aside if the Div is empty. And then change the width of item-page to 100%. Right now the aside takes up 85px empty or not. How can do this in my php file?

Here is my CSS:

item-page { position:relative; width: 100%; } .item-page aside { float:left; position:absolute; width:85px; } gk-article { font-size:14px; line-height:26px !important; margin:0 0 80px 110px; }

Here is my php file:

<div id="main"> <jdoc:include type="component" /> </div>

最满意答案

你在这里标记了javascript / jquery,这可能是你应该使用的(不是PHP)。

(在jQuery中)你可以做这样的事情 - 使用类作为charlietfl建议:

if( $('.item-page aside').html() == '') ) { $('.item-page aside').hide(); $('.item-page').removeClass('isntempty').addClass('isempty'); } else { $('.item-page aside').show(); $('.item-page').removeClass('isempty').addClass('isntempty'); }

CSS:

.isntempty { width: 100%; } .isempty { width: 50%; /* whatever your default width is */ }

You've tagged javascript/jquery here, and that's probably what you should use (not PHP).

(in jQuery) you can do something like this - use classes as charlietfl suggested:

if( $('.item-page aside').html() == '') ) { $('.item-page aside').hide(); $('.item-page').removeClass('isntempty').addClass('isempty'); } else { $('.item-page aside').show(); $('.item-page').removeClass('isempty').addClass('isntempty'); }

CSS:

.isntempty { width: 100%; } .isempty { width: 50%; /* whatever your default width is */ }

更多推荐

本文发布于:2023-08-03 05:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1384093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宽度   为空   div   Div   width

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!