2017-10-11 8 views
0

CSSでcalcを使って何かを計算しようとしています。数時間後、私の実際のdivは間違った100%の数字を与えることが分かりました。ここCSSはdivから100%得られ、ページ全体ではありません

が小さい例である:

html, body, .calender { 
 
\t position: relative; 
 
\t height: 100%; 
 
\t overflow: hidden; 
 
} 
 

 
.appointmentsA { 
 
\t background: blue; 
 
} 
 

 
.appointmentsB { 
 
\t background: red; 
 
} 
 

 
.calender { 
 
\t display: table; 
 
\t width: 100%; 
 
\t table-layout: fixed; 
 
\t padding: 10px 10px 0 10px; 
 
} 
 
.calender .row { 
 
\t display: table-cell; 
 
\t padding: 0 10px; 
 
} 
 

 
.appointments { 
 
\t height: 100%; 
 
} 
 

 
.appointments:before { 
 
\t \t \t content: "test"; 
 
\t \t \t position: absolute; 
 
\t \t \t top: calc(100% - 18px); 
 
\t \t \t color: #fff; 
 
\t \t }
<main class="calender"> 
 
\t <div class="row"> 
 
\t \t <h1 class="title">ABC</h1> 
 
\t \t <div class="appointments appointmentsA"></div> 
 
\t </div> 
 
\t <div class="row"> 
 
\t \t <h1 class="title">DEF</h1> 
 
\t \t <div class="appointments appointmentsB"></div> 
 
\t </div> 
 
</main>

赤と青のブロックが容器rowとメイン親と同じ高さを有します。

色付きブロックの高さを100%にするJavaScriptはありませんか? 着色されたブロックが実際の100%を持つ場合、 ":after"要素はハーフテキストだけでなく正しく表示されます。

画像:example

+0

あなたは "色のブロックの100%の高さを取得するには、" 何を意味するのですか? – DaFois

+0

サンプルを実行してデベロッパーツールでそれを調べると、計算された高さが表示されます。これは、例えば、「予約」ブロックと同じ高さを「予約」ブロックに表示する。 "行"ブロック(タイトル付き) –

+0

私はまだundestand申し訳ありません – DaFois

答えて

0

あなたはフルハイトCOLの色を設定することを意味しますか?

* { 
 
    box-sizing: border-box; 
 
} 
 

 
html, 
 
body, 
 
.calender { 
 
    position: relative; 
 
    height: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.appointmentsA { 
 
    background: blue; 
 
} 
 

 
.appointmentsB { 
 
    background: red; 
 
} 
 

 
.calender { 
 
    display: table; 
 
    width: 100%; 
 
    table-layout: fixed; 
 
    padding: 10px 10px 0 10px; 
 
} 
 

 
.calender .row { 
 
    display: table-cell; 
 
    padding: 0 10px; 
 
} 
 

 
.appointments { 
 
    height: 100%; 
 
} 
 

 
.title { 
 
    position: absolute; 
 
}
<main class="calender"> 
 
    <div class="row"> 
 
    <h1 class="title">ABC</h1> 
 
    <div class="appointments appointmentsA"></div> 
 
    </div> 
 
    <div class="row"> 
 
    <h1 class="title">DEF</h1> 
 
    <div class="appointments appointmentsB"></div> 
 
    </div> 
 
</main>

または着色のdivのために:私は私が正しくあなたを理解してきました願っています

* { 
 
    box-sizing: border-box; 
 
} 
 

 
html, 
 
body, 
 
.calender { 
 
    position: relative; 
 
    height: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.appointmentsA { 
 
    background: blue; 
 
} 
 

 
.appointmentsB { 
 
    background: red; 
 
} 
 

 
.calender { 
 
    display: table; 
 
    width: 100%; 
 
    table-layout: fixed; 
 
    padding: 10px 10px 0 10px; 
 
} 
 

 
.calender .row { 
 
    display: table-cell; 
 
    padding: 0 10px; 
 
    position: relative; 
 
} 
 

 
.appointments { 
 
    height: 100%; 
 
    position: absolute; 
 
    width: 100%; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
} 
 

 
.title { 
 
    position: relative; 
 
    z-index: 2; 
 
}
<main class="calender"> 
 
    <div class="row"> 
 
    <h1 class="title">ABC</h1> 
 
    <div class="appointments appointmentsA"></div> 
 
    </div> 
 
    <div class="row"> 
 
    <h1 class="title">DEF</h1> 
 
    <div class="appointments appointmentsB"></div> 
 
    </div> 
 
</main>

+0

私はすべてを色づけしたくありません。私はcalc関数で私の例を変更しました。 –

+0

イメージを取得したいものを表示すると、何が欲しいのか分かりにくいです。 – kizoso

0

それがある場合は、タイトルのためposition: absoluteを設定します。

h1は、ブロックレベルの要素です。 div .appointmentsは、あなたの構造内にあります。 h1background-colorを対応する.appointmentに設定し、下のmarginを削除するか、appointmentの中にh1を入れ子にすることができます。以下のスニペットで行っています。

html, 
 
body, 
 
.calender { 
 
    position: relative; 
 
    height: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.appointmentsA { 
 
    background: blue; 
 
} 
 

 
.appointmentsB { 
 
    background: red; 
 
} 
 

 
.calender { 
 
    display: table; 
 
    width: 100%; 
 
    table-layout: fixed; 
 
    padding: 10px 10px 0 10px; 
 
} 
 

 
.calender .row { 
 
    display: table-cell; 
 
    padding: 0 10px; 
 
} 
 

 
.appointments { 
 
    height: 100%; 
 
}
<main class="calender"> 
 
    <div class="row"> 
 
    <div class="appointments appointmentsA"> 
 
     <h1 class="title">ABC</h1> 
 
    </div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="appointments appointmentsB"> 
 
     <h1 class="title">DEF</h1> 
 
    </div> 
 
    </div> 
 
</main>

+0

私はすべての色にしたくないので、私はcalc関数で私の例を変更しました。 –

+1

@ Mr.Tr33希望の結果がどのように見えるかのイメージを提供できますか?ありがとう – sol

関連する問題