2016-07-07 71 views
1

在時間軸上,我想顯示一天的小時數:JSFiddle:https://jsfiddle.net/9532otkm/2/(簡體)。Responsive leave out Divs

<div class="day"> 
<div class="hour">1</div> 
<div class="hour">2</div> 
<div class="hour">3</div> 
<div class="hour">4</div> 
... 
<div class="hour">22</div> 
<div class="hour">23</div> 
<div class="hour">24</div> 
</div> 

.day{ 
    border: 2px solid #73AD21; 
    width: 800px; 

} 
.hour{ 
    display: inline-block; 
    width: 2em; 
    text-align: center; 
    vertical-align: middle; 
} 

當外部div變小時,將不會有更多的空間來顯示所有的小時。

是否有可能與響應css/jquery重新調整方式,我遺漏了一些divs。

例如: 第一個所有小時,如果沒有足夠的空間,則只有3個小時,9個,15 & 21 ...

+0

3,9,15和21爲什麼?什麼是隱藏一些領域的模式? –

+0

我並不清楚,我的意思是其他方面,只有顯示3,9,15和21 :) – Paul

回答

2

可以使用@media查詢此

.day{ 
 
    border: 2px solid #73AD21; 
 
    display: inline-block; 
 
} 
 
.hour{ 
 
    display: inline-block; 
 
    width: 2em; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 

 
@media screen and (max-width: 700px) { /* adjust the 700px value for your needs */ 
 

 
    /* specific items ver. 2 */ 
 
    .hour 
 
    {display: none} 
 
    
 
    .hour:nth-of-type(3), 
 
    .hour:nth-of-type(9), 
 
    .hour:nth-of-type(15), 
 
    .hour:nth-of-type(21) 
 
    {display: inline-block} 
 

 
    /* specific items 
 
    .hour:nth-of-type(3), 
 
    .hour:nth-of-type(9), 
 
    .hour:nth-of-type(15), 
 
    .hour:nth-of-type(21) 
 
    {display: none} 
 
    */ 
 

 
    /* odd or even 
 
    .hour:nth-of-type(even) 
 
    {display: none} 
 
    */ 
 
}
<div class="day"> 
 
    <div class="hour">1</div> 
 
    <div class="hour">2</div> 
 
    <div class="hour">3</div> 
 
    <div class="hour">4</div> 
 
    <div class="hour">5</div> 
 
    <div class="hour">6</div> 
 
    <div class="hour">7</div> 
 
    <div class="hour">8</div> 
 
    <div class="hour">9</div> 
 
    <div class="hour">10</div> 
 
    <div class="hour">11</div> 
 
    <div class="hour">12</div> 
 
    <div class="hour">13</div> 
 
    <div class="hour">14</div> 
 
    <div class="hour">15</div> 
 
    <div class="hour">16</div> 
 
    <div class="hour">17</div> 
 
    <div class="hour">18</div> 
 
    <div class="hour">19</div> 
 
    <div class="hour">20</div> 
 
    <div class="hour">21</div> 
 
    <div class="hour">22</div> 
 
    <div class="hour">23</div> 
 
    <div class="hour">24</div> 
 
</div>

更新基於評論

document.querySelector('input').addEventListener('change', function(e){ 
 
    document.querySelector('.day').style.width = e.target.value + 'px'; 
 
    if (e.target.value < 484) { 
 
    document.querySelector('.day').classList.add('hide'); 
 
    } else { 
 
    document.querySelector('.day').classList.remove('hide'); 
 
    } 
 
})
.day{ 
 
    border: 2px solid #73AD21; 
 
    width: 484px; 
 
    overflow: hidden; 
 
} 
 
.hour{ 
 
    float: left; 
 
    width: 20px; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 
.day.hide .hour{ 
 
    display: none 
 
} 
 
.day.hide .hour:nth-of-type(3), 
 
.day.hide .hour:nth-of-type(9), 
 
.day.hide .hour:nth-of-type(15), 
 
.day.hide .hour:nth-of-type(21){ 
 
    display: inline-block 
 
}
<div class="day"> 
 
    <div class="hour">1</div> 
 
    <div class="hour">2</div> 
 
    <div class="hour">3</div> 
 
    <div class="hour">4</div> 
 
    <div class="hour">5</div> 
 
    <div class="hour">6</div> 
 
    <div class="hour">7</div> 
 
    <div class="hour">8</div> 
 
    <div class="hour">9</div> 
 
    <div class="hour">10</div> 
 
    <div class="hour">11</div> 
 
    <div class="hour">12</div> 
 
    <div class="hour">13</div> 
 
    <div class="hour">14</div> 
 
    <div class="hour">15</div> 
 
    <div class="hour">16</div> 
 
    <div class="hour">17</div> 
 
    <div class="hour">18</div> 
 
    <div class="hour">19</div> 
 
    <div class="hour">20</div> 
 
    <div class="hour">21</div> 
 
    <div class="hour">22</div> 
 
    <div class="hour">23</div> 
 
    <div class="hour">24</div> 
 
</div> 
 
<input type="range" name="points" min="100" max="968">

+0

謝謝! 我明白最大寬度代表屏幕寬度。 是否可以鏈接到「day」-Dav? – Paul

+0

@Paul如果你用'screen'表示'viewport'(瀏覽器窗口),是的,否則不,不是監視器的屏幕。 – LGSon

+0

@Paul更新了我的答案 – LGSon

1

自定義解決方案是類添加到小時像這樣

<div class="hour small">6</div>480px 

ANSD然後添加一個額外的CSS樣式時,屏幕是小於480像素隱藏元素與此類名稱

@media screen and (max-width: 480px) { 
    .small { 
     display : none; 
    } 
} 

見更新FID DLE這裏

https://jsfiddle.net/9532otkm/5/

+0

謝謝你,看看我對LGSon'解決方案的評論:) – Paul

+0

@Paul:你想要一個數字disapear或?你想要一個固定的寬度的日子div?要麼? – lordkain