作为后端开发,分享10个我常用到的前端小知识

主做后端,偶尔也要写一下前端,分享一下我常用的前端小知识。

1、内容超过指定宽度,超出部分用...表示

overflow 属性规定当内容溢出元素框时发生的事情。
overflow: hidden; // 溢出隐藏
white-space: nowrap; // 文本不进行换行
text-overflow: ellipsis; // 超出文本被修剪...

代码:

.plan_time {
    width: 60px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

 示例:

 

2、清除input输入框的历史记录

特别是用时间插件的时候,被遮住了,很烦!

<input type="text" autocomplete="off" name="name"> , 加上autocomplete="off"就可以了。

3、文本居中

水平居中:text-align: center;
水平垂直居中:
flex-direction: column; // 元素垂直排列
justify-content: center; // 水平居中对齐
align-items: center; // 垂直居中对齐

代码:

#home {
  width: 100%;
     height: 100%;
     display: flex;
     justify-content: center;
     align-items: center;
 }

示例:

4、去除滚动条

去掉水平滚动条:<body style="overflow-x: hidden">
去掉竖直滚动条:<body style="overflow-y: hidden">

隐藏横向滚动条,显示纵向滚动条:<body style="overflow-x:hidden;overflow-y:scroll">

全部隐藏:<body style="overflow:hidden">

代码:

.aaa {
    overflow-x: hidden;
}

示例:

5、div不换行

 

 代码:

div{ display:inline} 

示例: 

6、鼠标放上去显示

 代码:

#dropdown_div:hover ul{display:block}

 示例:

7、鼠标点击触发(获得焦点)

代码:

input:focus{
	background-color:yellow;
}

示例:

8、字体

font-family: sans-serif; // 字体设置
Serif 字体
Sans-serif 字体
Monospace 字体
Cursive 字体
Fantasy 字体

字体风格:

font-style:normal;
normal - 文本正常显示
italic - 文本斜体显示
oblique - 文本倾斜显示

字体大小,粗细:

.aa{
    font-size: 28px;
    font-weight: 1000;
}

示例:

 9、边距、边框

代码: 

.aaa{
    margin: 23px;
    border: 2px solid #999;
    padding: 10px;
}

示例:

10、对齐

水平对齐:

.aaa{
margin:auto;
width:90%;
background-color:red;
}

提示:如果宽度是 100%,对齐无效。

左右对齐:

.aaa{
    float:right;
    width:300px;
    background-color:red;
}

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值