I'm sure this is possible but I can't get it to work, I want to create a banner with 4 slides and 4 buttons underneath it.
The first slide should show initially until you hover over say 'button 2' and it hides slides 1, 3 & 4 and displays slide 2 and holds that slide there (mouse off) until another button is hovered over and it will then show the corresponding slide and hide the rest.
I want to try and do all this in HTML/CSS without the need for jQuery if it is possible.
My code:
<style type="text/css">
.banners {width:100%; max-width:1004px; height:100%; max-height:546px; overflow: hidden;}
#slide1 {width:100%; height:100%; background:yellow; display:block;}
#slide2 {width:100%; height:100%; background:blue; display:none;}
#slide3 {width:100%; height:100%; background:green; display:none;}
#slide4 {width:100%; height:100%; background:red; display:none;}
#bannerbutton1 {width:100%; max-width: 251px; height:100%; max-height: 40px; float:left; background:yellow;}
#bannerbutton2 {width:100%; max-width: 251px; height:100%; max-height: 40px; float:left; background:blue;}
#bannerbutton3 {width:100%; max-width: 251px; height:100%; max-height: 40px; float:left; background:green;}
#bannerbutton4 {width:100%; max-width: 251px; height:100%; max-height: 40px; float:left; background:red;}
</style>
<div class="banners">
<div id="slide1">
</div>
<div id="slide2">
</div>
<div id="slide3">
</div>
<div id="slide4">
</div>
</div>
<a id="bannerbutton1" href="">
BANNER 1
</a>
<a id="bannerbutton2" href="">
BANNER 2
</a>
<a id="bannerbutton3" href="">
BANNER 3
</a>
<a id="bannerbutton4" href="">
BANNER 4
</a>
It might be simple and I might be missing something but help would be greatly appreciated.
Such things must be done using JavaScript. Hovering and hiding elements with pure CSS is only possible if the elements supposed to be shown/hidden are child elements of those, which you hover with your mouse. For example:
<div class="hover-to-hide-sub-div">
<div class="hide-me"></div>
</div>
and in the CSS:
div.hover-to-hide-sub-div:hover div.hide-me { display: none; }
If this hierarchy is not given, JS is needed.
Yes, you can do it without JavaScript or JQuery, but only the hover thing. If you want to stay on image when it's not on hover, then you need use JavaScript or JQuery. That's because css selector is not active when your mouse is out of the button.
Whatever, this is my code for you, pure css3. It works fine for the hover and show the image while you do hover at the button.
HTML
<div class="slider">
<input type="radio" id="control1" name="controls" checked="checked"/>
<label for="control1"></label>
<input type="radio" id="control2" name="controls"/>
<label for="control2"></label>
<input type="radio" id="control3" name="controls"/>
<label for="control3"></label>
<input type="radio" id="control4" name="controls"/>
<label for="control4"></label>
<input type="radio" id="control5" name="controls"/>
<label for="control5"></label>
<div class="sliderinner">
<ul>
<li>
<img src="bea.jpg" />
<div class="description">
<div class="description-text">
<h2>Title 1</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
</div>
</li>
<li>
<img src="bea.jpg" />
<div class="description">
<div class="description-text">
<h2>Title 2</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
</div>
</li>
<li>
<img src="bea.jpg" />
<div class="description">
<div class="description-text">
<h2>Title 3</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
</div>
</li>
<li>
<img src="bea.jpg" />
<div class="description">
<div class="description-text">
<h2>Title 4</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
</div>
</li>
<li>
<img src="bea.jpg" />
<div class="description">
<div class="description-text">
<h2>Title 5</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</p>
</div>
</div>
</li>
</ul>
</div>
</div>
CSS
h1 {color:#333; text-shadow:1px 1px #999; font-size:40px; font-family:Archivo Narrow; margin:40px; text-align:center;}
.slider {
display: block;
height: 320px;
min-width: 260px;
max-width: 640px;
margin: auto;
margin-top: 20px;
position: relative;
}
.sliderinner {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
.sliderinner>ul {
list-style: none;
height: 100%;
width: 500%;
overflow: hidden;
position: relative;
left: 0px;
-webkit-transition: left .8s cubic-bezier(0.77, 0, 0.175, 1);
-moz-transition: left .8s cubic-bezier(0.77, 0, 0.175, 1);
-o-transition: left .8s cubic-bezier(0.77, 0, 0.175, 1);
transition: left .8s cubic-bezier(0.77, 0, 0.175, 1);
}
.sliderinner>ul>li {
width: 20%;
height: 320px;
float: left;
position: relative;
}
.sliderinner>ul>li>img {
margin: auto;
height: 100%;
}
.slider input[type=radio] {
position: absolute;
left: 50%;
bottom: 15px;
z-index: 100;
visibility: hidden;
}
.slider label {
position: absolute;
left: 50%;
bottom: -45px;
z-index: 100;
width: 12px;
height: 12px;
background-color:#ccc;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
cursor: pointer;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,.8);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,.8);
box-shadow: 0px 0px 3px rgba(0,0,0,.8);
-webkit-transition: background-color .2s;
-moz-transition: background-color .2s;
-o-transition: background-color .2s;
transition: background-color .2s;
}
.slider input[type=radio]#control1:hover~label[for=control1] { background-color: #333; }
.slider input[type=radio]#control2:hover~label[for=control2] { background-color: #333; }
.slider input[type=radio]#control3:hover~label[for=control3] { background-color: #333; }
.slider input[type=radio]#control4:hover~label[for=control4] { background-color: #333; }
.slider input[type=radio]#control5:hover~label[for=control5] { background-color: #333; }
.slider label[for=control1] { margin-left: -36px }
.slider label[for=control2] { margin-left: -18px }
.slider label[for=control4] { margin-left: 18px }
.slider label[for=control5] { margin-left: 36px }
.slider input[type=radio]#control1:hover~.sliderinner>ul { left: 0 }
.slider input[type=radio]#control2:hover~.sliderinner>ul { left: -100% }
.slider input[type=radio]#control3:hover~.sliderinner>ul { left: -200% }
.slider input[type=radio]#control4:hover~.sliderinner>ul { left: -300% }
.slider input[type=radio]#control5:hover~.sliderinner>ul { left: -400% }
.description {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
font-family:Archivo Narrow;
z-index: 1000;
}
.description-text {
background-color: rgba(0,0,0,.8);
padding:10px;
top: 0;
z-index: 4;
-webkit-transition: opacity .2s;
-moz-transition: opacity .2s;
-o-transition: opacity .2s;
transition: opacity .2s;
color: #fff;
}
With CSS you can hide/show using child and sibling selectors, that is true. But even with sibling selectors the :hover elements must come before the effected element.
If you changed your structure, you could achieve a hover switch for hover states of the buttons using the :hover pseudo class and the general sibling selector ~. Here is an example:
http://jsfiddle.net/xxgLzgax/
Now using smart positioning you might be able to re-position this as you need but your problem comes when you want to keep the state of the last hovered element.
CSS is purely for styling, and even though it does cater for pseudo states of elements (inasmuch as their style), it is not able to do such a thing. :hover is for style on hover nothing else.
So as other posters have stated, you would need to use JS/JQuery to do this. Something probably along the lines of:
$( "button" ).on("mouseenter", function() {
$('class/ID to show').addClass( "hover" ).siblings().removeClass( "hover" );
});
But regardless of the JS solution to keep the state the same and make this particular setup work, you would have to use JS. Also if you do use JS to do this, I suggest using a class to toggle this, keeping the CSS and JS separate.
Related
In my example when a user hovers over a text that is too long for its container
it will start scrolling so the entire content can be read.
My problem is that I don't know how to adjust the transition duration
according to the length of the content.
I want that the text scrolls with a consistent speed across all containers.
body > div
{
width: 200px;
height: 50px;
overflow: hidden;
font-family: sans-serif;
margin-bottom: 10px;
font-size: 18px;
box-shadow: 15px 0px 0px #404040 inset, -15px 0px 0px #404040 inset;
}
div div
{
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
height: 50px;
background: #404040;
white-space: nowrap;
line-height: 50px;
color: #fff;
padding: 0px 15px;
float: left;
transform: translate(0px);
box-sizing: border-box;
position: relative;
z-index: -1;
}
div:hover div
{
width: unset;
overflow: unset;
text-overflow: unset;
transition: transform 2s linear;
transform: translate(calc(200px - 100%));
}
<div>
<div>Lorem ipsum dolor sit amet,</div>
</div>
<div>
<div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam</div>
</div>
<div>
<div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut</div>
</div>
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 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 the following scenario:
I'm using bootstrap to develop this site. When I hover into a list group, everything is suppose to have a trnasition into a blue background color and the text should go white. It works though the styles don't apply to the H4.
Here's the css code:
.styled-group-right-item{
padding: 20px;
margin-left: 100px;
}
.limited-list-group{
height: auto;
max-height: 500px;
overflow-y: scroll;
}
.author-pubdate-info{
font-weight: bold;
}
.list-group-item-switchhon-blog:hover{
transition: all 0.5s ease !important;
color: #fff !important;
background-color: #2980b9 !important;
}
.list-group-item-switchhon-blog{
transition: all 0.5s ease;
}
And here is the markup:
<div class="list-group limited-list-group">
<a href="#" class="list-group-item clearfix list-group-item-switchhon-blog">
<div class="pull-left">
<img src="http://placehold.it/100x100" class="btn-center">
</div>
<div class="styled-group-right-item">
<h4 class="list-group-item-heading">Lorem Ipsum Dolor Sit Amet</h4>
<p class="list-group-item-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget interdum libero. Vivamus pharetra faucibus.</p>
<span class="author-pubdate-info">Autor: John Doe | Fecha: 11 de Noviembre de 2014</span>
</div>
</a>
</div>
And here's a fiddle: http://jsfiddle.net/y7d5fm1w/
What I have tried so far: add another class like this:
.list-group-item-switchhon-blog:hover h4{
transition: all 0.5s ease !important;
color: #fff !important;
background-color: #2980b9 !important;
}
But that creates a very funny effect, try it on fiddle, it's not good.
Any ideas how to apply the styles into the h4, please I'm all ears.
Apply the style to the h4 as well. Also, place the transition on the non hover state; This ensures that the transition will apply in and out of the hover state.
Aside: If you change overflow-y: scroll to overflow-y: auto, you will only get a scrollbar if the content actually overflows.
Changes
.list-group-item-switchhon-blog, .list-group-item-switchhon-blog h4 { /* transition here */
transition: all 0.5s ease !important;
}
.list-group-item-switchhon-blog:hover {
color: #fff !important;
background-color: #2980b9 !important;
}
.list-group-item-switchhon-blog:hover h4 { /* add this */
color: #fff !important;
}
Working example
.styled-group-right-item {
padding: 20px;
margin-left: 100px;
}
.limited-list-group {
height: auto;
max-height: 500px;
overflow-y: auto;
}
.author-pubdate-info {
font-weight: bold !important;
}
.list-group-item-switchhon-blog, .list-group-item-switchhon-blog h4 {
transition: all 0.5s ease !important;
}
.list-group-item-switchhon-blog:hover {
color: #fff !important;
background-color: #2980b9 !important;
}
.list-group-item-switchhon-blog:hover h4 {
color: #fff !important;
}
.list-group-item-switchhon-blog {
transition: all 0.5s ease;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="list-group limited-list-group">
<a href="#" class="list-group-item clearfix list-group-item-switchhon-blog">
<div class="pull-left">
<img src="http://placehold.it/100x100" class="btn-center">
</div>
<div class="styled-group-right-item">
<h4 class="list-group-item-heading">Lorem Ipsum Dolor Sit Amet</h4>
<p class="list-group-item-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget interdum libero. Vivamus pharetra faucibus.</p>
<span class="author-pubdate-info">Autor: John Doe | Fecha: 11 de Noviembre de 2014</span>
</div>
</a>
</div>
Just trigger the h4 on hover:
.list-group-item-switchhon-blog:hover h4{
transition: all 0.5s ease;
color: #fff;
}
FIDDLE
UPDATE
A better way is actually setting the h4 to inherit the color from it's parent:
.list-group-item-switchhon-blog h4{
color: inherit !important;
}
That way you don't have to duplicate code and add extra code for the hover out
NEW FIDDLE
I have 3 boxes which need to be the same height with varying content. I am using display: table to achieve this. I need to vertically align the button to the bottom of the container. The button width could also change. I was not able to successfully get vertical-align: bottom to work.
http://codepen.io/simply-simpy/pen/kBaHt
<div id="cta-3-col" class="cta-3-col">
<div class="container">
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing </p>
</figcaption>
</figure>
Follow<i></i>
</div>
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt magna aliqua sed do edunt ut labore et dolore magna aliqua. </p>
</figcaption>
</figure>
Partner With Us<i></i>
</div>
<div class="cta">
<figure>
<img src="http://lorempixel.com/200/100/" alt="">
<figcaption>
<h2>CTA 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</figcaption>
</figure>
Learn<i></i>
</div>
</div>
</div>
.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 30px;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
}
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
}
You just have to change/add some CSS properties to your existing classes without adding extra markup:
http://codepen.io/anon/pen/rFmxa
CSS:
.cta {
background: #fff;
display: table-cell;
width: 270px;
/*padding: 0 0 30px;*/
padding: 0 0 4em;
position: relative;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
}
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
position: absolute;
bottom: 0;
margin-bottom: 1em;
left: 50%;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
}
look modified code without complex transform-translate properties wich will work in all browsers including ols IE!
advantages over other methods: efficient, fast, cross-browser, easy!
Codepen YourSolution
Modified css
.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 30px;
position:relative;
}
.cta-3-col {
background: gray;
text-align: center;
border-spacing: 10px;
.container {
display: table;
width: 1000px;
margin: 0 auto;
}
}
p {
margin:10px 0px 40px 0px;
}
a.btn {
position: absolute;
bottom: 10px;
left: 0;
right: 0px;
width: 64px;
margin: auto;
background: blue;
color: #fff;
padding: 10px;
}
Here's an updated CodePen.
The bulk of the change was adding a position:relative; modifier to the .cta class and then giving the following rules to the class .btn:
position:absolute;
bottom:5px;
left:50%;
-moz-transform:translateX(-50%);
-webkit-transform:translateX(-50%);
transform: translateX(-50%);
That should take care of the problem for you.
.cta {
background: #fff;
display: table-cell;
width: 270px;
padding: 0 0 40px;
position:relative;
}
.btn {
background: blue;
color: #fff;
padding: 10px;
position:absolute;
left:50%;
bottom:0;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
-o-transform: translateX(-50%);
transform: translateX(-50%);
}
You just need to add below additional css and it will display your html as you requested:
- .cta {position:relative;}
- .btn {position:absolute;left:45%;bottom:0px;}