padding-left与text-align: center在有定位的组件中如何区分应用

我们写一个带箭头的header和一个左边带图标的input来做比较(注:矢量图标链接需引入)
1、首先我们写一个带箭头的header

 <div class="header">
        <div class="header-left font">&#xe650;</div>
        首页
    </div>

样式如下:

.header {
  color: #ffffff;
  font-size: 26px;
  font-weight: bold;
  position: relative;
  height: 45px;
  line-height: 45px;
  background-color: #ef6d6d;
  margin-top: 10px;
  text-align: center;
}
.header .header-left {
  position: absolute;
  left: 10px;
  top: 0;
  font-size: 16px;
}

2、接下来写带图标的input

 <div class="input-group">
     <div class="input-group-adds font">&#xe652;</div>
      <input type="text" class="form-control" placeholder="请输入用户名">
 </div>

样式如下:

.input-group {
  width: 100%;
  color: #ffffff;
  border: 1px solid transparent;
  border-radius: 4px ;
  margin-top: 10px;
  padding-left: 60px;
  position: relative;
}
.input-group .input-group-adds {
  width: 60px;
  position: absolute;
  left: 0;
  top: 0;
  font-size: 23px;
  text-align: center;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
  background-color: rgba(255, 255, 255, 0.3);
  margin-right: 1px;
  padding: 5px;
  border: 1px solid rgba(0, 0, 0, 0.16);
}
.input-group .form-control {
  width: 100%;
  padding: 10px 12px;
  border-bottom-right-radius: 4px;
  border-top-right-radius: 4px ;
  background-color: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(0, 0, 0, 0.16);
}

二者中我们都使用了定位,唯一的区别是header中没有使用padding-left给左边的箭头预留位置,而input中我们需要使用padding-left给左边的图标预留位置,这样写的原因是:header中的首页是居中的不会遮挡我们定位到左边的箭头,input中输入框的文字自身是居左的为了避免与左边的图标重叠所以我们需要用到padding-left预留出左边的位置。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值