常用html设置:

  • 省略
  • 居中

1. 省略 ellipsis:  

  text-overflow:ellipsis;

       要求容器必须是固定的,要不然无法做省略。

       table的省略

table{
 table_layout:fixed;  //默认是auto即根据内容大小自动扩充
}
table tr td,table tr th{
      white-space:nowrap;  // 不允许折行
      overflow:hidden;
      text-overflow:ellipsis;  
}

       div的省略

div{
   width:50px;
   text-overflow:ellipsis;
   overflow:hidden;
}

2.居中:

.div{
  display:flex;
  align-items:center;
}

   flex为html5内容,低版本ie不支持。

可使用下面table属性代替居中:

.cell{
    display: table-cell;
    vertical-align:middle;
    text-align:center;
}

 .table{
    display: table;
    width:100%;
    height:80px;
 }
<div class="table">
    <div class="cell">1</div>
</div>

 

 还可用line-height:

.cell{
    display: table-cell;
    vertical-align:middle;
    text-align:center;
}

 .table{
    display: inline-table;
    width:60%;
    height:80px;
    line-height:80px;
 }

</style>
<div class="table">
    <div class="cell">1</div>
</div>

 

 还可用margin-top:

这种需要知道父元素的高度和子元素的高度。margin-top = 父元素高度/2 - 子元素高度/2

.cell{
    width:30px;
    height:20px;
    background-color: #33f65c;
    margin: auto;
    margin-top:30px;
}

 .table{
    display: block;
    width:60%;
    height:80px;
    text-align:center;
    background-color: #d3f3ac;
    overflow:hidden;
 }

<div class="table">
    <div class="cell">1</div>
</div>

 

转载于:https://www.cnblogs.com/DennyZhao/p/8418915.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值