display content above labels using radio tabs - CSS only? - html

I am trying to display the content ABOVE the tab labels when clicked. Is there a simple way to do this? Maybe using CSS only? When placing the content div above the label the page breaks... Any ideas will be appreciated.
Thanks in advance!
DEMO LINK
CSS
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin: 25px 0;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
border: 1px solid #ccc;
margin-left: -1px;
position: relative;
left: 1px;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: 28px;
left: 0;
background: white;
right: 0;
bottom: 0;
padding: 20px;
border: 1px solid #ccc;
}
[type=radio]:checked ~ label {
background: white;
border-bottom: 1px solid white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
}
HTML
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Tab One</label>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dapibus varius urna, ac venenatis arcu convallis consequat. In augue est, posuere auctor facilisis varius, dictum ac risus. Donec nibh justo, aliquam sed tempus quis, lobortis sed orci.
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab Two</label>
<div class="content">
Vivamus id elementum risus. In sit amet mi nulla, ac sollicitudin odio. Phasellus laoreet leo vitae velit lobortis at condimentum odio placerat. Nam sapien eros, accumsan id porttitor a, commodo ut urna. Cras dignissim metus quis enim placerat lobortis.
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">Tab Three</label>
<div class="content">
Phasellus scelerisque luctus ligula, a consequat orci posuere rutrum. Sed ipsum nisi, ullamcorper eget fermentum a, dignissim sed dolor. Mauris viverra pretium ante, eu mollis nisi volutpat quis. Nunc neque erat, pharetra in feugiat eget, faucibus id sem.
</div>
</div>
</div>

If your complete design allows for it, you could assign a fixed height and min-width to the content area. Then you will be able to position the tabs by adding a negative value to their bottom property.
.tab label {
background: #eee;
left: 1px;
margin-left: -1px;
padding: 10px;
position: relative;
/*--- Updated value ---*/
bottom: -149px;
}
...
.content {
background: white;
left: 0;
/*--- Updated values ---*/
bottom: 0;
height: 100px;
min-width: 350px;
/*----*/
padding: 20px;
position: absolute;
right: 0;
top: 0;
}
Check it out here: http://jsbin.com/quceviha/1/

Related

CSS tab system with input radio (no js)

Good evening all,
my name is Erika and I am working on a website.
I have a good understanding of html and css however I got stuck with this problem:
and for this reason I am writing on stackoverflow.
I want to make this tab system work, however I am struggling to understand how I can change the tab when the input radio is :checked.
Here you can find the code and a image of what I am trying of achieve.
I would really appreciate any help.
Thank you very much.
Best reagards
Erika
/* tabs input and label */
.tabs-wrapper {
margin-bottom: 35px;
overflow: hidden;
.tabs {
display: inline-flex;
flex-wrap: wrap;
justify-content: flex-start;
&.tab {
margin-right: 4px;
margin-bottom: 12px;
color: white;
text-align: center;
user-select: none;
&:hover {
cursor: pointer;
}
}
}
}
/* second separate div where the tab-content are */
.product-main-body-wrapper {
.product-body {
width: 100%;
.tab-content {
display: none;
}
}
}
/* make panel tab-content appear */
.tabs-wrapper
.tabs-nav
#tab-1:checked
~ .product-main-body-wrapper
.product-body
#Tab1,
.tabs-wrapper
.tabs-nav
#tab-2:checked
~ .product-main-body-wrapper
.product-body
#Tab2 {
display: block;
}
.radio {
display: none;
}
/* change color of tab label */
#tab-1:checked ~ .tabs #one-tab,
#tab-2:checked ~ .tabs #two-tab {
background: red;
color: white;
}
<div class="tabs-wrapper">
<nav class="tabs-nav">
<input type="radio" class="radio" id="tab-1" name="tab-control" checked>
<input type="radio" class="radio" id="tab-2" name="tab-control">
<div class="tabs">
<label for="tab-1" id="one-tab" class="tab btn-secondary">Tab one</label>
<label for="tab-2" id="two-tab" class="tab btn-secondary">Tab two</label>
</div>
</nav>
</div>
<div class="product-main-body-wrapper">
<div class="product-body">
<div id="Tab1" class="tab-content">
<article>
<p> panel one </p>
</article>
</div>
<div id="Tab2" class="tab-content">
<article> panel two</article>
</div>
</div>
</div>
Have a look at this page.
Code (c) copyright css tricks
<html><head>
<meta charset="UTF-8">
<title>CSS Tabs</title>
<style>
* { margin: 0; padding: 0; }
#page-wrap { width: 960px; margin: 100px auto; }
h1 { font: 36px Georgia, Serif; margin: 20px 0; }
.group:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
p { margin: 0 0 10px 0; }
.tabs { list-style: none; }
.tabs li { display: inline; }
.tabs li a { color: black; float: left; display: block; padding: 4px 10px; margin-left: -1px; position: relative; left: 1px; background: white; text-decoration: none; }
.tabs li a:hover { background: #ccc; }
/* Generic styles & example one */
.tabbed-area { margin: 0 0 120px 0; }
.box-wrap { position: relative; min-height: 250px; }
.tabbed-area div div { background: white; padding: 20px; min-height: 250px; position: absolute; top: -1px; left: 0; width: 100%; }
.tabbed-area div div, .tabs li a { border: 1px solid #ccc; }
#box-one:target, #box-two:target, #box-three:target { z-index: 1; }
/* Stuff for example two */
.cur-nav-fix { margin-top: 60px; }
.cur-nav-fix .tabs { position: absolute; bottom: 100%; left: -1px; }
.cur-nav-fix .tabs li a { background: -moz-linear-gradient(top, white, #eee); }
#box-four { z-index: 1; }
#box-four:target .tabs,
#box-five:target .tabs,
#box-six:target .tabs { z-index: 3; }
#box-four:target, #box-five:target, #box-six:target { z-index: 2; }
.cur-nav-fix .tabs li.cur a { border-bottom: 1px solid white; background: white; }
/* Stuff for example three */
.cur-nav-fix-2 .tabs li a { background: -moz-linear-gradient(top, white, #eee); }
.cur-nav-fix-2 .tabs { z-index: 2; position: relative; }
#box-seven:target .box-seven,
#box-eight:target .box-eight,
#box-nine:target .box-nine { z-index: 1; }
#box-seven:target a[href="#box-seven"],
#box-eight:target a[href="#box-eight"],
#box-nine:target a[href="#box-nine"] { border-bottom: 1px solid white; background: white; }
/* Stuff for example four */
.active-test { padding-top: 40px; }
.active-test .single-tab em { background: white; width: 50px; font-style: normal; position: absolute; bottom: 100%; text-decoration: none; color: black; border: 1px solid #ccc; padding: 5px 10px; }
.active-test .single-tab span { position: absolute; top: -1px; left: 0; width: 100%; display: block; padding: 20px; border: 1px solid #ccc; min-height: 250px; background: white; }
.active-test .single-tab:active em { background: #ccc; }
.active-test .single-tab:active span, .active-test .single-tab:focus span { z-index: 1; }
.tab-ten em { left: 0; }
.tab-eleven em { left: 70px; }
.tab-twelve em { left: 140px; }
/* Stuff for example five */
.adjacent { position: relative; margin-top: 50px; min-height: 300px; }
.adjacent div { border: 1px solid #ccc; background: white; padding: 20px; min-height: 250px; position: absolute; top: -1px; left: 0; width: 100%; }
.adjacent .tabs { position: absolute; bottom: 100%; left: 0; z-index: 2; }
.adjacent .tabs li a { background: -moz-linear-gradient(top, white, #eee); }
#box-thirteen:target,
#box-fourteen:target,
#box-fifteen:target { z-index: 1; }
#box-thirteen:target ~ .tabs a[href='#box-thirteen'],
#box-fourteen:target ~ .tabs a[href='#box-fourteen'],
#box-fifteen:target ~ .tabs a[href='#box-fifteen'] { background: white; border-bottom: 1px solid white; }
/* Stuff for example six */
.w3c { min-height: 250px; position: relative; width: 100%; }
.w3c > div { display: inline; }
.w3c > div > a { margin-left: -1px; position: relative; left: 1px; text-decoration: none; color: black; background: white; display: block; float: left; padding: 5px 10px; border: 1px solid #ccc; border-bottom: 1px solid white; }
.w3c > div:not(:target) > a { border-bottom: 0; background: -moz-linear-gradient(top, white, #eee); }
.w3c > div:target > a { background: white; }
.w3c > div > div { background: white; z-index: -2; left: 0; top: 30px; bottom: 0; right: 0; padding: 20px; border: 1px solid #ccc; }
.w3c > div:not(:target) > div { position: absolute }
.w3c > div:target > div { position: absolute; z-index: -1; }
/* Stuff for example seven - including conditionals below */
#ie-test { position: relative; width: 100%; }
#boxLinks { list-style: none; overflow: hidden; }
#boxLinks li { display: inline; }
#boxLinks li a { padding: 5px 10px; color: black; text-decoration: none; border: 1px solid #ccc; float: left; display: block; margin-left: -1px; position: relative; left: 1px; }
#boxLinks li a:hover { color: #fff; background: #000; }
#box { height: 250px; border: 1px solid #ccc; overflow: hidden; padding: 0px 30px 0px 30px; position: relative; top: -1px; }
.box { display: none; height: 250px; overflow: auto; display: block; position: relative; overflow-x: hidden; }
#box1:target, #box2:target, #box3:target { display: block; }
</style>
<!--[if IE]>
<style type="text/css">
.box { display: block; }
#box { overflow: hidden;position: relative; }
b { position: absolute; top: 0px; right: 0px; width:1px; height: 251px; overflow: hidden; text-indent: -9999px; }
</style>
<![endif]-->
</head>
<body>
<div id="demo-top-bar">
<div id="demo-bar-inside">
<h2 id="demo-bar-badge">
CSS-Tricks Example
</h2>
<div id="demo-bar-buttons">
<a class="header-button" href="/5841-css3-tabs/">← Back to Article</a> </div>
</div>
</div>
<div id="page-wrap">
<div style="width: 420px; float: left;">
<h1>Example One</h1>
<p>Grade: C</p>
<p>From an HTML perspective, this is the absolute cleanest. It just doesn't deal with current
navigation highlighting.</p>
<div class="tabbed-area">
<ul class="tabs group">
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div class="box-wrap">
<div id="box-one">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
</div>
<div id="box-two">
<p>Feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
<div id="box-three">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</div>
</div>
</div>
<h1>Example Three</h1>
<p>Grade: B</p>
<p>This has current navigation highlighting. The only downside is that it requires as
many wrapping divs as there are panels.</p>
<div id="box-seven"><div id="box-eight"><div id="box-nine">
<div class="tabbed-area cur-nav-fix-2">
<ul class="tabs group">
<li>Tab 7</li>
<li>Tab 8</li>
<li>Tab 9</li>
</ul>
<div class="box-wrap">
<div class="box-seven">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
</div>
<div class="box-eight">
<p>Feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
<div class="box-nine">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</div>
</div>
</div>
</div></div></div>
<h1>Example Five</h1>
<p>Grade: B</p>
<p>This is handles current navigation highlighting, with pretty clean HTML. The only downside is
that the list for the tab navigation comes <em>after</em> the panels.</p>
<div class="tabbed-area adjacent">
<div id="box-thirteen">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
</div>
<div id="box-fourteen">
<p>Feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
<div id="box-fifteen">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</div>
<ul class="tabs group">
<li>Tab 13</li>
<li>Tab 14</li>
<li>Tab 15</li>
</ul>
</div>
<h1>Example Seven</h1>
<p>Grade: Depends</p>
<p>This example is the only one that works in IE 7+, so that's big bonus points.</p>
<div id="ie-test">
<ul id="boxLinks" class="group">
<li>Tab 19</li>
<li>Tab 20</li>
<li>Tab 21</li>
</ul>
<div id="box">
<div id="box1" class="box">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
<!--[if IE]><b>.</b><![endif]-->
</div>
<div id="box2" class="box">Another box! <!--[if IE]><b>.</b><![endif]--></div>
<div id="box3" class="box">Woot! <!--[if IE]><b>.</b><![endif]--></div>
</div>
</div>
</div>
<div style="width: 420px; float: right;">
<h1>Example Two</h1>
<p>Grade: D</p>
<p>This fixes the current navigation problem, but requires the menu to be repeated inside
of each panel, which is pretty unacceptable. The hash-links also jump to the panel themselves,
which cuts off the actual tabs if there is enough page scroll below the panels.</p>
<div class="tabbed-area cur-nav-fix">
<div class="box-wrap">
<div id="box-four">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
<ul class="tabs group">
<li class="cur">Tab 4</li>
<li>Tab 5</li>
<li>Tab 6</li>
</ul>
</div>
<div id="box-five">
<p>Feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
<ul class="tabs group">
<li>Tab 4</li>
<li class="cur">Tab 5</li>
<li>Tab 6</li>
</ul>
</div>
<div id="box-six">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
<ul class="tabs group">
<li>Tab 4</li>
<li>Tab 5</li>
<li class="cur">Tab 6</li>
</ul>
</div>
</div>
</div>
<h1>Example Four</h1>
<p>Grade: F</p>
<p>This was an attempt at using the :active and :focus states instead of using :target.
This would have made it even IE 6 compatible. It works as you click, but I haven't been
able to get the link to keep it's focus or active state after the click. Plus, all the
content is inside the anchor link which is sketchy at best.</p>
<div class="tabbed-area active-test">
<div class="box-wrap">
<a class="single-tab tab-ten" href="#box-ten">
<em>Tab 10</em>
<span id="box-ten">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
<li>Vestibulum auctor dapibus neque.</li>
</ul>
</span>
</a>
<a class="single-tab tab-eleven" href="#box-ten">
<em>Tab 11</em>
<span id="box-eleven">
<p>Feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</span>
</a>
<a class="single-tab tab-twelve" href="#box-ten">
<em>Tab 12</em>
<span id="box-twelve">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</span>
</a>
</div>
</div>
<h1>Example Six</h1>
<p>Grade: A</p>
<p>This is the winner so far. It is infinitely expandable (no selectors specific to panels) and the markup is pretty clean.
Possible issues: cross-browser line height issues possibly not making perfect layout, links are placed right above each
div instead of a in central list at the top.</p>
<div class="w3c">
<div id="tab16">
Tab 16
<div>One might well argue, that...</div>
</div>
<div id="tab17">
Tab 17
<div>... 30 lines of CSS is rather a lot, and...</div>
</div>
<div id="tab18">
Tab 18
<div>... that 2 should have been enough, but...</div>
</div>
</div>
</div>
</div>
<style type="text/css" style="display: none !important;">
* {
margin: 0;
padding: 0;
}
body {
overflow-x: hidden;
}
#demo-top-bar {
text-align: left;
background: #222;
position: relative;
zoom: 1;
width: 100% !important;
z-index: 6000;
padding: 20px 0 20px;
}
#demo-bar-inside {
width: 960px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#demo-bar-buttons {
padding-top: 10px;
float: right;
}
#demo-bar-buttons a {
font-size: 12px;
margin-left: 20px;
color: white;
margin: 2px 0;
text-decoration: none;
font: 14px "Lucida Grande", Sans-Serif !important;
}
#demo-bar-buttons a:hover,
#demo-bar-buttons a:focus {
text-decoration: underline;
}
#demo-bar-badge {
display: inline-block;
width: 302px;
padding: 0 !important;
margin: 0 !important;
background-color: transparent !important;
}
#demo-bar-badge a {
display: block;
width: 100%;
height: 38px;
border-radius: 0;
bottom: auto;
margin: 0;
background: url(/images/examples-logo.png) no-repeat;
background-size: 100%;
overflow: hidden;
text-indent: -9999px;
}
#demo-bar-badge:before, #demo-bar-badge:after {
display: none !important;
}
</style>
</body></html>

Multiple CSS collapse/expand in same page

I've CSS collapse/expand code refereed from # https://codepen.io/peternguyen/pen/hICga/ . But the problem with my code is that they won't work in same page. I intended to use it at Wordpress page.
Have a look at my code. Thanks.
input {
display: none;
visibility: hidden;
}
label {
font-weight: bold;
font-size: 15px;
display: block;
color: #666;
text-decoration: underline;
}
label:hover {
color: #000;
}
#expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
color: #000;
}
section {
padding: 0 20px;
}
#toggle:checked ~ #expand {
height: auto;
}
<input id="toggle" type="checkbox">
<label for="toggle">Hidden Kitten</label>
<div id="expand">
<section>
<p>mew</p>
</section>
</div>
<input id="toggle" type="checkbox">
<label for="toggle">Hidden Kitten</label>
<div id="expand">
<section>
<p>mew</p>
</section>
</div>
I made all id-specific parts independent and changed ~ to +.
Working codepen
Code:
#import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: "Open Sans", Arial;
background: #CCC;
}
main {
background: #EEE;
width: 600px;
margin: 20px auto;
padding: 10px 0;
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
}
h2 {
text-align: center;
}
p {
font-size: 13px;
}
input {
display: none;
visibility: hidden;
}
label {
display: block;
padding: 0.5em;
text-align: center;
border-bottom: 1px solid #CCC;
color: #666;
}
label:hover {
color: #000;
}
label::before {
font-family: Consolas, monaco, monospace;
font-weight: bold;
font-size: 15px;
content: "+";
vertical-align: text-top;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 3px;
background: radial-gradient(ellipse at center, #CCC 50%, transparent 50%);
}
.expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
background: url(http://placekitten.com/g/600/300);
color: #FFF;
}
section {
padding: 0 20px;
}
.toggle:checked+label+.expand {
height: 250px;
}
.toggle:checked+label::before {
content: "-";
}
<main>
<h2>CSS Expand/Collapse Section</h2>
<input id="toggle" type="checkbox" checked class="toggle">
<label for="toggle">Hidden Kitten</label>
<div class="expand">
<section>
<p>mew</p>
</section>
</div>
<section>
<h3>Other content</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas porta non turpis faucibus lobortis. Curabitur non eros rutrum, gravida felis non, luctus velit. Ut commodo congue velit feugiat lobortis. Etiam nec dolor quis nulla bibendum blandit
vitae nec enim. Maecenas id dignissim erat. Aenean ac mi nec ante venenatis interdum quis vel lacus.
</p>
<p>Aliquam ligula est, aliquet et semper vitae, elementum eget dolor. In ut dui id leo tristique iaculis eget a dui. Vestibulum cursus, dolor sit amet lacinia feugiat, turpis odio auctor nisi, quis pretium dui elit at est. Pellentesque lacus risus, vulputate
sed gravida eleifend, accumsan ac ante. Donec accumsan, augue eu congue condimentum, erat magna luctus diam, adipiscing bibendum sem sem non elit.</p>
</section>
<input id="toggle2" type="checkbox" checked class="toggle">
<label for="toggle2">Hidden Kitten 2</label>
<section class="expand">
test
</section>
</main>

CSS collapse/expand

I have a pure CSS CSS Expand/Collapse div which is based on someone else's code # here by default hidden text is collapsable but it would be better if the text expands after the click.
Anyone have suggestions on how to edit this code so that text is minimize before the click is minimized? It would be better if javascript is avoided and Wordpress compactible.
<main>
<h2>CSS Expand/Collapse Section</h2>
<input id="toggle" type="checkbox" checked>
<label for="toggle">Hidden Kitten</label>
<div id="expand">
<section>
<p>mew</p>
</section>
</div>
<section>
<h3>Other content</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas porta non turpis faucibus lobortis. Curabitur non eros rutrum, gravida felis non, luctus velit. Ut commodo congue velit feugiat lobortis. Etiam nec dolor quis nulla bibendum blandit vitae nec enim. Maecenas id dignissim erat. Aenean ac mi nec ante venenatis interdum quis vel lacus.
</p>
<p>Aliquam ligula est, aliquet et semper vitae, elementum eget dolor. In ut dui id leo tristique iaculis eget a dui. Vestibulum cursus, dolor sit amet lacinia feugiat, turpis odio auctor nisi, quis pretium dui elit at est. Pellentesque lacus risus, vulputate sed gravida eleifend, accumsan ac ante. Donec accumsan, augue eu congue condimentum, erat magna luctus diam, adipiscing bibendum sem sem non elit.</p>
</section>
</main>
CSS
#import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: "Open Sans", Arial;
background: #CCC;
}
main {
background: #EEE;
width: 600px;
margin: 20px auto;
padding: 10px 0;
box-shadow: 0 3px 5px rgba(0,0,0,0.3);
}
h2 {
text-align: center;
}
p {
font-size: 13px;
}
input {
display: none;
visibility: hidden;
}
label {
display: block;
padding: 0.5em;
text-align: center;
border-bottom: 1px solid #CCC;
color: #666;
}
label:hover {
color: #000;
}
label::before {
font-family: Consolas, monaco, monospace;
font-weight: bold;
font-size: 15px;
content: "+";
vertical-align: text-top;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 3px;
background: radial-gradient(ellipse at center, #CCC 50%, transparent 50%);
}
#expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
background: url(http://placekitten.com/g/600/300);
color: #FFF;
}
section {
padding: 0 20px;
}
#toggle:checked ~ #expand {
height: 250px;
}
#toggle:checked ~ label::before {
content: "-";
}
I think you are looking to have the image start collapsed.
All you need to do is remove the checked attribute from the input checkbox to achieve this.
Change:
<input id="toggle" type="checkbox" checked>
To:
<input id="toggle" type="checkbox">
Here is you code in a runable snippet:
body {
font-family: "Open Sans", Arial;
background: #CCC;
}
main {
background: #EEE;
width: 600px;
margin: 20px auto;
padding: 10px 0;
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
}
h2 {
text-align: center;
}
p {
font-size: 13px;
}
input {
display: none;
visibility: hidden;
}
label {
display: block;
padding: 0.5em;
text-align: center;
border-bottom: 1px solid #CCC;
color: #666;
}
label:hover {
color: #000;
}
label::before {
font-family: Consolas, monaco, monospace;
font-weight: bold;
font-size: 15px;
content: "+";
vertical-align: text-top;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 3px;
background: radial-gradient(ellipse at center, #CCC 50%, transparent 50%);
}
#expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
background: url(http://placekitten.com/g/600/300);
color: #FFF;
}
section {
padding: 0 20px;
}
#toggle:checked~#expand {
height: 250px;
}
#toggle:checked~label::before {
content: "-";
}
<main>
<h2>CSS Expand/Collapse Section</h2>
<input id="toggle" type="checkbox">
<label for="toggle">Hidden Kitten</label>
<div id="expand">
<section>
<p>mew</p>
</section>
</div>
<section>
<h3>Other content</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas porta non turpis faucibus lobortis. Curabitur non eros rutrum, gravida felis non, luctus velit. Ut commodo congue velit feugiat lobortis. Etiam nec dolor quis nulla bibendum blandit
vitae nec enim. Maecenas id dignissim erat. Aenean ac mi nec ante venenatis interdum quis vel lacus.
</p>
<p>Aliquam ligula est, aliquet et semper vitae, elementum eget dolor. In ut dui id leo tristique iaculis eget a dui. Vestibulum cursus, dolor sit amet lacinia feugiat, turpis odio auctor nisi, quis pretium dui elit at est. Pellentesque lacus risus, vulputate
sed gravida eleifend, accumsan ac ante. Donec accumsan, augue eu congue condimentum, erat magna luctus diam, adipiscing bibendum sem sem non elit.</p>
</section>
</main>
Just remove checked in your input and you're good to go.
It should look like this:
<input id="toggle" type="checkbox">

Timeline spacing issue with pseudo background

I have a baseline line-height which i dont want to amend for this part of the site, but as you can see on the examples below, there are spaces between each element.
What i want to achieve?
I want the line that is aligned vertically
p {
margin: 0;
padding: 0;
}
.view-timeline-block {
padding: 0 5em;
line-height: 28px;
}
.view-timeline-block .ml-container {
padding-left: 25px;
}
.view-timeline-block .line {
position: relative;
}
.view-timeline-block .line:after {
content: '';
position: absolute;
left: -19px;
top: 0;
width: 5px;
height: 100%;
background: black;
}
.view-timeline-block .active {
position: relative;
}
.view-timeline-block .active:after {
content: '';
position: absolute;
left: -25px;
top: 5px;
width: 7px;
height: 7px;
border-radius: 50%;
background: transparent;
border: 5px solid black;
}
.view-timeline-block .active-small {
position: relative;
}
.view-timeline-block .active-small:after {
content: '';
position: absolute;
left: -22px;
top: 5px;
width: 10px;
height: 10px;
border-radius: 50%;
background: black;
}
<div class="view-timeline-block">
<div class="main-listing">
<div class="title active">Testing name</div>
<div class="content line">
<p>testing name content</p>
</div>
<div class="sub_name active-small">asdasdasdasd</div>
<div class="sub_content line">
<p>testing sub name content</p>
</div>
</div>
<div class="main-listing">
<div class="title active">Timeline 2 name</div>
<div class="content line">
<p>timeline 2 content</p>
</div>
<div class="sub_name active-small">Timeline 2 sub name</div>
<div class="sub_content ">
<p>timeline 2 sub content</p>
</div>
</div>
</div>
needs to meet. Would anyone know how to accomplish this?
Did some slight modifications - maybe you can give it a try.
I changed the lines positions. To avoid them overlapping the circles, I added a background to those circles and gave them a higher z-index.
Last but not least, I changed the circles / dots size to make them more centered.
p {
margin: 0;
padding: 0;
}
.view-timeline-block {
padding: 0 5em;
line-height: 28px;
}
.view-timeline-block .ml-container {
padding-left: 25px;
}
.view-timeline-block .line {
position: relative;
}
.view-timeline-block .line:after {
background: black none repeat scroll 0 0;
content: "";
height: -webkit-calc(100% + 25px);
height: -moz-calc(100% + 25px);
height: -o-calc(100% + 25px);
left: -19px;
position: absolute;
top: -15px;
width: 5px;
}
.view-timeline-block .active {
position: relative;
}
.view-timeline-block .active:after {
background-color: white;
border: 5px solid black;
border-radius: 50%;
content: "";
height: 8px;
left: -25px;
position: absolute;
top: 6px;
width: 8px;
z-index: 100;
}
.view-timeline-block .active-small {
position: relative;
}
.view-timeline-block .active-small:after {
background: black none repeat scroll 0 0;
border-radius: 50%;
content: "";
height: 12px;
left: -23px;
position: absolute;
top: 9px;
width: 12px;
z-index: 150;
}
<div class="view-timeline-block">
<div class="main-listing">
<div class="title active">Testing name</div>
<div class="content line">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu quam facilisis, sagittis diam sit amet, consectetur est. Donec ac dolor augue. Vestibulum efficitur ante at tempor ultricies. Nullam pharetra vel arcu condimentum posuere. Cras auctor
pulvinar mattis. Quisque pulvinar eget risus non sagittis. Duis lorem sapien, rhoncus sed turpis dictum, accumsan scelerisque justo. Nullam nec turpis sit amet magna mattis gravida ut ut magna. Sed pharetra lacus eros, ac vulputate tellus rutrum
facilisis. Fusce nec justo dictum, lobortis ipsum ultricies, dapibus tellus. Vestibulum nulla nibh, pretium in semper ut, luctus molestie mi.</p>
</div>
<div class="sub_name active-small">asdasdasdasd</div>
<div class="sub_content line">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu quam facilisis, sagittis diam sit amet, consectetur est. Donec ac dolor augue. Vestibulum efficitur ante at tempor ultricies. Nullam pharetra vel arcu condimentum posuere. Cras auctor
pulvinar mattis. Quisque pulvinar eget risus non sagittis. Duis lorem sapien, rhoncus sed turpis dictum, accumsan scelerisque justo. Nullam nec turpis sit amet magna mattis gravida ut ut magna. Sed pharetra lacus eros, ac vulputate tellus rutrum
facilisis. Fusce nec justo dictum, lobortis ipsum ultricies, dapibus tellus. Vestibulum nulla nibh, pretium in semper ut, luctus molestie mi.
</p>
</div>
</div>
<div class="main-listing">
<div class="title active">Timeline 2 name</div>
<div class="content line">
<p>timeline 2 content</p>
</div>
<div class="sub_name active-small">Timeline 2 sub name</div>
<div class="sub_content ">
<p>timeline 2 sub content</p>
</div>
</div>
</div>
Update: I replaced the height: 200% by height:-webkit-calc(100% + 25px); and some other browser-specific height-calculations. Should work in all modern browsers.

Align Buttons In Div To Bottom

I have a main div with CSS:
.border {
border-radius: 25px;
border: 8px solid #2C3E50;
padding: 50px;
width: 500px;
height: 500px;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
And two buttons, side by side, inside the div, with CSS to make it animate on hover/press. How would I make the buttons to be at the bottom of the div, no matter of what the content is in the div? Position: absolute, doesn't work for me.
Try position: absolute or relative and then alter the bottom and right properties.
Also, have you checked to make sure that no other styles are overwriting your preferred styles? Chrome's developer tools are an awesome way to find this out.
For html:
<div id="wrapper">
<button></button>
</div>
You can apply style:
#wrapper {
position: relative;
}
#wrapper > button {
position: absolute;
bottom: 0;
}
To place the <button> element at the bottom of the wrapper <div>. Take note that you must declare position: relative or position: absolute on the containing element ( the wrapper ) for position: absolute to place a child element (the button) with respect to its bottom.
Try this
.border {
border-radius: 25px;
border: 8px solid #2C3E50;
padding: 50px;
width: 500px;
height: 500px;
margin: 0 auto;
position: relative;
}
.inner-border-normal {
float: left;
}
.inner-border-bottom {
position: absolute;
bottom: 50px;
}
.button {
width: 100px;
height: 32px;
border: 1px solid #CCCCCC;
border-radius: 4px;
background: #F2F2F2;
cursor: pointer;
}
<div class="border">
<div class="inner-border-normal">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id erat interdum ex dapibus sodales nec id nibh. Sed egestas bibendum erat quis ultricies. Ut auctor iaculis odio quis tempor. In maximus nisi et ex consectetur scelerisque. Nam et nunc sit amet massa faucibus commodo. Etiam at tortor nisl. Integer at justo sit amet ex ornare rutrum a sed felis. Mauris eu risus dolor. Curabitur non ullamcorper lacus. Curabitur ultricies aliquet ex, non maximus erat convallis eget. Nulla pretium ex quis commodo tempus. Nunc non vestibulum neque, vitae venenatis lorem. Nunc eget maximus ante. Sed aliquam ac arcu sed pharetra.</div>
<div class="inner-border-bottom">
<input type="button" class="button" value="Press">
<input type="button" class="button" value="Press">
</div>
</div>