Html+Css小tips:网易新闻右侧窗口

20210817:新闻列表和默认样式去除

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/reset.css">
    <style>
        body {
            font-family: "Microsoft YaHei", 微软雅黑, sans-serif;
        }

        a {
            text-decoration: none;
        }
        
        .news-wrapper {
            width: 300px;
            margin: 50px auto;
            background-color: #ffffff;

        }

        .box-title {
            height: 42px;
            border-top: 1px #dddddd solid;
            line-height: 40px;
        }
        /* 通过该样式使h2上移,盖住上边款 */
        .news-title {           
            display: inline;
            padding-top: 9px;
            border-top: 1px #f34540 solid;
        }

        .news-title a {
            color: #404040;
            font-weight: bold;
        }

        .news-img {
            height: 150px;
            margin-top: 4px;
        }

        .news-img .img-title {
            /* 设置图片的文字效果 */
            margin-top: -30px;
            color: #ffffff;
            font-weight: bold;
            padding-left: 30px;
        }

        .news-list {
            margin-top: 10px;
        }

        .news-list li {
            float: left;
            font-size: 14px;
            height: 30px;
            line-height: 30px;
        }
        /* 通过伪元素设置li标签前面的列表标记 */
        .news-list li::before {          
            content: '■';
            color: #dddddd;
            font-size: 1px;
            margin-right: 6px;
            display: block;
            float: left;
        }

        .news-list li a {
            font-size: 14px;
            color: #666666;

        }

        .news-list li a:hover {
            color: #c81623;
        }
    </style>
</head>

<body>
    <!-- 设置一个新闻列表的外部容器 -->
    <div class="news-wrapper">
        <!-- 标题容器 -->
        <div class="box-title">
            <h2 class="news-title">
                <a href="javascript:;">体育</a>
            </h2>
        </div>
        <div class="news-img">
            <a href="javascript:;">
                <img src="./img/2.jpg" alt="美军阿富汗现场惊现绝密飞机">
                <h3 class="img-title">美军阿富汗现场惊现绝密飞机</h3>
            </a>
        </div>
        <ul class="news-list">
            <li><a href="javascript:;">重生的“东阳魔女”</a></li>
            <li><a href="javascript:;">为了踢球拒绝哈佛的英超“学霸”</a></li>
            <li><a href="javascript:;">吴刚有多强,拿他怎么办?</a></li>
            <li><a href="javascript:;">这个综艺咖,在CBA竟能混下去?</a></li>
        </ul>
    </div>
</body>

</html>

*难点:
1、在这我们无法像往常一样通过设置margin值来使h2的上边框与div的上边框重合,所以引用了行内块元素(inline-block),使h2能通过margin上移,达到两个边框重合。
2、列表中li标签前面的标记,我们可以通过::before伪元素来代替list-style对li标签前面的标记更仔细的设置样式,再使伪元素成为块元素,接着使用float使其与li标签对齐。
3.由于代码本身保有一定的格式,所以link,引用删除原有样式,代码如下:
*

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值