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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="block">
	  <div class="box">
	    <div class="box-inner">
				box-innerの縦幅が180pxを超えるとmoreが出現する<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
				テキスト<br>
	    </div>
	  </div>
	</div>
	<div class="block">
	  <div class="box">
	    <div class="box-inner">
				縦幅180pxを超えない場合は出ない
	    </div>
	  </div>
	</div>
              
            
!

CSS

              
                .block{
	margin-bottom: 30px;
}
.box{
	max-width: 600px;
	margin: 0 auto;
	background: #ddd;
  overflow: hidden;
}
.box-inner{
	padding: 10px 20px;
}
.more{
  height: 55px;
	line-height: 55px;
  margin-top: -25px;
  text-align: center;
	color: #2e9ce5;
	cursor: pointer;

  background: rgba(255,255,255,0);
  background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 31%, rgba(255,255,255,1) 100%);
  background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(255,255,255,0)), color-stop(0%, rgba(255,255,255,0)), color-stop(31%, rgba(255,255,255,1)), color-stop(100%, rgba(255,255,255,1)));
  background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 31%, rgba(255,255,255,1) 100%);
  background: -o-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 31%, rgba(255,255,255,1) 100%);
  background: -ms-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 31%, rgba(255,255,255,1) 100%);
  &:after{
  	content:'↓';
		display: inline-block;
		font-weight: bold;
		font-size: 18px;
		-webkit-transition: .3s;
		transition: .3s;
  }
  &.is-active{
    &:after{
      -webkit-transform:rotate(180deg);
      transform:rotate(180deg);
    }
  }
}
              
            
!

JS

              
                $(function(){
	
	var box = $('.box');
	box.after('<div class="more">MORE</div>');
	var more = $('.more');
	
	function remClass(){
		$(this).next(more).removeClass('is-active');
	}
	function adClass(){
		$(this).next(more).addClass('is-active');
	}
	
	//forで.box-innerの高さを取得、縦幅が180pxより小さい場合.moreをhideする
	for(var i=0;i<box.length;i++){
		var boxInnerH = $('.box-inner').eq(i).innerHeight();
		if(boxInnerH<180){
			more.eq(i).hide();
		}else{
			box.eq(i).css({
				height:'180px'
			});
		}
	}
	
	more.on('click',function(){
		
		//複数あった時を考慮
		//クリックした.moreに対応する.box-innerの高さを取得する
		var index = more.index(this);
		var boxThis = box.eq(index);
		var innerH = $('.box-inner').eq(index).innerHeight();
		
		if($(this).hasClass('is-active')){
			boxThis.animate({
				height:'180px'
			},200,remClass);
		}else{
			boxThis.animate({
				height:innerH
			},200,adClass);
		}
	});
});
              
            
!
999px

Console