0

テキストの非表示と表示が tag に依存するコードがいくつかあります<section>

1 つのセクションが 2 番目に表示され、[表示] ボタンをクリックするまで非表示になります。

文字数によっては作り方が分からないのですが、

たとえば、最初の 100 文字が表示され、表示ボタンをクリックすると残りのテキストが表示されます。

そして、ここに私のコードがあります

HTML

<article>
<input type="checkbox" id="read_more" role="button">
<label for="read_more" onclick=""><span>Show</span><span>Hide</span></label>     
<figure>
<img src="HERE MUST BE A IMAGE.jpg" alt="" />
</figure>

<section>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</section>

<section>
    <b>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</b>
</section>

</article>

そしてCSS

figure {
    margin: 0 0 1.3rem 0;
    -webkit-transition: .125s linear;
    -moz-transition: .125s linear;
    -ms-transition: .125s linear;
    -o-transition: .125s linear;
    transition: .125s linear;
}

figure img {
    max-width: 100%;
    height: auto;
}



body:before, body:after {
    content: "";
    display: table;
}

body:after { clear: both }

p { margin-bottom: 1.3rem }

article {
    margin-bottom: 3rem;
    position: relative;
    *zoom: 1;
}

article:before, article:after {
    content: "";
    display: table;
}

article:after { clear: both }

article figure {
    float: left;
    width: 32.5%;
}

article section:first-of-type {
    float: right;
    width: 62.5%;
}

article section:last-of-type {
    display: none;
    visibility: hidden;
}

section {
    -webkit-transition: .125s linear;
    -moz-transition: .125s linear;
    -ms-transition: .125s linear;
    -o-transition: .125s linear;
    transition: .125s linear;
}

input[type=checkbox] {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
}

[for="read_more"] {
    position: absolute;
    bottom: -3rem;
    left: 0;
    width: 100%;
    text-align: center;
    padding: .65rem;
    box-shadow: inset 1px 1px rgba(0, 0, 0, 0.1), inset -1px -1px rgba(0, 0, 0, 0.1);
}

[for="read_more"]:hover {
    background: rgba(0,0,0,.5);
    color: rgb(255,255,255);
}

[for="read_more"] span:last-of-type {
    display: none;
    visibility: hidden;
}

input[type=checkbox]:checked ~ section {
    display: block;
    visibility: visible;
    width: 100%;
}

input[type=checkbox]:checked ~ figure { width: 100% }

input[type=checkbox]:checked ~ [for="read_more"] span:first-of-type {
    display: none;
    visibility: hidden;
}

input[type=checkbox]:checked ~ [for="read_more"] span:last-of-type {
    display: block;
    visibility: visible;
}

これがjsfiddleの例です

ありがとうございました

4

1 に答える 1