Is there a way to use use text as the background with CSS?

前端 未结 8 695
暖寄归人
暖寄归人 2020-11-28 03:48

I would like to use dynamic text as background of certain elements in my tag. Because of this, I can use images (dynamic text). How do I do it with just CSS or JavaScript?

8条回答
  •  离开以前
    2020-11-28 04:07

    Using pure CSS:

    (But use this in rare occasions, because HTML method is PREFERRED WAY).

    .container{
    	position:relative;
    }
    .container::before{ 
    	content:"";
    	width: 100%; height: 100%; position: absolute; background: black; opacity: 0.3; z-index: 1;  top: 0;   left: 0;
    	background: black;
    }
    .container::after{ 
    	content: "Your Text"; position: absolute; top: 0; left: 0; bottom: 0; right: 0; z-index: 3; overflow: hidden; font-size: 2em; color: red;    text-align: center; text-shadow: 0px 0px 5px black; background: #0a0a0a8c; padding: 5px;
    	animation-name: blinking;
    	animation-duration: 1s;
    	animation-iteration-count: infinite;
    	animation-direction: alternate;
    }
    @keyframes blinking {
    	0% {opacity: 0;}
    	100% {opacity: 1;}
    }
    here is main content, text ,
    images and other page details

提交回复
热议问题