H1标签前后的CSS背景图片 [英] css background image before and after h1 tag

查看:52
本文介绍了H1标签前后的CSS背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须设置所有h1标签的样式,以便在h1文本之前和之后都具有图像.

I have to style all h1 tags to have an image before and after h1 text.

我知道以前如何添加图像,但不知道如何同时添加两者.

I know how to add image before, but do not know how to add both.

CSS(将h1样式设置为在文本之前具有图像)

CSS (styling h1 to have image before text)

h1 {
        background-image: url('images/h_ltr.png');
        background-position: left center;
        background-repeat: no-repeat;
        text-align: center;
        font-size: 22px;
        font-weight: bold;
        color: #5d5d5d;
    }

推荐答案

您可以使用:之前:after CSS选择器.

You can use the :before and :after css selectors.

h1:before {
    background-color: green;
    padding: 0 20px;
    content: " ";
}
h1:after {
    background-color: red;
    padding: 0 20px;
    content: " ";
}

<h1>Test</h1>

这篇关于H1标签前后的CSS背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆