opacity



значения свойства:


  • 1
  • number
  • inherit



css/style.css
  • * {
  •  margin: 0;
  •  padding: 0;
  • }
  •  
  • .main {
  •  width: 600px;
  •  height: 500px;
  •  position: absolute;
  •  left: 50%;
  •  top: 50%;
  •  margin-left: -300px;
  •  margin-top: -250px;
  • }
  •  
  • .a {
  •  width: 298px;
  •  height: 98px;
  •  font-size: 26px;
  •  background-color: #00F;
  •  border: 1px solid #808080;
  •  text-align: center;
  •  line-height: 98px;
  •  float: left;
  • }
  •  
  • .b {
  •  width: 298px;
  •  height: 98px;
  •  font-size: 26px;
  •  border: 1px solid #808080;
  •  text-align: center;
  •  line-height: 98px;
  •  float: left;
  • }
  •  
  • .c {
  •  width: 600px;
  • }
  •  
  • #div1 {
  •  opacity: 1;
  • }
  •  
  • #div4 {
  •  opacity: 0.3;
  • }
  •  
  • #div5 {
  •  opacity: 0.0;
  • }
* {
 margin: 0;
 padding: 0;
}

.main {
 width: 600px;
 height: 500px;
 position: absolute;
 left: 50%;
 top: 50%;
 margin-left: -300px;
 margin-top: -250px;
}

.a {
 width: 298px;
 height: 98px;
 font-size: 26px;
 background-color: #00F;
 border: 1px solid #808080;
 text-align: center;
 line-height: 98px;
 float: left;
}

.b {
 width: 298px;
 height: 98px;
 font-size: 26px;
 border: 1px solid #808080;
 text-align: center;
 line-height: 98px;
 float: left;
}

.c {
 width: 600px;
}

#div1 {
 opacity: 1;
}

#div4 {
 opacity: 0.3;
}

#div5 {
 opacity: 0.0;
}


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="c">
  •    <div id="div1" class="a">Hello World!</div>
  •    <div class="b">opacity = 1</div>
  •   </div>
  •   <div class="c">
  •    <div id="div2" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.7</div>
  •   </div>
  •   <div class="c">
  •    <div id="div3" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.5</div>
  •   </div>
  •   <div class="c">
  •    <div id="div4" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.3</div>
  •   </div>
  •   <div class="c">
  •    <div id="div5" class="a">Hello World!</div>
  •    <div class="b">opacity = 0</div>
  •   </div>
  •  </div>
  • <script>
  •  /*JavaScript*/
  •  document.getElementById("div2").style.opacity = "0.7";
  •  /*jQuery*/
  •  $(document).ready(function () {
  •   $("#div3").css({ "opacity": "0.5" });
  •  });
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="c">
  •    <div id="div1" class="a">Hello World!</div>
  •    <div class="b">opacity = 1</div>
  •   </div>
  •   <div class="c">
  •    <div id="div2" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.7</div>
  •   </div>
  •   <div class="c">
  •    <div id="div3" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.5</div>
  •   </div>
  •   <div class="c">
  •    <div id="div4" class="a">Hello World!</div>
  •    <div class="b">opacity = 0.3</div>
  •   </div>
  •   <div class="c">
  •    <div id="div5" class="a">Hello World!</div>
  •    <div class="b">opacity = 0</div>
  •   </div>
  •  </div>
  • <script>
  •  /*JavaScript*/
  •  document.getElementById("div2").style.opacity = "0.7";
  •  /*jQuery*/
  •  $(document).ready(function () {
  •   $("#div3").css({ "opacity": "0.5" });
  •  });
  • </script>
  • </body>
  • </html>