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

              
                <div class="position-relative d-inline-block">
  <img class="imgset bg-mask" src="https://images.unsplash.com/photo-1606670311254-631ac68ef80c?ixid=MXwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxMnx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60" alt="">
  <p class="position-absolute soldout">Sold out</p>
</div>

<!-- 
absolute 如果父層沒有設定 relative,就會以 body 為基準點。
金魚腦一度一直在同層的 img 設定 relative 難怪沒反應 ,冏 !
.
所以 img 與 sold out 外面包一個父層設定 relative 讓 absolute 對齊,
sold out 文字對齊可使用右方 transform 屬性。而圖片上方的深灰色遮罩
使用 filter 屬性,不需要使用絕對與相對定位,直接寫 class 在要套用的 html 標籤上即可。
.
因為 div 為區塊元素,所以加上 inline-block 防止 sold out 文字位置跑到 div 整個寬度的中間。可拿掉 div 的 inline-block 試試。
-->
              
            
!

CSS

              
                .position{
  &-relative{
  position:relative;
  }
  &-absolute{
  position:absolute;
  }  
}
.d-inline-block{
  display: inline-block;
}
.imgset{
  width: 300px;
  height: auto;
  display: block;
}
.soldout{
  transform:translate(-50% , -50%);
  top:50%;
  left:50%;
  white-space: nowrap;  
  font-weight: 700;
  font-size: 20px;
  color:#feda77;
}
.bg-mask{
  filter:brightness(60%);
}

              
            
!

JS

              
                
              
            
!
999px

Console