CSS Create a transparent div

Is there a way to make a div element translucent?

+5
source share
4 answers

Using a background PNG file that is half transparent and hopes you don't need to support IE6?

+4
source

With CSS, this is a cross-browser solution.

div {
    opacity: 0.5;
    filter: alpha(opacity = 0.5);
    filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
}
+10
source

div {
 -khtml-opacity:.50; 
 -moz-opacity:.50; 
 -ms-filter:"alpha(opacity=50)";
  filter:alpha(opacity=50);
  filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
  opacity:.50; 
}

, , http://www.impressivewebs.com/css-opacity-that-doesnt-affect-child-elements/

+8

If you need only the background of your translucent div, and not some text and elements inside it, you can simply set the background color to transparent (for example, with alpha-1).

For example, our site , the example below:

<html>
<head>
  <title>Transparency test</title>
  <style type="text/css">
    body {
      background-image: url(http://www.fencing-game.de/style/background6.png);
    }
    #trans {
      background-color: rgba(255,0,0,0.5);
      max-width: 80ex;
    }
    p {
    max-width: 70ex;
    margin: auto;
    }
    #nontrans {
      background-color: rgb(255,255, 0);
    }
  </style>
</head>
<body>
  <div id="trans">
    <p>normal text</p>
    <p id="nontrans">nontransparent</p>
    <p>normal text</p>
  </div>
</body>
0
source

All Articles