How can I make my website's background transparent without making the content (images & text) transparent too?

前端 未结 8 1369
小鲜肉
小鲜肉 2020-12-15 04:25

I\'m doing a website for a school project, and I\'m currently having a small problem... I can\'t make the body\'s background transparent without it also affecting the conten

8条回答
  •  既然无缘
    2020-12-15 05:17

    There is a css3 solution here if that is acceptable. It supports the graceful degradation approach where css3 isn't supported. you just won't have any transparency.

    body {
        font-family: tahoma, helvetica, arial, sans-serif;
        font-size: 12px;
        text-align: center;
        background: #000;
        color: #ffffd4d4;
        padding-top: 12px;
        line-height: 2;
        background-image: url('images/background.jpg');
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-size: 100%;
        background: rgb(0, 0, 0); /* for older browsers */
        background: rgba(0, 0, 0, 0.8); /* R, G, B, A */
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#CC000000, endColorstr=#CC0000); /* AA, RR, GG, BB */
    
    }
    

    to get the hex equivalent of 80% (CC) take (pct / 100) * 255 and convert to hex.

提交回复
热议问题