2016-08-17 10 views
-1

このタイムラインを作成するには、この素晴らしいコードがあります。私は自分のために編集しています。しかし、私はそれを垂直に短くすることを試みましたが失敗しました。私は、ブロックの右または左に空きスペースを持たず、小さな垂直エリアを取る代わりに、ブロックを垂直方向に上に移動して、ラインの両側を埋めることができるようにする必要があります。垂直方向のタイムラインでブロックを互いに近づけるにはどうすればいいですか?

ご意見をお寄せください。

https://codepen.io/codyhouse/pen/FdkEf

jQuery(document).ready(function($){ 
 
\t var $timeline_block = $('.cd-timeline-block'); 
 

 
\t //hide timeline blocks which are outside the viewport 
 
\t $timeline_block.each(function(){ 
 
\t \t if($(this).offset().top > $(window).scrollTop()+$(window).height()*0.75) { 
 
\t \t \t $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden'); 
 
\t \t } 
 
\t }); 
 

 
\t //on scolling, show/animate timeline blocks when enter the viewport 
 
\t $(window).on('scroll', function(){ 
 
\t \t $timeline_block.each(function(){ 
 
\t \t \t if($(this).offset().top <= $(window).scrollTop()+$(window).height()*0.75 && $(this).find('.cd-timeline-img').hasClass('is-hidden')) { 
 
\t \t \t \t $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in'); 
 
\t \t \t } 
 
\t \t }); 
 
\t }); 
 
});
@import "bourbon"; 
 

 
// variables - colors 
 

 
$main-text: #7f8c97; // main text 
 
$link: #acb7c0; // anchor tags 
 
$background: #e9f0f5; // body background color 
 

 
$color-1: #303e49; // blue dark 
 
$color-2: #c03b44; // red 
 
$color-3: #ffffff; // white 
 
$color-4: #75ce66; // green 
 
$color-5: #f0ca45; // yellow 
 

 
// variables - fonts 
 

 
$primary-font: 'Droid Serif', serif; 
 
$secondary-font: 'Open Sans', sans-serif; 
 

 
// mixins - rem fallback - credits: http://zerosixthree.se/ 
 

 
@function calculateRem($size) { 
 
    $remSize: $size/16px; 
 
    @return $remSize * 1rem; 
 
} 
 

 
@mixin font-size($size) { 
 
    font-size: $size; 
 
    font-size: calculateRem($size); 
 
} 
 

 
// mixins - border radius 
 

 
@mixin border-radius($radius:.25em) { 
 
    border-radius: $radius; 
 
} 
 

 
// layout - breakpoints 
 
    
 
$S:  320px; 
 
$M:  768px;  
 
$L:  1170px;  
 

 
// layout - media queries 
 

 
@mixin MQ($canvas) { 
 
    @if $canvas == S { 
 
    @media only screen and (min-width: $S) { @content; } 
 
    } 
 
    @else if $canvas == M { 
 
    @media only screen and (min-width: $M) { @content; } 
 
    } 
 
    @else if $canvas == L { 
 
    @media only screen and (min-width: $L) { @content; } 
 
    } 
 
} 
 

 
/* -------------------------------- 
 

 
Primary style 
 

 
-------------------------------- */ 
 

 
html * { 
 
\t -webkit-font-smoothing: antialiased; 
 
\t -moz-osx-font-smoothing: grayscale; 
 
} 
 

 
*, *:after, *:before { 
 
\t @include box-sizing(border-box); 
 
} 
 

 
body { 
 
\t font: { 
 
\t \t size: 100%; 
 
\t \t family: $primary-font; 
 
\t } 
 
\t color: $main-text; 
 
\t background-color: $background; 
 
} 
 

 
a { 
 
\t color: $link; 
 
\t text-decoration: none; 
 
\t font-family: $secondary-font; 
 
} 
 

 
img { 
 
\t max-width: 100%; 
 
} 
 

 
h1, h2 { 
 
\t font-family: $secondary-font; 
 
\t font-weight: bold; 
 
} 
 

 
/* -------------------------------- 
 

 
Modules - reusable parts of our design 
 

 
-------------------------------- */ 
 

 
.cd-container { /* this class is used to give a max-width to the element it is applied to, and center it horizontally when it reaches that max-width */ 
 
\t width: 90%; 
 
\t max-width: $L; // breakpoints inside partials > _layout.scss 
 
\t margin: 0 auto; 
 

 
\t &::after { /* clearfix */ 
 
\t \t content: ''; 
 
\t \t display: table; 
 
\t \t clear: both; 
 
\t } 
 
} 
 

 
/* -------------------------------- 
 

 
Main components 
 

 
-------------------------------- */ 
 

 
header { 
 
\t height: 200px; 
 
\t line-height: 200px; 
 
\t text-align: center; 
 
\t background: $color-1; 
 

 
\t h1 { 
 
\t \t color: $color-3; 
 
\t \t @include font-size(18px); 
 
\t } 
 

 
\t @include MQ(L) { 
 
\t \t height: 300px; 
 
\t \t line-height: 300px; 
 

 
\t \t h1 { 
 
\t \t \t @include font-size(24px); 
 
\t \t } 
 
\t } 
 
} 
 

 
#cd-timeline { 
 
\t position: relative; 
 
\t padding: 2em 0; 
 
\t margin: { 
 
\t \t top: 2em; 
 
\t \t bottom: 2em; 
 
\t } 
 

 
\t &::before { 
 
\t \t /* this is the vertical line */ 
 
\t \t content: ''; 
 
\t \t position: absolute; 
 
\t \t top: 0; 
 
\t \t left: 18px; 
 
\t \t height: 100%; 
 
\t \t width: 4px; 
 
\t \t background: darken($background, 5%); 
 
\t } 
 

 
\t @include MQ(L) { 
 
\t \t margin: { 
 
\t \t \t top: 3em; 
 
\t \t \t bottom: 3em; 
 
\t \t } 
 

 
\t \t &::before { 
 
\t \t \t left: 50%; 
 
\t \t \t margin-left: -2px; 
 
\t \t } 
 
\t } 
 
} 
 

 
.cd-timeline-block { 
 
\t position: relative; 
 
\t margin: 2em 0; 
 
\t @include clearfix; 
 

 
\t &:first-child { 
 
\t \t margin-top: 0; 
 
\t } 
 

 
\t &:last-child { 
 
\t \t margin-bottom: 0; 
 
\t } 
 

 
\t @include MQ(L) { 
 
\t \t margin: 4em 0; 
 

 
\t \t &:first-child { 
 
\t \t \t margin-top: 0; 
 
\t \t } 
 

 
\t \t &:last-child { 
 
\t \t \t margin-bottom: 0; 
 
\t \t } 
 
\t } 
 
} 
 

 
.cd-timeline-img { 
 
\t position: absolute; 
 
\t top: 0; 
 
\t left: 0; 
 
\t width: 40px; 
 
\t height: 40px; 
 
\t border-radius: 50%; 
 
\t box-shadow: 0 0 0 4px $color-3, inset 0 2px 0 rgba(#000, .08), 0 3px 0 4px rgba(#000, .05) ; 
 

 
\t img { 
 
\t \t display: block; 
 
\t \t width: 24px; 
 
\t \t height: 24px; 
 
\t \t position: relative; 
 
\t \t left: 50%; 
 
\t \t top: 50%; 
 
\t \t margin-left: -12px; 
 
\t \t margin-top: -12px; 
 
\t } 
 

 
\t &.cd-picture { 
 
\t \t background: $color-4; 
 
\t } 
 

 
\t &.cd-movie { 
 
\t \t background: $color-2; 
 
\t } 
 

 
\t &.cd-location { 
 
\t \t background: $color-5; 
 
\t } 
 

 
\t @include MQ(L) { 
 
\t \t width: 60px; 
 
\t \t height: 60px; 
 
\t \t left: 50%; 
 
\t \t margin-left: -30px; 
 

 
\t \t /* Force Hardware Acceleration in WebKit */ 
 
\t \t -webkit-transform: translateZ(0); 
 
\t \t -webkit-backface-visibility: hidden; 
 

 
\t \t .cssanimations &.is-hidden { 
 
\t \t \t visibility: hidden; 
 
\t \t } 
 

 
\t \t .cssanimations &.bounce-in { 
 
\t \t \t visibility: visible; 
 
\t \t \t @include animation(cd-bounce-1 .6s); 
 
\t \t } 
 
\t } 
 
} 
 

 
@include keyframes(cd-bounce-1) { 
 
\t 0% { 
 
\t \t opacity: 0; 
 
\t \t @include transform(scale(.5)); 
 
\t } 
 

 
\t 60% { 
 
\t \t opacity: 1; 
 
\t \t @include transform(scale(1.2)); 
 
\t } 
 

 
\t 100% { 
 
\t \t @include transform(scale(1)); 
 
\t } 
 
} 
 

 
.cd-timeline-content { 
 
\t position: relative; 
 
\t margin-left: 60px; 
 
\t background: $color-3; 
 
\t @include border-radius; 
 
\t padding: 1em; 
 
\t box-shadow: 0 3px 0 darken($background, 5%); 
 
\t @include clearfix; 
 

 
\t h2 { 
 
\t \t color: $color-1; 
 
\t } 
 

 
\t p, .cd-read-more, .cd-date { 
 
\t \t @include font-size(13px); 
 
\t } 
 

 
\t .cd-read-more, .cd-date { 
 
\t \t display: inline-block; 
 
\t } 
 

 
\t p { 
 
\t \t margin: 1em 0; 
 
\t \t line-height: 1.6; 
 
\t } 
 

 
\t .cd-read-more { 
 
\t \t float: right; 
 
\t \t padding: .8em 1em; 
 
\t \t background: $link; 
 
\t \t color: $color-3; 
 
\t \t @include border-radius; 
 

 
\t \t .no-touch &:hover { 
 
\t \t \t background-color: lighten($link, 5%); 
 
\t \t } 
 
\t } 
 

 
\t .cd-date { 
 
\t \t float: left; 
 
\t \t padding: .8em 0; 
 
\t \t opacity: .7; 
 
\t } 
 

 
\t &::before { 
 
\t \t content: ''; 
 
\t \t position: absolute; 
 
\t \t top: 16px; 
 
\t \t right: 100%; 
 
\t \t height: 0; 
 
\t \t width: 0; 
 
\t \t border: 7px solid transparent; 
 
\t \t border-right: 7px solid $color-3; 
 
\t } 
 

 
\t @include MQ(M) { 
 
\t \t h2 { 
 
\t \t \t @include font-size(20px); 
 
\t \t } 
 

 
\t \t p { 
 
\t \t \t @include font-size(16px); 
 
\t \t } 
 

 
\t \t .cd-read-more, .cd-date { 
 
\t \t \t @include font-size(14px); 
 
\t \t } 
 
\t } 
 

 
\t @include MQ(L) { 
 
\t \t margin-left: 0; 
 
\t \t padding: 1.6em; 
 
\t \t width: 45%; 
 

 
\t \t &::before { 
 
\t \t \t top: 24px; 
 
\t \t \t left: 100%; 
 
\t \t \t border-color: transparent; 
 
\t \t \t border-left-color: $color-3; 
 
\t \t } 
 

 
\t \t .cd-read-more { 
 
\t \t \t float: left; 
 
\t \t } 
 

 
\t \t .cd-date { 
 
\t \t \t position: absolute; 
 
\t \t \t width: 100%; 
 
\t \t \t left: 122%; 
 
\t \t \t top: 6px; 
 
\t \t \t @include font-size(16px); 
 
\t \t } 
 

 
\t \t .cd-timeline-block:nth-child(even) & { 
 
\t \t \t float: right; 
 

 
\t \t \t &::before { 
 
\t \t \t \t top: 24px; 
 
\t \t \t \t left: auto; 
 
\t \t \t \t right: 100%; 
 
\t \t \t \t border-color: transparent; 
 
\t \t \t \t border-right-color: $color-3; 
 
\t \t \t } 
 

 
\t \t \t .cd-read-more { 
 
\t \t \t \t float: right; 
 
\t \t \t } 
 

 
\t \t \t .cd-date { 
 
\t \t \t \t left: auto; 
 
\t \t \t \t right: 122%; 
 
\t \t \t \t text-align: right; 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t .cssanimations &.is-hidden { 
 
\t \t \t visibility: hidden; 
 
\t \t } 
 

 
\t \t .cssanimations &.bounce-in { 
 
\t \t \t visibility: visible; 
 
\t \t \t @include animation(cd-bounce-2 .6s); 
 
\t \t } 
 
\t } 
 
} 
 

 
@include MQ(L) { 
 
\t /* inverse bounce effect on even content blocks */ 
 
\t .cssanimations .cd-timeline-block:nth-child(even) .cd-timeline-content.bounce-in { 
 
\t \t @include animation(cd-bounce-2-inverse .6s); 
 
\t } 
 
} 
 

 
@include keyframes(cd-bounce-2) { 
 
\t 0% { 
 
\t \t opacity: 0; 
 
\t \t @include transform(translateX(-100px)); 
 
\t } 
 

 
\t 60% { 
 
\t \t opacity: 1; 
 
\t \t @include transform(translateX(20px)); 
 
\t } 
 

 
\t 100% { 
 
\t \t @include transform(translateX(0)); 
 
\t } 
 
} 
 

 
@include keyframes(cd-bounce-2-inverse) { 
 
\t 0% { 
 
\t \t opacity: 0; 
 
\t \t @include transform(translateX(100px)); 
 
\t } 
 

 
\t 60% { 
 
\t \t opacity: 1; 
 
\t \t @include transform(translateX(-20px)); 
 
\t } 
 

 
\t 100% { 
 
\t \t @include transform(translateX(0)); 
 
\t } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section id="cd-timeline" class="cd-container"> 
 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-picture"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-picture.svg" alt="Picture"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Title of section 1</h2> 
 
\t \t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, optio, dolorum provident rerum aut hic quasi placeat iure tempora laudantium ipsa ad debitis unde? Iste voluptatibus minus veritatis qui ut.</p> 
 
\t \t \t \t <a href="#0" class="cd-read-more">Read more</a> 
 
\t \t \t \t <span class="cd-date">Jan 14</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 

 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-movie"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-movie.svg" alt="Movie"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Title of section 2</h2> 
 
\t \t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, optio, dolorum provident rerum aut hic quasi placeat iure tempora laudantium ipsa ad debitis unde?</p> 
 
\t \t \t \t <a href="#0" class="cd-read-more">Read more</a> 
 
\t \t \t \t <span class="cd-date">Jan 18</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 

 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-picture"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-picture.svg" alt="Picture"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Title of section 3</h2> 
 
\t \t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, obcaecati, quisquam id molestias eaque asperiores voluptatibus cupiditate error assumenda delectus odit similique earum voluptatem doloremque dolorem ipsam quae rerum quis. Odit, itaque, deserunt corporis vero ipsum nisi eius odio natus ullam provident pariatur temporibus quia eos repellat consequuntur perferendis enim amet quae quasi repudiandae sed quod veniam dolore possimus rem voluptatum eveniet eligendi quis fugiat aliquam sunt similique aut adipisci.</p> 
 
\t \t \t \t <a href="#0" class="cd-read-more">Read more</a> 
 
\t \t \t \t <span class="cd-date">Jan 24</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 

 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-location"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-location.svg" alt="Location"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Title of section 4</h2> 
 
\t \t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, optio, dolorum provident rerum aut hic quasi placeat iure tempora laudantium ipsa ad debitis unde? Iste voluptatibus minus veritatis qui ut.</p> 
 
\t \t \t \t <a href="#0" class="cd-read-more">Read more</a> 
 
\t \t \t \t <span class="cd-date">Feb 14</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 

 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-location"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-location.svg" alt="Location"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Title of section 5</h2> 
 
\t \t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iusto, optio, dolorum provident rerum.</p> 
 
\t \t \t \t <a href="#0" class="cd-read-more">Read more</a> 
 
\t \t \t \t <span class="cd-date">Feb 18</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 

 
\t \t <div class="cd-timeline-block"> 
 
\t \t \t <div class="cd-timeline-img cd-movie"> 
 
\t \t \t \t <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148866/cd-icon-movie.svg" alt="Movie"> 
 
\t \t \t </div> <!-- cd-timeline-img --> 
 

 
\t \t \t <div class="cd-timeline-content"> 
 
\t \t \t \t <h2>Final Section</h2> 
 
\t \t \t \t <p>This is the content of the last section</p> 
 
\t \t \t \t <span class="cd-date">Feb 26</span> 
 
\t \t \t </div> <!-- cd-timeline-content --> 
 
\t \t </div> <!-- cd-timeline-block --> 
 
\t </section> <!-- cd-timeline -->

+0

サイドバイサイドまたは間隔を単に取り除く? –

+0

スペースを取り除くと、ブロックが横に並んで座っていると思います – syzd

+0

横並びではなく、グリッドシステムです。スペースを減らす必要があるだけであれば、マージンを変更することができます –

答えて

-1

.cd容器は、ビューのサイズおよび90%の幅のためのブレークポイントによって設定される最大幅を有します。

具体的には、幅を制限するコンテナのブレークポイントです。

ブラウザのデバッグツールを使用してください。

+0

私が正しく理解すれば、私は幅について話していません、私は高さについて話しています。私はブロックの下に座って大きな垂直空間を作るのではなく、お互いの隣に座ってほしい – syzd

関連する問題