CSS element positioning trouble - html

I was wondering how can I get the heading element to flow under the slider instead of on top and behind the slider. In other words how can I get the heading or any other element to flow normaly below the slider.
Here is the link to the Jsfiddle https://jsfiddle.net/1kg7s473/
HTML
<form class="sliders">
<input type="radio" name="slider-choice" id="first-slider" checked />
<div class="slider-container">
<div class="slider">
<p>Some Random Text...</p>
</div>
<div class="nav">
<label for="second-slider" class="prev"></label>
<label for="second-slider" class="next"></label>
</div>
</div>
<input type="radio" name="slider-choice" id="second-slider" />
<div class="slider-container">
<div class="slider">
<p>Even Some More Random Text...</p>
</div>
<div class="nav">
<label for="first-slider" class="prev"></label>
<label for="first-slider" class="next"></label>
</div>
</div>
</form>
<h2>Some more random text</h2>
CSS
.sliders {
width: 600px;
position: relative;
}
.sliders input{
display: none;
}
.slider {
position: absolute;
opacity: 0;
width: 600px;
transform: scale(0);
transition: all .6s ease-in-out;
}
.nav label {
margin-top: 65px;
width: 85px;
display: none;
position: absolute;
opacity: 0;
cursor: pointer;
transition: opacity .2s;
color: black;
font-size: 6em;
text-align: center;
background-color: rgba(100, 100, 100, .6);
Z-index: 99999;
}
.sliders:hover .nav label{
opacity: 0.5;
cursor: pointer;
}
.sliders:hover .prev:hover, .sliders:hover .next:hover{
opacity: 1;
}
.nav .next{
right: 0;
}
.prev:before{
content: '\2770';
}
.next:before{
content: '\2771';
}
input:checked + .slider-container .slider{
opacity: 1;
transform: scale(1);
transition: opacity 2s ease-in-out;
}
input:checked + .slider-container .nav label{
display: block;
}
p{
padding: 100px 20px;
width: 560px;
text-align: center;
background: #dae1ef;
}

Put the h2 inside a div like this:
<div class="h2Container" >
<h2>Some more random text</h2>
</div>
Add the following CSS to the class h2Container
.h2Container
{
position: relative; padding-top: 25%;
}
Here is the Demo for the same.

Remove the styles on the .sliderclass and attribute them to the slides container instead with these changes too:
.slider-container {
width: 600px;
position: relative; //do not use absolute on this
top: 0;
height: 235px; //you must have a height defined or 100%
display: inline-block; //this reserves the entire area (width X Height) and automatically places the next element below the defined height
}
See the working DEMO

Related

Add a Link to an Overlay Image

I would like to add a link to an image that has an overlay applied to it. When users hover over the image they get an opaque overlay and text appear. This works great, however I also need users to be able to click that image and taken to a link.
I have pasted my code below - the overlay works but the link portion does not. I believe it's because the overlay is interfering. I tried changing the placement of the link but was unable to do so. I am able to make the '+' be the link, but ideally the entire image should link.
Any thoughts?
JSFiddle
.roomphoto:hover .img__description { transform: translateY(0); }
.roomphoto .img__description_layer { top: 30px; }
.roomphoto:hover .img__description_layer { visibility: visible; opacity: 1; }
.img__description_layer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
color: #cdcbca;
visibility: hidden;
opacity: 0;
display: flex;
align-items: center;
justify-content: center;
transition: opacity .2s, visibility .2s;
}
.roomphoto {
height: 166px;
}
.img__description {
transition: .2s;
transform: translateY(1em);
z-index: 999;
}
.overlay {
position: relative;
}
.overlay:after {
position: absolute;
content:"";
top:0;
left:0;
width:100%;
height:100%;
opacity:0;
}
.overlay:hover:after {
opacity: .8;
}
.blue:after {
background-color: #1a3761;
}
.img__description a {
color: #fff;
}
.roomselect {
clear: both;
float: none;
width: 100%;
max-width: 1000px;
margin: 0px auto;
padding-top: 20px;
}
.roomselect img {
width: 100%;
margin-bottom: -10px;
}
.room3 {
width: 32%;
text-align: left;
float:left;
}
<div class="roomselect"><div class="room3">
<div class="roomphoto overlay blue">
<a href="http://www.google.com">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
</a>
<div class="img__description_layer">
<p class="img__description">
<span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span>
</p>
</div>
</div>
</div>
You need to rearrange your html in such a way that when you click on image, you are actually clicking on the anchor tag. I have made some changes to your html, let me know if these work. You might have to increase roomphoto height.
<div class="roomselect">
<div class="room3">
<a href="http://www.google.com">
<div class="roomphoto overlay blue">
<img src="https://cdn.mos.cms.futurecdn.net/J9KeYkEZf4HHD5LRGf799N-650-80.jpg" alt="Image Text" />
<div class="img__description_layer">
<p class="img__description"><span style="border-radius: 50%; width: 30px; height: 30px; padding: 0px 14px; border: 1px solid #fff; text-align: center; font-size: 36px;">+</span></p>
</div>
</div>
</a>
</div>
</div>

css checkbox not applying changes when in the :checked state

I am trying to bring some hidden text into view when a radio checkbox is checked. I cant quite work out why the :checked styling is not applying once the label is checked. I think i am being really daft but just cant work out what is going on.
Could anyone lend some advice?
.wrap__wrapper {
width: 400px;
margin: 0 auto;
}
.wrap {
position: relative;
overflow: hidden;
}
.wrap__radio--input {
display: none;
}
.wrap__inner {
width: 300%;
left: 0;
transition: all 1s;
}
.wrap__slides {
float: left;
width: 33.333%;
}
.wrap__text {
font-size: 16px;
text-align: center;
}
.wrap__button {
font-size: 1.8rem;
cursor: pointer;
text-align: center;
display: block;
}
.wrap__radio--input:checked~.wrap__inner {
transition: all 1s;
background: red;
left: -100%;
}
<div class="wrap__wrapper">
<div class="wrap">
<input type="radio" class="wrap__radio--input" id="slide--1">
<label for="slide--1" class="wrap__button">next slide</label>
<div class="wrap__inner">
<div class="wrap__slides">
<p class="wrap__text">slide1</p>
</div>
<div class="wrap__slides">
<p class="wrap__text">slide2</p>
</div>
</div>
</div>
</div>
Your element need to be positionned so you have to set position property to relative, absolute or fixed on .wrap__inner to be able to use left property. You cannot update position of static element.
.wrap__wrapper {
width: 400px;
margin: 0 auto;
}
.wrap {
position: relative;
overflow: hidden;
}
.wrap__radio--input {
display: none;
}
.wrap__inner {
position:relative;
width: 300%;
left: 0;
transition: all 1s;
}
.wrap__slides {
float: left;
width: 33.333%;
}
.wrap__text {
font-size: 16px;
text-align: center;
}
.wrap__button {
font-size: 1.8rem;
cursor: pointer;
text-align: center;
display: block;
}
.wrap__radio--input:checked~.wrap__inner {
transition: all 1s;
background: red;
left: -100%;
}
<div class="wrap__wrapper">
<div class="wrap">
<input type="radio" class="wrap__radio--input" id="slide--1">
<label for="slide--1" class="wrap__button">next slide</label>
<div class="wrap__inner">
<div class="wrap__slides">
<p class="wrap__text">slide1</p>
</div>
<div class="wrap__slides">
<p class="wrap__text">slide2</p>
</div>
<div class="wrap__slides">
<p class="wrap__text">slide3</p>
</div>
</div>
</div>
</div>
You can use the :before or :after pseudo-elements to toggle the previous and next text, apply the position property different from the default value of static to the .wrap__inner div and most importantly change the input type="radio" to input type="checkbox" to be able to toggle the checkbox state:
.wrap__wrapper {
width: 400px;
margin: 0 auto;
}
.wrap {
position: relative;
overflow: hidden;
}
.wrap__radio--input {
display: none;
}
.wrap__inner {
position: relative; /* any value other than default */
width: 300%;
left: 0;
transition: all 1s;
}
.wrap__slides {
float: left;
width: 33.333%;
}
.wrap__text {
font-size: 16px;
text-align: center;
}
.wrap__button {
font-size: 1.8rem;
cursor: pointer;
text-align: center;
display: block;
}
/* added */
.wrap__button:after {
content: "next";
}
.wrap__radio--input:checked + .wrap__button:after {
content: "previous";
}
/***/
.wrap__radio--input:checked ~ .wrap__inner {
transition: all 1s;
background: red;
left: -100%;
}
<div class="wrap__wrapper">
<div class="wrap">
<input type="checkbox" class="wrap__radio--input" id="slide--1">
<label for="slide--1" class="wrap__button"></label>
<div class="wrap__inner">
<div class="wrap__slides">
<p class="wrap__text">slide1</p>
</div>
<div class="wrap__slides">
<p class="wrap__text">slide2</p>
</div>
</div>
</div>
</div>
Note: Like I wrote in the comment, this only works for two slides.

Semantic UI: Get clearing segment to expand to the height of it's contents

I'm using a clearing segment to clear a floating button, but the segment does not seem to expand to the height of it's content.
How can I get it to expand it's height to fit the content?
Examples JSFiddle: https://jsfiddle.net/ftwL2whn/
/* View rubrics */
.ui.centered.button-header.header {
position: absolute;
z-index: 1;
right: 0;
left: 0;
}
.ui.button.floated.button-header {
position: relative;
z-index: 2;
}
.ui.labeled.icon.button > .dark.icon {
background-color: rgba(0, 0, 0, .1);
}
/* Edit Rubric Input*/
.edit.rubric.input {
display: inline-block;
margin: 0.2em;
width: 250px;
}
.edit.rubric.wide.input {
display: inline-block;
width: 300px;
}
.edit.rubric.narrow.input {
display: inline-block;
width: 200px;
}
.edit.rubric.input input {
border: none;
width: 100%;
border-bottom: 1px solid #D4D4D5;
}
.edit.rubric.input input:focus {
outline: none;
border-color: transparent;
transition: 300ms ease all;
}
.bar:after {
content: '';
display: block;
transform: scaleX(0);
height: 2px;
background: #48afb9;
transition: 300ms ease all;
}
.edit.rubric.input input:focus ~ .bar:after {
transform: scaleX(1);
}
.centered .edit.rubric.input input {
text-align: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.4/semantic.min.css" rel="stylesheet"/>
<br>
<div class="ui container">
<div class="ui top attached clearing segment">
<h3 class="ui centered button-header header">
<div class="edit rubric input">
<input type="text" value="Phone QA">
<span class="bar"></span>
</div>
<div class="sub header">
<div class="edit rubric wide input">
<input type="text" value="Create and edit rubrics here">
<span class="bar"></span>
</div>
</div>
</h3>
<div class="ui left floated left labeled icon orange button-header button">
Back
<i class="dark left arrow icon"></i>
</div>
</div>
</div>
The clearing segment code that semantic added:
.ui.clearing.segment::after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
The issue is the third property of height: 0; If you open your dev tools and untick the selected height property, you'll see the height adjusting to cover 100% of the content.
One way to override this is to do something like this in your main CSS file:
.ui.clearing.segment::after {
height: 1.5em;
}

Using nth child to select one particular sibling

I am hosting three images from Google on my codepen demo.
I have built image overlays which add a semi-transparent overlay when a user hovers over them.
They're working fine, but due to the colour of the last one, it looks much darker when hovered over than the other two.
I wondered whether there was a way to select the last image using the nth child (or similar) selector so that I could style that with a lower opacity irrespective of the other two, which I want to keep the same.
Here's the codepen link - http://codepen.io/skoster7/pen/ozgjmP?editors=1100
Like I said, I would like the last image to have a lower opacity then the other two, ideally using the nth-child selector or something similar.
I know I could just use a separate overlay with a different class name, but wanted to know if this was possible before doing that.
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
opacity: .6;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:last-child .overlay:hover {
rgba(20, 5, 5, 0.35);
text-
}
<div class="flexcontainer">
<div class="photocontainer">
<img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay">
<p>Spring is here</p>
</div>
</div>
<div class="photocontainer">
<img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay">
<p>Winter is here</p>
</div>
</div>
<div class="photocontainer">
<img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay">
<p>Autumn is here</p>
</div>
</div>
</div>
This is how you could target each one of them using nth-child, we are targeting parent element i.e. .photocontainer as they are of same class name in all three images.
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"><p>Spring is here</p>
</div>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"> <p>Winter is here</p>
</div>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"><p>Autumn is here</p>
</div>
</div>
</div>
UPDATED
The issue of text opacity lowering and last child opacity control both has been fixed
Working example at CODEPEN
HTML:
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"></div>
<p>Spring is here</p>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"></div>
<p>Winter is here</p>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"></div>
<p>Autumn is here</p>
</div>
</div>
CSS:
.flexcontainer {
display: flex;
}
.photocontainer,
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
position: relative;
}
.overlay {
transition: .5s;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
margin: 5px;
}
.photocontainer p {
position: absolute;
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
top: 20px;
left: 0;
right: 0;
bottom: 0;
margin: 5px;
z-index: 1;
transition: .5s;
opacity: 0;
}
.photocontainer:hover .overlay {
transition-delay: .2s;
transition-duration: 1s;
opacity: 0.6;
}
.photocontainer:hover p {
transition-delay: .2s;
transition-duration: 1s;
opacity: 1;
}
.photocontainer:hover:last-child .overlay {
opacity: 0.3;
}
Old:
.photocontainer:last-child .overlay:hover {
opacity: 0.4;
}
I hope now your both issue has been resolved.
Enjoy :)
Here's how you target it. The opacity value is just for example.
.photocontainer:last-child .overlay:hover {
opacity: .3;
}
revised codepen
The :last-child pseudo-class targets the last sibling of the same parent.
In your HTML, the third image is contained in the last .photocontainer div.
Once the focus is on the third container, you can use a descendant selector to target the image.
Also, keep in mind that the opacity property applies not only to the targeted element, but to all of the element's descendants, as well.
So when you reduce the opacity of .overlay, the text inside will also fade away.
The solution is to use the rgba() color method. The a stands for alpha channel, and allows you to apply transparency only to the color.
Add this to your code:
.photocontainer:last-child .overlay:hover {
background-color: rgba(0, 0, 0, 0.5);
}
revised codepen illustrating both methods
(If you're applying opacity to an image, that's another ball game. You can find lots of posts on this site on that topic.)
References:
https://www.w3.org/TR/css3-selectors/#selectors
https://developer.mozilla.org/en-US/docs/Web/CSS/opacity

Content sliders CSS z-index property not working properly in the Edge browser

for some reason the z-index property is not working properly in the Edge browser which should display the arrow I'm hovering over at full opacity until removed. For example, when I click an arrow a second time to view the next slide the current arrows full opacity is not on until I move the mouse again. I was wondering if it's possible to keep the current arrow in full opacity until the mouse pointer is not hovering over the arrow any longer?
I was wondering if there is a way to fix this for the Edge browser since in all the other browsers this is working perfectly.
Here is the link to the Jsfiddle https://jsfiddle.net/ef2bvkqb/
HTML
<form class="sliders">
<input type="radio" name="slider-choice" id="first-slider" checked />
<div class="slider-container">
<div class="slider">
<p>Some Random Text...</p>
</div>
<div class="nav">
<label for="second-slider" class="prev"></label>
<label for="second-slider" class="next"></label>
</div>
</div>
<input type="radio" name="slider-choice" id="second-slider" />
<div class="slider-container">
<div class="slider">
<p>Even Some More Random Text...</p>
</div>
<div class="nav">
<label for="first-slider" class="prev"></label>
<label for="first-slider" class="next"></label>
</div>
</div>
</form>
CSS
.sliders {
width: 600px;
position: relative;
}
.sliders input{
display: none;
}
.slider {
position: absolute;
opacity: 0;
width: 600px;
transform: scale(0);
transition: all .6s ease-in-out;
}
.nav label {
margin-top: 65px;
width: 85px;
display: none;
position: absolute;
opacity: 0;
cursor: pointer;
transition: opacity .2s;
color: black;
font-size: 6em;
text-align: center;
background-color: rgba(100, 100, 100, .6);
Z-index: 99999;
}
.sliders:hover .nav label{
opacity: 0.5;
cursor: pointer;
}
.sliders:hover .prev:hover, .sliders:hover .next:hover{
opacity: 1;
}
.nav .next{
right: 0;
}
.prev:before{
content: '\2770';
}
.next:before{
content: '\2771';
}
input:checked + .slider-container .slider{
opacity: 1;
transform: scale(1);
transition: opacity 2s ease-in-out;
}
input:checked + .slider-container .nav label{
display: block;
}
p{
padding: 100px 20px;
width: 560px;
text-align: center;
background: #dae1ef;
}
This happens because the arrows are inside each slide, I mean each slide has it's own arrows.
You need to put the arrows outside the slides, and only one couple of the arrows and you gonna need to use JavaScript instead of using only CSS3 to animate.