点晴MIS问题教程区 加入收藏
问题搜索
 您的位置:点晴OA办公管理信息系统『 经验分享&问题答疑 』浏览当前教程  
  

  网站搜索
  搜索范围: 搜索方式: 关键词(可用空格分开)  

  作者及文章信息: 本文热度:32 % 
admin

积分:80658
等级:网站管理员
文数:14933
注册:2004-7-20

 信息   主页       

楼 顶 

 input输入框添加内部图标


有可能在制作网页的过程中遇到各种美化表单设计,这次我们来试着做一个demo,将input输入框添加内部图标。


话不多说,看一下最终效果:


我们的思路是,在一个div中,加入一个div和一个input标签,小div在左侧,input放右侧,用box-sizing:border-box,这句代码代表的是这个:怪异盒子模型 => 盒子定长定宽,不管有没有padding,border,margin,始终就是这么大,影响的只会是里面的元素。


左侧的div给border,也要给border-radius,右边的input只给右边的border,不给border-radius,input里面padding-left最好设置一下,更加美观。


总体思路其实是把大的div做成让人感觉像是一个input,如果能做到,那么你就成功了。


下面附代码:

<div class="student-name-box">
  <div>
    <img src="./img/学号.png" />
  </div>
  <input type="text" value="" placeholder="请输入学号" />
</div>
<div class="student-id-box">
  <div>
    <img src="./img/密码.png" />
  </div>
  <input type="password" placeholder="请输入密码" />
</div>


CSS:

.student-name-box,.student-id-box{
  box-sizing: border-box;
  width:300px;
  height:36px;
  border: 2px solid #DDD;
  border-radius: 5px;
  margin-top: 27px;
  margin-left: 50%;
  transform: translateX(-50%);
}
input{
  box-sizing: border-box;
  margin-bottom: 1px;
  outline: none;
  width:264px;
  height:32px;
  padding-left: 10px;
  border:;
}
.student-name-box div:first-child
  ,.student-id-box div:first-child{
  box-sizing: border-box;
  float: left;
  width: 32px;
  height: 32px;
  background: rgb(233,236,239);
  background-position:8px 10px;
  border-right: 2px solid #DDD;
}
.student-name-box img,.student-id-box img{
  width: 16px;
  height: 16px;
  margin:8px;
}

该文章在 2023/5/17 19:09:04 编辑过

  离 线  2023/5/17 19:07:09 
  本文章共有 0 页, 0 张回文,每页有 10 张回文 >> [ ]
页码:  
Copyright 2010-2023 ClickSun All Rights Reserved