作者归档:Rick

line-height深入理解

语法

line-height:normal | <length> | <percentage> | <number>

默认值:normal

适用于:所有元素

继承性:有

动画性:当值为 <length> | <number>

计算值:指定值

经常配合的属性有 display: inline-block vertical-align:middle

听我解释

line-height作用于所有元素,具有继承性;

一个容器的高度是有line-height决定的,不是由文字大小;

文字本身可以看成是一个内联(inline)元素;

如果,父容器设置了行高200px

  • 子元素是内联的,设置行高,子元素的行高是不会覆盖的,这设置是没有任何效果的;
  • 子元素是块内联的,设置行高,子元素的行高是覆盖的,内部有自己的行高,整体在父容器中,通过vertical-align:middle实现多行居中的效果(此时的元素可以看成是一个img标签);
  • 子元素是块结构,设置行高,子元素的行高是覆盖的,但是父容器的高度不是200px,而是块子元素的行高撑起,可以理解,父元素的行高失效无意义,除了继承line-height,不会对块元素产生位置上的影响;

测试代码片段

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>line-height</title>
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        .line {
            /*display: inline;*/
            font-size: 0;
            line-height: 200px;
            background-color: red;
            color: #fff;
            /*vertical-align: middle;*/
        }

        .line span {
            background-color: blue;
            /*line-height: 1.5;*/
            display: inline;/*当display:block的时候,不会继承line的line-height; inline会集成*/
            vertical-align: middle;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="line">
       <span>本次国考涉及苏州大市范围内的职位共需招录81人,用人司局包括长江航运公安局苏州分局、苏州市国家税务局基层分局、苏州出入境检验检疫局、国家统计局江苏调查总队、苏州银监分局等。从招录人数来看,共有五个岗位招录人数最多,皆为4人。</span>

    </div>
</body>
</html>

代码片段 => 实现单行,多行文字垂直居中

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>nav</title>
    <style>
      .bar-container {
          line-height: 70px;
          font-size: 0;

          /*调试属性*/
          background-color: red;
          color: #fff;
        }

        .bar-container > * {
          display: inline-block;
          line-height: 30px;
          vertical-align: middle;
          font-size: 14px;
          /*调试属性*/
          background-color: blue;
        }


        ul,li {
          padding: 0;
          margin: 0;
        }
        li {
          float: left;
          /*display: inline;*/
          /*line-height: 1;*/
          /*vertical-align: middle;*/

          margin-right: 10px;
          list-style: none;
        }

    </style>
</head>
<body>
  <div class="bar-container">
      <span>
         11111
      </span>
        <ul>
          <li>111111111111</li>
          <li>222222222222</li>
          <li>333333333333</li>
        </ul>
        <span>33333</span>
        <div>
          <div class="tel">18878767761</div>
          <div class="email">188787@qq.com</div>
      </div>
  </div>
  xxxxx

</body>
</html>

效果图

http://xhope.top/wp-content/uploads/2017/11/s1.png

http://xhope.top/wp-content/uploads/2017/11/s2.png

  • 参考链接

https://www.cnblogs.com/fanyoufu/p/6425149.html

http://www.zhangxinxu.com/wordpress/2009/11/css%E8%A1%8C%E9%AB%98line-height%E7%9A%84%E4%B8%80%E4%BA%9B%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E5%8F%8A%E5%BA%94%E7%94%A8/

做出高大上的网站所需要的前端插件

框架部分

设计框架

关于两者的区别可以参见:http://www.dengzhr.com/frontend/css/337

  • 阿里图标库
    阿里妈妈MUX倾力打造的矢量图标管理、交流平台。
    设计师将图标上传到Iconfont平台,用户可以自定义下载多种格式的icon,平台也可将图标转换为字体,便于前端工程师自由调整与调用。

  • jquery
    jQuery是一个快速、简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架)。jQuery设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。是很多插件的依赖

  • bootstrap
    Bootstrap 是最受欢迎的 HTML、CSS 和 JS 框架,用于开发响应式布局、移动设备优先的 WEB 项目。

  • animate.css
    animate.css 是一个来自国外的 CSS3 动画库,它预设了抖动(shake)、闪烁(flash)、弹跳(bounce)、翻转(flip)、旋转(rotateIn/rotateOut)、淡入淡出(fadeIn/fadeOut)等多达 60 多种动画效果,几乎包含了所有常见的动画效果。

  • WOW
    WOW.js 是一款帮助你实现滚动页面时触发CSS 动画效果的插件,依赖样式库animate.css

  • drawer
    非常好用的菜单插件,依赖jquery iScroll

  • lazyload
    jQuery图片延迟加载插件jQuery.lazyload,使用延迟加载在可提高网页下载速度。在某些情况下,它也能帮助减轻服务器负载,插件基于jQueryZepto

  • Swiper
    Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。
    Swiper能实现触屏焦点图、触屏Tab切换、触屏多图切换等常用效果。
    Swiper开源、免费、稳定、使用简单、功能强大,是架构移动终端网站的重要选择!

功能性框架

工具部分

  • holder
    html图片占位符插件holder.js可以为图片生成一个占位符图片也可以为某个区域生成一个占位符图片,准确的说应该是为某个区域生成一个占位符图片,因为img也可以看做是一个区域。

  • sass

  • compass
  • gulp
    …..

更多参考网站

https://github.com/iamjoel/front-end-plugins
https://www.zhihu.com/question/60517583

$.ajax提交数组到SpringMVC

前台数据提交

$.ajax({
                'type': 'POST',
                'url':"${pageContext.request.contextPath}/web/${webId}/menu/saveList",
                'contentType': 'application/json',
                'data': JSON.stringify(menu.menuList),
                'dataType': 'json',
                success: function(data) {

                }
            });

后台数据接收

    @PostMapping("/saveList")
    @ResponseBody
    public ResponseDTO saveList(@RequestBody List<MenuDto> menuDtoList) {
        menuService.saveList(menuDtoList);
        return response(menuDtoList.size());
    }

@RequestBody会通过jackson将json字符串转化成java对象

数据提交

http://xhope.top/wp-content/uploads/2017/08/1.png

参考链接
https://stackoverflow.com/questions/14459171/spring-mvc-and-jquery-post-request-with-array-of-pojo

MySQL的root密码找回

1 . 查找my.conf位置

[root@iZ28t57xzbcZ ~]# whereis my.cnf
my: /etc/my.cnf

2 . 修改my.conf文件,新增skip-grant-tables

[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-grant-tables

3 . 重启mysql

systemctl restart mariadb

4 . 登陆修改root密码

[root@localhost log]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.23-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Database changed
mysql> update user set password = password('root') where user = 'root';
Query OK, 4 rows affected (0.91 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)

mysql> quit
Bye

5 . 删除之前my.conf文件中新增的skip-grant-tables

6 . 重启DB,登陆正常

7 . 参数skip-grant-tables说明
这个参数看名字就是skip权限用的,通常用来找回root密码用,相对危险,慎用,特别是在生产上

参考:
https://my.oschina.net/Kenyon/blog/87632

Nodejs + Express + EJS搭建带有母版的网站

通过nodejs express ejs ejs-mate 搭建具有母版页面的网站页面,省略nodejs的安装过程。

Express

  • 安装Express
$ npm install express --save
  • Express 应用生成器搭建网站
$ npm install express-generator -g
$ express myapp
$ cd myapp 
$ npm install
$ DEBUG=myapp npm start

后在浏览器中打开 http://localhost:3000/ 网址就可以看到这个应用了。注意这时默认的模版引擎是jade。需要做相应的修改才能支持ejs
通过 Express 应用生成器创建的应用一般都有如下目录结构:

.
├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│   └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
├── error.jade
├── index.jade
└── layout.jade

7 directories, 9 files

EJS & ejs-mate

  • 安装
$ npm install ejs
$ npm install ejs-mate --save
  • 修改文件app.js,使用母版引擎ejs
var engine = require('ejs-mate');
app.engine('ejs', engine);
app.set('view engine', 'ejs');
  • 添加模版文件layout.ejs
<!DOCTYPE html>
<html>
  <head>
    <title>It's <%= who %></title>
  </head>
  <body>
    <section>
      <%- body -%>
    </section>
  </body>
</html>
  • index.ejs使用母版文件
<% layout('layout') -%>
<h1>I am the <%= what %> template</h1>
  • Express4.0 渲染
var express = require('express'),
  engine = require('ejs-mate'),
  app = express();

// use ejs-locals for all ejs templates:
app.engine('ejs', engine);

app.set('views',__dirname + '/views');
app.set('view engine', 'ejs'); // so you can render('index')

// render 'index' into 'boilerplate':
app.get('/',function(req,res,next){
  res.render('index', { what: 'best', who: 'me' });
});

app.listen(3000);

渲染后将会得到代码

<!DOCTYPE html>
<html>
  <head>
    <title>It's me</title>
  </head>
  <body>
    <section>
      <h1>I am the best template</h1>
    </section>
  </body>
</html>

参考链接
www.expressjs.com.cn/
http://www.embeddedjs.com/
https://github.com/JacksonTian/ejs-mate