CSS中样式 display 属性 inline,block及inline-block

div 元素默认display属性为block 为块状元素,无论div中文字字数,总以块状显示,即占满浏览器宽度。

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <div style="background-color:red;">测试测试</div>  


[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <div style="display:inline;background-color:red;">sss</div>  



而span元素默认display属性为inline,只占据span中所占字数的宽度。


[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="background-color:red;">测试测试<span>  


[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="background-color:red;display:block;">测试测试<span>  


inline-block

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <div style="display:inline-block;background-color:red;width:20px;">sfffs</div>  
  2. <p>  
  3. <span style="display:inline-block;background-color:red;width:20px;">sfffs</span>  




inline-block 与 inline 的区别

默认情况下 inline-block 与inline 效果一致

但当对div设置width或height时,由于width和height属性只对块状元素即block类型起作用,就能看出inline-block与inline 的区别了。

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <div style="display:inline-block;background-color:red;width:200px;">sfffs</div>  
  2. <p>  
  3. <span style="display:inline;background-color:red;width:200px;">sfffs</span>  


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值