I am using a slightly modified version of this: https://codepen.io/ferry/pen/ZYVwxz (Thank you Michael Ferry).
HTML:
<div class="accordion">
<ul>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="0">
<div>
<a href="#">
<h2>Lorem Ipsum 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
</ul>
</div>
CSS:
<style>
.accordion {
width: 100%;
max-width: 1140px;
height: 560px;
overflow: hidden;
margin: 20px auto;
}
.accordion ul {
width: 100%;
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
}
.accordion ul li {
list-style-type: none;
display: table-cell;
top:0px;
vertical-align: top;
position: relative;
width: 16.666%;
height: 520px;
background-repeat: no-repeat;
background-position: top center;
transition: all 500ms ease;
}
.accordion ul li div {
display: block;
overflow: hidden;
width: 100%;
}
.accordion ul li div a {
display: block;
height: 520px;
width: 100%;
position: relative;
z-index: 3;
vertical-align: bottom;
padding: 0px;
box-sizing: border-box;
color: #fff;
text-decoration: none;
transition: all 200ms ease;
}
.accordion ul li div a * {
opacity: 0;
margin: 0;
width: 100%;
text-overflow: ellipsis;
position: relative;
z-index: 5;
white-space: nowrap;
overflow: hidden;
-webkit-transform: translateX(-20px);
transform: translateX(-20px);
-webkit-transition: all 400ms ease;
transition: all 400ms ease;
}
.accordion ul li div a h2 {
text-overflow: clip;
font-size: 24px;
/*text-transform: uppercase;*/
margin-bottom: 0px;
top: 435px;
color:#000;
}
.accordion ul li div a p {
top: 440px;
font-size: 13.5px;
color:#000;
}
.accordion ul li:nth-child(1) {
background-image: url("1b.jpg");max-height:400px;
}
.accordion ul li:nth-child(2) {
background-image: url("2b.jpg");max-height:400px;
}
.accordion ul li:nth-child(3) {
background-image: url("3b.jpg");max-height:400px;
}
.accordion ul li:nth-child(4) {
background-image: url("4b.jpg");max-height:400px;
}
.accordion ul li:nth-child(5) {
background-image: url("5b.jpg");max-height:400px;
}
.accordion ul li:nth-child(6) {
background-image: url("6b.jpg");max-height:400px;
}
.accordion ul:hover li {
width: 16%;
}
.accordion ul:hover li:hover {
width: 100%;
}
.accordion ul:hover li:hover a {
}
.accordion ul:hover li:hover a * {
opacity: 1;
-webkit-transform: translateX(0);
transform: translateX(0);
}
#media screen and (max-width: 600px) {
body {
margin: 0;
}
.accordion {
height: auto;
}
.accordion ul li, .accordion ul li:hover, .accordion ul:hover li, .accordion ul:hover li:hover {
position: relative;
display: table;
table-layout: fixed;
width: 100%;
-webkit-transition: none;
transition: none;
}
}
</style>
I can't get it to display the "slide" when using the keyboard.
I have tried adding .active, :focus, role="button", aria-expanded="true" and tab-index to no avail.
Before I go bald, does anyone have a solution? (without using javascript)
Thanks so much!
If you use tabindex="1" on your li like <li tabindex="1">, you should be able to target them with :focus as
li {
&:focus {
// your stuff here
}
}
Right now what happened is when you press tab it selects the a element but the transformation is applied on the li.
If I take the code from Michael Ferry's code pen you will have the following lines.
HTML:
<h1>Responsive Accordion</h1>
<div class="accordion">
<ul>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
</ul>
</div>
<p class="about">
By Michael Ferry
</p>
<h1>Responsive Accordion</h1>
<div class="accordion">
<ul>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
<li tabindex="1">
<div>
<a href="#">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</a>
</div>
</li>
</ul>
</div>
<p class="about">
By Michael Ferry
</p>
SCSS:
#import url(https://fonts.googleapis.com/css?family=Open+Sans);
#import url(https://fonts.googleapis.com/css?family=Montserrat:700);
// Accordion Height
$a-height: 250px;
// Position text along bottom
$text-offset: $a-height - 90;
// Page Title
h1 {
text-align: center;
font-family: Montserrat, sans-serif;
color: #333;
}
.accordion {
width: 100%;
max-width: 1080px;
height: $a-height;
overflow: hidden;
margin: 50px auto;
ul {
width: 100%;
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
li {
display: table-cell;
vertical-align: bottom;
position: relative;
width: 16.666%; // 6 into 100
height: $a-height;
background-repeat: no-repeat;
background-position: center center;
transition: all 500ms ease;
div {
display: block;
overflow: hidden;
width: 100%;
a {
display: block;
height: $a-height;
width: 100%;
position: relative;
z-index: 3;
vertical-align: bottom;
padding: 15px 20px;
box-sizing: border-box;
color: #fff;
text-decoration: none;
font-family: Open Sans, sans-serif;
transition: all 200ms ease;
* {
opacity: 0;
margin: 0;
width: 100%;
text-overflow: ellipsis;
position: relative;
z-index: 5;
white-space: nowrap;
overflow: hidden;
-webkit-transform: translateX(-20px);
transform: translateX(-20px);
-webkit-transition: all 400ms ease;
transition: all 400ms ease;
}
h2 {
font-family: Montserrat, sans-serif;
text-overflow: clip;
font-size: 24px;
text-transform: uppercase;
margin-bottom: 2px;
top: $text-offset;
}
p {
top: $text-offset;
font-size: 13.5px;
}
}
}
}
// Background images
li:nth-child(1) {
background-image: url("http://michael-ferry.com/assets/accordion1.jpg");
}
li:nth-child(2) {
background-image: url("http://michael-ferry.com/assets/accordion2.jpg");
}
li:nth-child(3) {
background-image: url("http://michael-ferry.com/assets/accordion3.jpg");
}
li:nth-child(4) {
background-image: url("http://michael-ferry.com/assets/accordion4.jpg");
}
li:nth-child(5) {
background-image: url("http://michael-ferry.com/assets/accordion5.jpg");
}
li:nth-child(6) {
background-image: url("http://michael-ferry.com/assets/accordion6.jpg");
}
&:hover li,
li:focus ~ li{
width: 8%;
}
&:hover li:hover,
li:focus {
width: 60%;
a {
background: rgba(0, 0, 0, 0.4);
* {
opacity: 1;
-webkit-transform: translateX(0);
transform: translateX(0);
}
}
}
}
}
// Stack items
#media screen and (max-width: 600px) {
// IE gets fussy if this isn't here
body {
margin: 0;
}
.accordion {
height: auto;
ul,
ul:hover {
li,
li:hover {
position: relative;
display: table;
table-layout: fixed;
width: 100%;
-webkit-transition: none;
transition: none;
}
}
}
}
.about {
text-align: center;
font-family: "Open Sans", sans-serif;
font-size: 12px;
color: #666;
a {
color: blue;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
In the SCSS code I have added li:focus ~ li to target li's siblings and li:focus to the existing code to reproduce the animation.
I also recommend you to disable a element tabbing with tabindex=0 in order to avoid the user to scroll top again after tabbing through the slider.
Focus within fix this issue, and works fine
:hover, :focus-within {
your css
}
you can check MDN to learn more about focus-within
Related
I am trying to create a scrollable horizontal timeline with a fixed width. I have overflow-x: auto on the parent container and whenever I add white-space: nowrap to that same element, the child list elements start getting cut off. I assume this is something to do with the behavior of flex-box. I have tried adding min-width: 0 to the flex elements and flex-grow: 1 but no luck.
body {
font-family: Arial, Helvetica, sans-serif;
}
.container {
height: 200px;
width: 500px;
margin: 0 auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}
.timeline {
display: flex;
justify-content: center;
min-width: 0;
}
.timeline ol {
list-style: none;
display: flex;
justify-content: center;
}
.timeline .horizontal-line {
position: relative;
background-color: #0d6a3d;
height: 3px;
border-radius: 4px;
margin: 5em 0;
}
.event {
margin: 0px 10px;
position: relative;
}
.date {
position: relative;
text-align: center;
top: -70px;
width: 100%;
}
.date::after {
content: "";
position: absolute;
bottom: -28px;
left: 50%;
right: auto;
height: 20px;
width: 20px;
border-radius: 50%;
border: 3px solid #00a950;
background-color: #fff;
transition: 0.3s ease;
transform: translateX(-50%);
}
.content {
width: 100%;
text-align: center;
position: relative;
top: -45px;
}
<section class="container">
<div class="timeline">
<div class="horizontal-line">
<ol>
<li class="event">
<h3 class="date">07/02/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
</ol>
</div>
</div>
</section>
Add width: fit-content; to your timeline. That gets all elements to fit in the horizontal scroll. Then you are left with the default padding-inline-start on the ol. You can remove that gap by setting padding: 0; or padding-inline-start: 0;.
body {
font-family: Arial, Helvetica, sans-serif;
}
.container {
height: 200px;
width: 500px;
margin: 0 auto;
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
}
.timeline {
display: flex;
justify-content: center;
min-width: 0;
width: fit-content;
}
.timeline ol {
list-style: none;
display: flex;
justify-content: center;
padding: 0;
}
.timeline .horizontal-line {
position: relative;
background-color: #0d6a3d;
height: 3px;
border-radius: 4px;
margin: 5em 0;
}
.event {
margin: 0px 10px;
position: relative;
}
.date {
position: relative;
text-align: center;
top: -70px;
width: 100%;
}
.date::after {
content: "";
position: absolute;
bottom: -28px;
left: 50%;
right: auto;
height: 20px;
width: 20px;
border-radius: 50%;
border: 3px solid #00a950;
background-color: #fff;
transition: 0.3s ease;
transform: translateX(-50%);
}
.content {
width: 100%;
text-align: center;
position: relative;
top: -45px;
}
<section class="container">
<div class="timeline">
<div class="horizontal-line">
<ol>
<li class="event">
<h3 class="date">07/02/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
<li class="event">
<h3 class="date">08/25/2020</h3>
<p class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</li>
</ol>
</div>
</div>
</section>
Can anyone kindly help me out with my css+html issue? Please refer the code snippet I have added.
What I need to achive,
1. The boxes(.box) with images to stay fixed
2. The hidden description (.hidden) to go over the below image box when hovered without moving it
Can someone please help me figuring this out?
.box {
width: 170px;
transition: all .4s ease;
border-bottom: 10px solid #fff;
color:#000 !important;
}
#caption {
width: 160px;
font-size:15px;
text-decoration:none;
margin: 0 0 0px 5px;
}
.boximg{
width: auto;
max-width: 100%;
margin-bottom: 8px;
}
.box:hover {
width: auto;
max-width: 170px;
border-bottom: 10px solid #000;
transition: all .4s ease;
color:#ccdc29 !important;
background-color:#000;
}
.box:hover > #hidden {
display:block;
transition: all .3s ease;
overflow-x: hidden;
}
#hidden {
display:none;
color:#fff;
margin:5px;
transition: all .3s ease;
}
.image_off, #home:hover .image_on{
display:none;
transition: all .4s ease;
}
.image_on, #home:hover .image_off{
display:block;
transition: all .4s ease;
}
<div class="box">
<a href="#">
<img width="170px" class="image_on" src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" /><img width="170px" class="image_off" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSH5rO0Te6nVxuBwuR352PJIKb6MeV-PDBKnVm4DBpwvd-8DPAJ" />
<br>
</a>
<p id="caption">Lorem Ipsum</p>
<p id="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin condimentum, nisi vel cursus consectetur, 7</p>
</div>
<div class="box">
<a href="#">
<img width="170px" class="image_on" src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" /><img width="170px" class="image_off" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSH5rO0Te6nVxuBwuR352PJIKb6MeV-PDBKnVm4DBpwvd-8DPAJ" />
<br>
</a>
<p id="caption">Lorem Ipsum</p>
<p id="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin condimentum, nisi vel cursus consectetur</p>
</div>
Thanks heaps!
Try the following. I have fixed your nested anchors, removed some duplicate ids and positioned the caption absolutely. The only thing I would say is the caption has an 18px minus margin - not sure what creates that gap for the margin to be needed
Also if you want to stop the blinking effect, you need to use the same size images - your hover one is slightly larger
.box {
width: 170px;
transition: all .4s ease;
color: #000 !important;
position:relative;
padding:0;
margin-bottom:10px;
}
.box > a
.box span,
.box img {
display:block;
}
#caption {
width: 160px;
font-size: 15px;
text-decoration: none;
margin: 0 0 0px 5px;
}
.boximg {
width: auto;
max-width: 100%;
}
.box:hover {
width: auto;
max-width: 170px;
transition: all .4s ease;
color: #ccdc29 !important;
z-index:2;
}
.box:hover>#caption {
display:none;
}
.box:hover>#hidden {
display: block;
transition: all .3s ease;
background-color: #000;
}
#hidden {
display: none;
color: #fff;
transition: all .3s ease;
position:absolute;
left:0;
right:0;
top:100%;
padding:5px;
margin:-18px 0 0 0;
}
.box .image_off,
#home:hover .image_on {
display: none;
transition: all .4s ease;
}
.box .image_on,
#home:hover .image_off {
display: block;
transition: all .4s ease;
}
<div class="box">
<a href="#">
<span class="boximg" id="home"><img width="170px" class="image_on" src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" /><img width="170px" class="image_off" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSH5rO0Te6nVxuBwuR352PJIKb6MeV-PDBKnVm4DBpwvd-8DPAJ"
/></span>
<br>
</a>
<p id="caption">Lorem Ipsum</p>
<p id="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin condimentum, nisi vel cursus consectetur, 7</p>
</div>
<div class="box">
<a href="#">
<span class="boximg" id="home1"><img width="170px" class="image_on" src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" /><img width="170px" class="image_off" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSH5rO0Te6nVxuBwuR352PJIKb6MeV-PDBKnVm4DBpwvd-8DPAJ"
/></span>
<br>
</a>
<p id="caption">Lorem Ipsum</p>
<p id="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin condimentum, nisi vel cursus consectetur</p>
</div>
.img-with-text{
position: relative;
width: 170px;
}
.img-with-text > div{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0);
color: transparent;
transition: 1s;
}
.img-with-text > div:hover{
background-color: rgba(0, 0, 0, 0.6);
color: white;
}
<div class="img-with-text">
<img src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" alt="image" width="170">
<div><h2>Hello!</h2></div>
</div>
<div class="img-with-text">
<img src="http://kittenrescue.org/wp-content/uploads/2017/03/KittenRescue_KittenCareHandbook.jpg" alt="image" width="170">
<div><h2>Hello!</h2></div>
</div>
I'm experimenting with a tabbed navigation made of radio buttons.
My problem is that when I click on the tab the selected id's opacity isn't change so the content doesn't get visible.
My HTML code:
<div id="container">
<div id="tabs">
<input id="tab-1" type="radio" name="tab-group" checked="checked" />
<label for="tab-1">Tab 1</label>
<input id="tab-2" type="radio" name="tab-group" />
<label for="tab-2">Tab 2</label>
<input id="tab-3" type="radio" name="tab-group" />
<label for="tab-3">Tab 3</label>
</div>
<div id="content">
<div id="content-1">
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
</div>
<div id="content-2">
<p class="column-left"><img src="http://ximg.es/200x150" alt="">Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
<p class="column-right"><img src="http://ximg.es/200x150" alt="">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div id="content-3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing it.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing it.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
</ul>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
My CSS code:
* {
font-family: Arial, sans;
margin: 0;
padding: 0;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
#container {
padding-top: 6em;
margin: 0 auto;
width: 50%;
}
#tabs input {
height: 2.5em;
visibility: hidden;
}
#tabs label {
background: #f9f9f9;
border-radius: .25em .25em 0 0;
color: red;
cursor: pointer;
display: block;
float: left;
font-size: 1em;
height: 2.5em;
line-height: 2.5em;
margin-right: .25em; /*space between tabs*/
padding: 0 1.5em;
text-align: center;
}
#tabs input:hover + label {
background: #ddd;
color: lawngreen;
}
#tabs input:checked + label {
background: black;
color: white;
position: relative;
z-index: 6;
}
#content {
background: red;
border-radius: 0 .25em .25em .25em;
min-height: 20em;
position: relative;
width: 100%;
z-index: 5;
}
#content div {
opacity: 0;
padding: 1.5em;
position: absolute;
z-index: -100;
transition: all linear 0.1s;
}
#tabs input#tab-1:checked ~ #content #content-1,
#tabs input#tab-2:checked ~ #content #content-2,
#tabs input#tab-3:checked ~ #content #content-3 {
opacity: 1;
z-index: 100;
}
input.visible {
visibility: visible !important;
}
I think the problem lies with the 3 selector lines "#tabs input#tab-1:checked ~ #content #content-1"
I've tried to rewrite these line in different syntax bu nothing works.
Please help.
The div that matches #content is not a sibling of any of the inputs. It is a sibling of their parent.
My aunt is not my sister.
You can't draw a link from the inputs to #content-X with CSS selectors. There is no parent combinator.
You would need to use JavaScript for this.
* {
font-family: Arial, sans;
margin: 0;
padding: 0;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
#container {
padding-top: 6em;
margin: 0 auto;
width: 50%;
}
#tabs input {
height: 2.5em;
visibility: hidden;
}
#tabs label {
background: #f9f9f9;
border-radius: .25em .25em 0 0;
color: red;
cursor: pointer;
display: block;
float: left;
font-size: 1em;
height: 2.5em;
line-height: 2.5em;
margin-right: .25em; /*space between tabs*/
padding: 0 1.5em;
text-align: center;
}
#tabs input:hover + label {
background: #ddd;
color: lawngreen;
}
#tabs input:checked + label {
background: black;
color: white;
position: relative;
z-index: 6;
}
#content {
background: red;
border-radius: 0 .25em .25em .25em;
min-height: 20em;
position: relative;
width: 100%;
z-index: 5;
overflow-y: auto;
}
#content div {
opacity: 0;
padding: 1.5em;
position: absolute;
z-index: -100;
transition: all linear 0.1s;
}
#tabs input#tab-1:checked ~ #content div#content-1,
#tabs input#tab-2:checked ~ #content div#content-2,
#tabs input#tab-3:checked ~ #content div#content-3 {
opacity: 1;
z-index: 1000;
}
input.visible {
visibility: visible !important;
}
<div id="container">
<div id="tabs">
<input id="tab-1" type="radio" name="tab-group" checked="checked" />
<label for="tab-1">Tab 1</label>
<input id="tab-2" type="radio" name="tab-group" />
<label for="tab-2">Tab 2</label>
<input id="tab-3" type="radio" name="tab-group" />
<label for="tab-3">Tab 3</label>
<div id="content">
<div id="content-1">
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
</div>
<div id="content-2">
<p class="column-left"><img src="http://ximg.es/200x150" alt="">Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
<p class="column-right"><img src="http://ximg.es/200x150" alt="">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div id="content-3">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing it.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing it.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
</ul>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
</div>
You can if you slightly change your html.
Basically, to make #content siblings #tabs, I moved #tabs closing div to the end. Hope this helps.
Check the fiddle here
I want to display text at the center of my 4 images. No matter what I do it doesn't display at all or display on the top of the page.
Somebody, please help me!
By the way, does anybody know how to make banner-text always stay the same (the same as at 100%) when zooming?
UPD: https://jsfiddle.net/5no1pjt2/4/
/* quick reset */
* {
margin: 0;
padding: 0;
border: 0;
}
#banner {
position: relative;
width: 100%;
}
#banner img {
width: 100%;
height: 100%;
float: left; /* no line after <img> */
}
#banner-text {
position: absolute;
margin: 250px 120px;
font-size: 42px;
color: #ffffff;
/* background: rgba(0, 0, 0, 0.5); */
}
#banner-text p {
width: 800px;
/* font-family: Palanquin Regular; */
font-size: 24px;
line-height: 24px;
}
#img__wrap img {
width: 50%;
height: auto;
/* display: inline-block; */
float: left; /* no line after <img> */
/* transition */
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
#img__wrap img:hover {
/* filters for animation */
-webkit-filter: brightness(70%);
-moz-filter: brightness(70%);
-o-filter: brightness(70%);
-ms-filter: brightness(70%);
filter: brightness(70%);
}
/* relevant styles */
#img__wrap {
position: relative;
}
.img__description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: visible;
opacity: 0;
}
#img__wrap:hover .img__description {
visibility: visible;
opacity: 1;
}
<div id="banner">
<img src="http://placehold.it/1920x1080"/>
<div id="banner-text">
<h1>Lorem ipsum dolor sit amet</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis ultrices tellus, at vulputate risus.Cras convallis molestie libero, ac fringilla lacus lobortis ut.
</p>
</div>
</div>
<div id="img__wrap">
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
The key is to create a wrapper to hold your image and text. Then add position relative to that wrapper. And then to the text inside it, add top 50% and then lift it half of its height by adding transform translateY(-50%).
If you want the same for X axis, use left 50% and translateX(-50%).
/* quick reset */
* {
margin: 0;
padding: 0;
border: 0;
}
#banner {
position: relative;
width: 100%;
}
#banner img {
width: 100%;
height: 100%;
float: left; /* no line after <img> */
}
#banner-text {
position: absolute;
margin: 250px 120px;
font-size: 42px;
color: #ffffff;
/* background: rgba(0, 0, 0, 0.5); */
}
#banner-text p {
width: 800px;
/* font-family: Palanquin Regular; */
font-size: 24px;
line-height: 24px;
}
#img__wrap img {
width: 100%;
height: auto;
/* display: inline-block; */
float: left; /* no line after <img> */
/* transition */
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
#img__wrap img:hover {
/* filters for animation */
-webkit-filter: brightness(70%);
-moz-filter: brightness(70%);
-o-filter: brightness(70%);
-ms-filter: brightness(70%);
filter: brightness(70%);
}
/* relevant styles */
.img__wrap {
position: relative;
height: 200px;
width: 257px;
}
.img__description {
position: absolute;
top: 50%;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
height: 40px;
transform: translateY(-50%);
text-align: center;
}
.img__wrap:hover .img__description {
visibility: visible;
opacity: 1;
}
.image-wrap {
position: relative;
width: 50%;
float: left;
}
<div id="banner">
<img src="http://placehold.it/1920x1080"/>
<div id="banner-text">
<h1>Lorem ipsum dolor sit amet</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis ultrices tellus, at vulputate risus.Cras convallis molestie libero, ac fringilla lacus lobortis ut.
</p>
</div>
</div>
<div id="img__wrap">
<div class="image-wrap">
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="image-wrap">
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="image-wrap">
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="image-wrap">
<img class="img__img" src="http://placehold.it/952x512"/>
<p class="img__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
To make the banner text central in the banner you could try:
#banner-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 42px;
color: #ffffff;
}
Its worth noting that the transform won't work on older versions of IE.
I want to display text at the center of my 4 images.
No matter what I do it doesn't display at all or display
on the top of the page.
You have two problems:
The "absolute" position declaration for the "img__description". The absolute position rule you have used on the text (<p class="img__description">...</p>) places all 4 texts in the upper left hand corner of the page. Declare a relative position for the text, and then give the text something to be relative to. (See next point).
Structure: No relation exists between each img and text pair There is currently no container or relationship tying any of the text elements (<p class="img__description">...</p>) to any of your 4 images: <img class="img__img" src="..." />.
It will be difficult to position the text relative to the appropriate image without a wrapper. Consider either:
moving the image inside each paragraph, and moving your positioning and sizing rules to the paragraph, which will act like a wrapper;
or add a <div> around each image and text pair, and subsequently move your positioning and sizing rules to the new <div> wrapper
Either of these wrapper options will also constrain the height and width of the text, which you also need.
i have been messing with CSS but cant get desired results.
I made simple list with url & thumbnails in html and styled it with CSS.
I cant get list into center of page. I want it to be even from both sides, but its more on the right side of page.
Can someone help me with this issue please.
CSS
body {
background-color: #151924;
}
ul#playlist
{
text-align: center;
}
ul#playlist li
{
display:block;
list-style: none;
background: #323B55;
border: 1px solid #b2b2b2;
max-width: 100%;
margin-top: 5px
}
ul#playlist li img
{
float: left;
margin: 15px 15px 15px 15px;
}
ul#playlist h3
{
font: bold 20px/1.5 Helvetica, Verdana, sans-serif;
}
ul#playlist li a
{
font-weight: bold;
line-height: 2.8em;
margin-left: 50px;
color: #b2b2b2
}
<title>Playlist test</title>
<body> <ul style="list-style-type:none" id="playlist">
<li><a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
<li> <a href="http://hls01-09.az.myvideo.az/hls-live/livepkgr/foxturk/foxturk/foxturk.m3u8?mfamwuUL6IpOXDJ8WwxJ">
<img src="https://c1.staticflickr.com/3/2790/5864018592_65d4a0a298.jpg">
<h3>Star TV</h3>
<p>Lorem ipsum dolor sit amet...</p></a></li>
</ul> </body>
http://jsfiddle.net/7yos5231/
#playlist ul inherit 50px left padding (available for the hidden li bullets).
You have to reset it #playlist { padding 0; } or add the padding value you need to equal center the content #playlist { padding 0 50px; }.
Updated fiddle: http://jsfiddle.net/7yos5231/5/
ul#playlist
{
text-align: center;
margin: 0 auto;
padding : 0 20px;/* change to the value you desire.*/
}