《CSS世界》读书笔记

CSS三无准则: 无宽度(充分利用流特性)、无浮动、无图片

无宽度与宽度分离分离准则相通

浏览器兼容(区别):

IE8仅支持单冒号的伪元素 如:
.element:before{}

 

 

 

常用清楚浮动方式

/* 清楚浮动 */
.clearfix{
    *zoom : 1; /*For IE 6/7*/
}
.clearfix:after {
    content: '';
    display: table;/*block也行*/
    clear: both
}

需求: 页面某模块的文字内容是动态的,希望文字少的时候居中显示,超过一行居左显示

        <div class="container">
          <div class="box">
              <p id="conMore" class="content">文字内容-新增文字-新增文字-新增文字</p>
          </div>
        </div>
        <div style="height: 10px;"></div>
        <div class="container">
          <div class="box">
              <p id="conMore" class="content">文字内容</p>
          </div>
        </div>
        <style>
            .container{
                background-color: #f00;
                color: #fff;
                width: 240px
            }
            .box {
                text-align: center;
            }
            .content {
                display: inline-block;
                text-align: left;
            }
        </style>    

 由于img标签在Firefox浏览器中的产生的差异,可以在reset.css中设置予以兼容:

img{display: inline-block}

 

利用 padding 实现高度可控的分割线(登录 | 注册)

<a href="">登录</a><a href="">注册</a>
<style>
    a+ a:before{
        content: "";
        font-size:0;
        padding: 10px 3px 1px;
        margin-left: 6px
        border-left: 1px solid gray    
    }
</style>

 

margin 实现等高布局(两兰、三栏等) PS: margin 的百分比无论水平还是垂直都是相对于宽度计算的

<div class="container">
    <div id="colLeft" class="column-left">
        <h4>正方观点</h4>
        <p>观点1</p>
        <p>观点1</p>
        <p>观点1</p>
        <p>观点1</p>
    </div>
    <div id="colRight" class="column-right">
        <h4>反方观点</h4>
        <p>观点1</p>
    </div>
</div>
<style>
    .container{
        width: 100px;
        overflow: hidden;
    }
    /* 核心代码 */
    .column-left,
    .column-right {
        margin-bottom: -9999px;
        padding-bottom: 9999px;
    }
    .column-left {
        background-color: #34538b;
    }
    .column-right {
        background-color: #cd0000;
    }
</style>

持续更新中。。。

转载于:https://www.cnblogs.com/gongxiansheng/p/10398700.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值