采用rem高仿网易新闻h5版新闻列表页

一、页面框架搭建(构建,scss)
终端输入

webpack --watch

可以执行webpack文件侦听并打包


二、页面样式编写


三、rem计算代码编写


四、适配多种机型大小,resize完善

代码如下:
文件目录
这里写图片描述

app.js

require('./index.scss');        // 引入scss文件

// 获取屏幕宽度(viewport宽度)
let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;

// 获取html的DOM
let htmlDom = document.getElementsByTagName('html')[0];

// 设置html的fontsize
htmlDom.style.fontSize = htmlWidth / 10 + 'px';

window.addEventListener('resize',(e)=>{
    let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
    htmlDom.style.fontSize = htmlWidth / 10 + 'px';
});

index.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<title>新闻列表</title>
<link rel="stylesheet" type="text/css" href="./reset.css" />
</head>

<body>
    <div class="header">
        <ul class="header-content">
            <li class="header-item">推荐</li>
            <li class="header-item">新闻</li>
            <li class="header-item">娱乐</li>
            <li class="header-item">体育</li>
            <li class="header-item">图片</li>
            <li class="header-item">财经</li>
        </ul>
    </div>
    <div class="banner-content">
        <img class="banner" src="./images/top.jpg" />
        <p class="banner-title">2018狗年时尚跨界盛典</p>
    </div>
    <div class="news-content">
        <ul>
            <li class="news-item">
                <div class="item-inner">
                    <img class="news-img" src="./images/1.jpg" />
                    <p class="news-title">美女头像美女头像美女头像美女头像</p>
                    <span class="time">
                        1小时前
                    </span>
                    <span class="num">
                        99999
                    </span>
                </div>
            </li>
            <li class="news-item">
                <div class="item-inner">
                    <img class="news-img" src="./images/1.jpg" />
                    <p class="news-title">美女头像美女头像美女头像美女头像</p>
                    <span class="time">
                        1小时前
                    </span>
                    <span class="num">
                        99999
                    </span>
                </div>
            </li>
            <li class="news-item">
                <div class="item-inner">
                    <img class="news-img" src="./images/1.jpg" />
                    <p class="news-title">美女头像美女头像美女头像美女头像</p>
                    <span class="time">
                        1小时前
                    </span>
                    <span class="num">
                        99999
                    </span>
                </div>
            </li>
            <li class="news-item">
                <div class="item-inner">
                    <img class="news-img" src="./images/1.jpg" />
                    <p class="news-title">美女头像美女头像美女头像美女头像</p>
                    <span class="time">
                        1小时前
                    </span>
                    <span class="num">
                        99999
                    </span>
                </div>
            </li>
        </ul>
    </div>
    <script src="./build/bundle.js"></script>
</body>
</html>

index.scss

// 定义方法,把px转换成rem
@function px2rem($px){
    $rem:37.5px;            //  定义rem基准值,这里用的是iphone 6的视觉稿
    @return ($px / $rem) + rem;
}

html{
    background-color: #f8f8f8;
}

.header{
    height: px2rem(40px);    // 注意设计稿上是80px,需要除以2
    width: 100%;
    background-color: red;
    padding-left: px2rem(23px);
    .header-item{
        float: left;
        color: #ffcdce;
        font-size: px2rem(16px);
        margin-right: px2rem(20px);
        line-height: px2rem(40px);

        &:nth-child(2){
            color: #fff;
            font-size: px2rem(17px);
        }
    }
}

.banner-content{
    position: relative;
    .banner{
        display: block;
        width: 100%;
        height: px2rem(190px);
    }
    .banner-title{
        position: absolute;
        left: px2rem(15px);
        bottom: px2rem(15px);
        font-size: px2rem(16px);
        color: #fff;
    }
}

.news-content{
    .news-item{
        width: 100%;
        height: px2rem(90px);
        padding-left:px2rem(15px);
        padding-right:px2rem(15px);
        box-sizing: border-box;
    }
    .item-inner{
        position: relative;
        overflow: hidden;
        height: 100%;
        border-bottom: px2rem(1px) solid #e5e5e5;
    }
    .news-img{
        float: left;
        display: block;
        margin-top: px2rem(10px);
        width: px2rem(95px);
        height: px2rem(70px);
        margin-right: px2rem(15px);
    }
    .news-title{
        color: #404040;
        font-size: 17px;
        margin-top: px2rem(16px);
        line-height: px2rem(20px);
    }
    .time{
        position:absolute;
        left: px2rem(110px);
        bottom: px2rem(17px);
        color: #888;
        font-size: px2rem(12px);
    }
    .num{
        position:absolute;
        color:#888;
        font-size: px2rem(12px);
        right: px2rem(4px);
        bottom: px2rem(17px);
        &::before{
            content: ' ';
            display: block;
            position: absolute;
            width: px2rem(21px);
            height:px2rem(20px);
            background-size: contain;
            top: px2rem(-4px);
            left: px2rem(-23px);
            background-image:url('./images/read-icon.png');
        }
    }
}

package.json

{
  "name": "rem",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "css-loader": "^0.28.9",
    "node-sass": "^4.7.2",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.20.2",
    "url-loader": "^0.6.2",
    "webpack": "^3.11.0"
  }
}

webpack.config.js

var webpack = require('webpack');
var path = require('path');
module.exports = {
    // 页面入口文件配置
    entry:[
        './app.js'
    ],
    // 入口文件输出配置
    output:{
        path:path.resolve(__dirname,'./build'),
        filename:'bundle.js'
    },
    module:{
        // 加载器配置
        loaders:[
            {
                test:/\.css$/,
                loader:'style-loader!css-loader'
            },{
                test:/\.scss$/,
                loader:'style-loader!css-loader!sass-loader'
            },{
                test:/\.(png|jpg)$/,
                loader:'url-loader?limit=8192'
            }
        ]
    }
};

这里写图片描述

最近几年随着百度、搜狗等搜索引擎对高质量新闻门户的鼓励和重视,新闻门户网站依然是最容易获取大流量的平台之一,而且中国网民的碎片化时间越来越多,时事热点新闻门户的受众群体也越来越多,之前很多人看新闻联播,但是现在不一样了,很多人都是工作之余上网浏览一下今天的最新实时动态。所以对于运营新闻门户网站的站长朋友来说,移动显得异常重要,能够让更多的“低头族”爱上你的新闻门户。 今天分享的这套新闻门户网站就是一套非常不错的H5自适应门户网站,能够完美兼容电脑、平板和手机,让你的新闻门户受众群体尽可能的覆盖所有网络中断,当然,有了移动,我们就很容易通过一些网站转APP的工具来给自己的网站生成一个APP客户端。这套源码整体是红色风格,界面按照科技类自媒体网站的排方式布局,干净清爽,非常适合国人浏览新闻的习惯,只要你的网站能够按时按量的更新大量的新闻热点,相信很容易就能拥有大流量。 这套源码是使用织梦开源程序二次开发的,详细的安装说明可以下载源码以后,参考源码压缩包内的“源码使用说明.txt”来完成源码的安装和搭建,当然,如果你自己不会安装源码也可以联系友软科技的在线客服,付费帮你安装。源码安装过程中会提示你创建网站的管理员账号密码,自己牢记,安装完成后默认的管理地址是:http://你的网站/dede/ 默认的管理员账号密码就是你安装过程中自己创建的账号密码。安装完成以后的数据库是空的,你可以通过管理后台的【系统->数据备份/还原->数据还原】操作来恢复源码自带的栏目结构及新闻数据内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值