如果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 */ }更多推荐
发布评论