cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <ul class="wrapper">
  <li>
    <a href="">
      <div class="image">
        <img src="http://designcolor-web.com/sample/img/css-responsive-image-trimming_270x270.jpg" alt="" />
      </div>
      <p>画像を中央でトリミングして表示</p>
    </a> 
  </li>
   <li>
    <a href="">
      <div class="image">
        <img src="http://designcolor-web.com/sample/img/css-responsive-image-trimming_300x200.jpg" alt="" />
      </div>
      <p>画像を中央でトリミングして表示</p>
    </a> 
  </li>
   <li>
    <a href="">
      <div class="image">
        <img src="http://designcolor-web.com/sample/img/css-responsive-image-trimming_500x300.jpg" alt="" />
      </div>
      <p>画像を中央でトリミングして表示</p>
    </a> 
  </li>
   <li>
    <a href="">
      <div class="image">
        <img src="http://designcolor-web.com/sample/img/css-responsive-image-trimming_400x440.jpg" alt="" />
      </div>
      <p>画像を中央でトリミングして表示</p>
    </a> 
  </li>
</ul>
            
          
!
            
              body{
  padding: 5% 3%;
}
.wrapper{
  max-width: 550px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0 auto;
}
li{
  position: relative;
  width: 48%;
  height: auto;
  margin: 0 1% 2%;
}
.image{
  position: relative;
  width: 100%;/* トリミングしたい枠の幅(固定にしたい場合はサイズを入力) */
  padding-top: 75%;/* トリミングしたい枠の高さ(固定にしたい場合はサイズを入力) */
  overflow: hidden;/* 画像が枠からはみ出た部分はトリミング(非表示)する */
  margin: 0 auto;
}
.image img{
/* 画像を上下左右に中央配置する(絶対指定) */
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  /* 画像の最大サイズは枠の1.5倍まで */
  max-width: 150%;
  max-height: 150%;
}
p{
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 5% 2%;
  font-size: 12px;
  line-height: 1.2;
  color: #fff;
  background: rgba(0,0,0, .7);
  text-align: center;
  box-sizing: border-box;
}
a{
  text-decoration: none;
}
a:hover img{
  opacity: 0.8;
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console