On a div I have css set:

在div中,我设置了css:

div.class {border: 1px solid red;}

The div is positioned absolutely in the center of the page. The problem is that the border appears even if there is no content.

div定位在页面的中心位置。问题是,即使没有内容,边界也会出现。

Any css methods to get the border to not appear if there is no content?

如果没有内容,有没有css方法可以让边框不出现?

2 个解决方案

#1


38

CSS3 has a selector defined for this case. It does not work in IE8 and lower though.

CSS3为这种情况定义了一个选择器。它在IE8和更低的版本中不起作用。

div.class:empty { 
    border: none;
}

Your best option would be to tweak this on the server side, and simply don't display that div if it would be empty.

最好的选择是在服务器端进行调整,如果div是空的,就不要显示它。

更多相关文章

  1. DiggBar如何基于不在其域上的内容动态调整其iframe的高度?
  2. IE-7 z-index问题-下拉区域在横幅下,它的内容没有显示在IE-7中。
  3. 提交一个表单(后台生成id),点击保存并一步后切换到下一个tab中,此t
  4. 在Paragraphs中显示mysql内容时出现问题
  5. thinkphp5使用workerman定时器定时爬取某站点新闻资讯等内容
  6. PHP调用内容DES加密的SOAP接口
  7. PHP限制HTML内容中图片必须是本站的方法
  8. 将Ajax div内容存储在PHP变量中
  9. 为什么我对JSON对象的AJAX调用会返回其特定内容的未定义?

随机推荐

  1. 用WordPress决定jQuery的版本?
  2. jQuery无法从localhost检索数据
  3. 如何使用jquery ajax获取api数据?
  4. 用jquery 绑定一个按钮click事件后,第一次
  5. Jquery中的队列函数quene()、dequene()、
  6. JQUERY中做表单验证,谁有带时间的日期选择
  7. 请问jquery如何选择tr下的n个tr?
  8. 如何检测jQuery中的水平滚动?
  9. jquery自定义事件
  10. Symfony 2在用户站点上动态添加字段以形