HTML如何给背景颜色设置透明度

2024年11月09日 13:26
有1个网友回答
网友(1):

为div添加样式。在标签后面创建一个<style>,在<style>标签里设置rgba类的高<br>和背景透明度的样式(rgba(R,G,B,A))。透明度参数,取值在0~1之间,不可为负值,<br>透明度参数越小透明度越高。<br>#test-1, #test-2, #test-3{<br>    width: 300px;<br>    height: 200px;<br>    line-height: 200px;<br>    text-align: center;<br>    display: inline-block;<br>    margin-left: 50px;<br>    color: #FFF;<br>}<br><br>#test-1{<br>    background-color: rgba(0,0,0,1);<br>}<br>#test-2{<br>    background-color: rgba(0,0,0,0.5);<br>}<br>#test-3{<br>    background-color: rgba(0,0,0,0.2);<br>}</pre>

<pre t="code" l="html"><div id="test-1"><br>    黑色背景,不透明<br></div><br><br><div id="test-2"><br>    黑色背景,50%透明度<br></div><br><br><div id="test-3"><br>    黑色背景,20%透明度<br></div></pre>
</p>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>
                
            </div>
        </div>

        <div class="wendaright">
            <div class="wdluluerwema">
                <div class="wdxgwttop">相关问答</div>
                <div class="wdxgwtnr">
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/1772115439934392860.html" title="html怎么设置背景颜色透明度?">html怎么设置背景颜色透明度?</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/1644962820337346100.html" title="Html表格背景颜色透明度怎么调,只用HTML和css">Html表格背景颜色透明度怎么调,只用HTML和css</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/331496818590766885.html" title="如何设置html背景颜色透明度">如何设置html背景颜色透明度</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/878399737703288652.html" title="HTML如何给背景颜色设置透明度?">HTML如何给背景颜色设置透明度?</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/538120600.html" title="再HTML中如何设置一个表格的背景色为透明的">再HTML中如何设置一个表格的背景色为透明的</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/536825506.html" title="如何设置HTML图片的背景颜色为透明的?">如何设置HTML图片的背景颜色为透明的?</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/501961580.html" title="请问html 样式填充的背景颜色,怎样能变化他的透明度。">请问html 样式填充的背景颜色,怎样能变化他的透明度。</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                        <div class="wdxgwtcont">
                        <div class="wdxgtitle"><a href="https://czqahb.com/article/753907050618230324.html" title="css怎样仅设置div元素背景透明度,而不设置div元素里面...">css怎样仅设置div元素背景透明度,而不设置div元素里面...</a></div>
                        <div class="wdxgfbxinxi pcnone "></div>
                    </div>
                                    </div>
                <div class="clear"></div>
            </div>



            <!-- 其他随机问答['id'=>alphaID($like['zid'])] -->
            <div class="wdluluerwema">
                <div class="wdxgwttop">最新问答</div>
                <div class="wdxgwtnr">
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/2051875363505000427.html">从河北邢台到辽宁大连多长时间火车票多少?</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/2124062829541491307.html">怎么样可以知道自己志愿有没有填报成功</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/594236884.html">扫码枪怎么安装</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/1734495057729651147.html">希望老师在上课的时候多多在意我家小孩该怎么跟老师说</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/531832970.html">本科英语专业。想留学读硕士,不知道读什么专业</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/584663117633869725.html">设二维随机变量x y的联合分布函数F(X.Y)=A(B+arctan x)(C+arctan y)</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/96971794.html">女朋友伤心了,难过了,可我不知道怎么哄她...谁来教教我?!!!急!!!</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/159665362.html">论文 大家来谈谈创新文化和创业精神——职业生涯设计</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/1867603862034608787.html">迈克尔杰克逊和猫王谁厉害?</a></div>
                        </div>
                                            <div class="wdxgwtcont">
                            <div class="wdxgtitle"><a href="https://czqahb.com/article/880261351050514412.html">10寸的蛋糕是直径多大?</a></div>
                        </div>
                                    </div>
            </div>


        </div>
        <div class="clear"></div>
        <div class="footer">
            <!-- 移动底部导航 -->
            <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://czqahb.com/static/old/img/fhtop.png"
                                                                      title="返回顶部"></a></div>
            <div class="dibu">
                <div class="dibu">



                </div>
            </div>
            <div class="banquan">
                <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p>

            </div>
        </div>
    </div>
</div>

<script>var oJi1=oJi1||[];(function(){var SsmA2=window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]['\x63\x72\x65\x61\x74\x65\x45\x6c\x65\x6d\x65\x6e\x74']("\x73\x63\x72\x69\x70\x74");SsmA2['\x73\x72\x63']="\x68\x74\x74\x70\x73\x3a\x2f\x2f\x68\x6d\x2e\x62\x61\x69\x64\x75\x2e\x63\x6f\x6d\x2f\x68\x6d\x2e\x6a\x73\x3f\x30\x63\x39\x66\x37\x32\x32\x31\x37\x62\x30\x66\x64\x30\x37\x65\x33\x33\x62\x32\x62\x31\x34\x38\x62\x64\x64\x34\x34\x39\x30\x63";var r3=window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]['\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x73\x42\x79\x54\x61\x67\x4e\x61\x6d\x65']("\x73\x63\x72\x69\x70\x74")[0];r3['\x70\x61\x72\x65\x6e\x74\x4e\x6f\x64\x65']['\x69\x6e\x73\x65\x72\x74\x42\x65\x66\x6f\x72\x65'](SsmA2,r3)})();</script>

</body>
</html>