我是 css 和 php 的新手,我正试图找到一种方法来在 Div 为空时隐藏我的 .item-page。然后将元素页面的宽度更改为 100%。现在 aside 占用 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>
最佳答案
您在这里标记了 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 */
}
关于javascript - 如果 Div 为空,隐藏它并改变另一个 div 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19696268/