Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <!--==============レイアウトを制御する独自のCSSを読み込み===============-->
  <link href="https://assets.codepen.io/6329135/reset04.css" rel="stylesheet">
</head>

<body>

  <div class="opacityText">
    <a href="#">
      <span class="mask">
        <img src="https://assets.codepen.io/6329135/26.jpg" alt="">
        <span class="cap">画像透過+グラデーション+テキストが出現 OpacityText</span>
      </span>
    </a>
  </div>

</body>
              
            
!

CSS

              
                @charset "utf-8";

/* 画像の透過+グラデーション+テキスト出現 */

.opacityText {
  /*テキストの基点となる位置を定義*/
  position: relative;
}

.opacityText span.mask {
  position: relative; /*グラデーションの基点となる位置を定義*/
  transition: 0.3s ease-in-out; /*移り変わる速さを変更したい場合はこの数値を変更*/
  display: block; /*画像をくくるspanタグをブロック要素にする*/
  line-height: 0; /*行の高さを0にする*/
}

.opacityText:hover span.mask::before {
  /*hoverした時の変化*/
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    45deg,
    rgba(88, 182, 211, 0.6),
    rgba(229, 93, 135, 0.6)
  ); /*背景色(グラデーション)*/
}

.opacityText img {
  opacity: 1;
  transition: 0.3s ease-in-out; /*移り変わる速さを変更したい場合はこの数値を変更*/
}

.opacityText:hover img {
  /*hoverした時の変化*/
  opacity: 0.5; /*透過具合を変更したい場合はこの数値を変更*/
}

.opacityText span.cap {
  opacity: 0;
  transition: 0.5s ease-in-out; /*移り変わる速さを変更したい場合はこの数値を変更*/
  position: absolute;
  z-index: 3; /*テキストを前面に出す*/
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff; /*テキストの色を変えたい場合はここを修正*/
  line-height: 1.5; /*行の高さを1.5にする*/
}

.opacityText:hover span.cap {
  /*hoverした時の変化*/
  opacity: 1;
  text-shadow: 1px 1px 2px #000;
}

/*========= レイアウトのためのCSS ===============*/

a {
  color: #333;
  text-decoration: none;
}

.lead {
  text-align: center;
  padding: 50px 20px;
}

/*画像のレスポンシブ*/

img {
  width: 100%;
  height: auto;
}

/* 横幅 */

.opacityText {
  width: 70%;
  margin: 0 auto; /*中央揃え*/
}

              
            
!

JS

              
                
              
            
!
999px

Console