text under a hover fading button - html

UPDATE: I am wanting the text to be shown beneath the button, so when it fades away, it will be revealed where the button was.
How can i place text under (in the z axis) a button made with a a element so that when i hover over the button
it fades away and shows the text under?
I have tried using positioning to and position:absolute to make it so both text can be in one spot, but it wont seem to work
My button: http://jsfiddle.net/27bCK/
<div id="pricebar">
<a class="see" href="#">PRICING</a>
</div>
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
}
#pricebar .see {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#000;
margin-right:20px;
}

try this:
<div id="pricebar">
<a class="see" href="#">PRICING</a>
<div id="hidden">hidden text</div>
</div>
css:
#hidden{
text-align:center;
position:relative;
bottom:100px;
z-index:0;
border:0px solid red;
}
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
z-index:1;
}
#pricebar .see {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
position:relative;
z-index:3;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
line-height:175px;
background-color:#000;
margin-right:20px;
}

You could always try using jQuery to accomplish this. There may be an easier way but my mind is currently focused on jQuery. There is a class that allows you to add or remove something specific. Let's take a look at the jQuery added with this.
jQuery:
$('a').hover(
function() {
var $this = $(this); // caching $(this)
$this.data('initialText', $this.text());
$this.text("I'm replaced!");
},
function() {
var $this = $(this); // caching $(this)
$this.text($this.data('initialText'));
}
);
EDIT: I replaced the add/remove of the classes to using a way where you cache the data you originally had into a variable and as you hover over it, it actually changes to the data you put inside of jQuery function and as you hover out, it will change it back. To be honest, I cannot take credit for this, because it was originally found in this Stack question, meaning, you should just go up vote that answer instead. But this should work with what you want to do.
The JSFIDDLE

If you want to do it with pure css, there are some changes to make. Get rid of the line height, set position on both .see and .show to absolute, set position of pricebar to relative, give the see and show a height and width, put the content for .show above the .see element in your html, and fiddle with a negative margin to line them up.
#pricebar {
width:100%;
height:175px;
background-color:#EAE5E5;
text-align:center;
position:relative;
}
#pricebar .see {
color:#fff;
font-size:50px;
margin-left:-15%;
background-color:#2ecc71;
border:5px solid #2ecc71;
border-radius:5px;
border-left:17px solid #2ecc71;
border-right:17px solid #2ecc71;
transition-duration: .3s;
transition-property: background-color, border, border-left, border-right, opacity;
position:absolute;
height:60px;
width:234px;
top:60px;
}
#pricebar .see:hover {
opacity:0;
background-color:#27ae60;
border:5px solid #27ae60;
border-left:17px solid #27ae60;
border-right:17px solid #27ae60;
}
#pricebar .show {
color:#fff;
font-size:50px;
background-color:#000;
height:60px;
top:60px;
margin-left:-40px;
position:absolute;
}
You can see it in this fiddle

Related

CSS issue with background color in ::after

I use the following HTML/CSS code to make a chat bubble:
body {background-color: red}
.message-sent {
position:relative;
padding:10px 20px;
color:white;
background:#0B93F6;
border-radius:25px;
float: right;
margin-bottom: 5px;
margin-right: 30px;
}
.message-sent-last::before {
content:"";
position:absolute;
z-index:-1;
bottom:-2px;
right:-7px;
height:20px;
border-right:20px solid #0B93F6;
border-bottom-left-radius: 16px 14px;
-webkit-transform:translate(0, -2px);
}
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-56px;
width:26px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: red;
}
<div class="message-sent message-sent-last">
Hey there! What's up?
</div>
But the problem is in the last line of the CSS in which I am forced to repeat the background color, otherwise, the bubble will break. Please, check this out:
body {background-color: red}
.message-sent {
position:relative;
padding:10px 20px;
color:white;
background:#0B93F6;
border-radius:25px;
float: right;
margin-bottom: 5px;
margin-right: 30px;
}
.message-sent-last::before {
content:"";
position:absolute;
z-index:-1;
bottom:-2px;
right:-7px;
height:20px;
border-right:20px solid #0B93F6;
border-bottom-left-radius: 16px 14px;
-webkit-transform:translate(0, -2px);
}
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-56px;
width:26px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: transparent;
}
<div class="message-sent message-sent-last">
Hey there! What's up?
</div>
I would like to not repeat the background color of the page since the snippet will be used in several places with different background colors. I've tried with transparent and inherit but none worked out.
This is how the second snipped looks like:
I've tested in Chrome and FF under Ubuntu.
What do you think?
In your case, since it is fundamental for the creation of the bubble to assign the same color of the background to the div I would suggest to use a variable, so when the color of the body changes even the color of the div::after will change:
add at the top of your css file:
:root {
--main-bg-color: red;
}
in your body element:
body {background-color: var(--main-bg-color);}
and div:
.message-sent-last::after {
content:"";
position:absolute;
z-index:1;
bottom:-2px;
right:-40px;
width:10px;
height:20px;
border-bottom-left-radius: 10px;
-webkit-transform:translate(-30px, -2px);
background: var(--main-bg-color);
}
This allows you to change it on root and making the change effective on both elements.
Please note that it will not work on IE though.

How do I set a partially transparent background on a div?

I want the divs to be partially transparent so that the background can be seen through, but want the other elements <p> not to be transparent as they are in the image. Currently I am using opacity: .4.
HTML
<!-- tarifas starts here-->
![<div class="tarifas">
<h1>Tarifas</h1>
<h3>Consigue la máxima experiencia sin preocuparte por el roaming</h3>
<div class="tarifas_left">
<div class="tarifas_left_top">
<p>5€<span>/día</span></p>
</div>
<div class="tarifas_left_bottom">
<p>hasta<span>1Gb</span>/día</p>
<p>router wifi movil</p><button>
<p>RESERVAR</p></button>
</div>
</div>
<div class="tarifas_right">
<div class="tarifas_right_top">
<p>30€<span>/mes</span></p>
</div>
<div class="tarifas_right_bottom">
<p>hasta<span>7Gb</span>/día</p>
<p>router wifi movil</p><button>
<p>RESERVAR</p></button>
</div>
</div>
</div>
CSS
tarifas {
background:url(image/air_image1.jpg) no-repeat scroll 0 -332px rgba(0,0,0,0);
height:460px;
position:relative;
width:100%
}
.tarifas h1 {
font-size:40px;
color:#fff;
margin-left:500px;
margin-top:28px;
position:absolute;
font-family:HelveticaNeue-Light
}
.tarifas h3 {
font-size:24px;
color:#fff;
margin-left:232px;
margin-top:100px;
position:absolute;
font-family:HelveticaNeue-Light
}
.tarifas_left_top {
position:absolute;
width:285px;
height:80px;
background-color:#AEABA1;
margin-top:150px;
margin-left:290px;
border-radius:10px 10px 0 0;
opacity:.4;
border:2px solid #fff
}
.tarifas_left_bottom {
position:absolute;
width:285px;
height:170px;
background-color:#AEABA1;
margin-top:237px;
margin-left:290px;
border-radius:0 0 10px 10px;
opacity:.4;
border:2px solid #fff
}
.tarifas_left_top p {
font-size:67.48px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light;
opacity:1
}
.tarifas_left_top p span {
font-size:12px;
color:#fff;
font-family:HelveticaNeue-Light
}
.tarifas_left_bottom p:nth-child(1) {
font-size:12px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light
}
.tarifas_left_bottom p:nth-child(1) span {
font-size:24px;
color:#fff;
font-family:HelveticaNeue-Light
}
.tarifas_left_bottom p:nth-child(2) {
font-size:24px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light
}
.tarifas_left_bottom button {
border-radius:10px;
color:#fff;
font-size:20px;
height:39px;
margin-left:65px;
margin-top:55px;
width:155px;
font-family:HelveticaNeue-Light;
opacity:1
}
.tarifas_right_top {
position:absolute;
width:285px;
height:80px;
background-color:#AEABA1;
margin-top:150px;
margin-left:600px;
border-radius:10px 10px 0 0;
opacity:.4;
border:2px solid #fff
}
.tarifas_right_bottom {
position:absolute;
width:285px;
height:170px;
background-color:#AEABA1;
margin-top:237px;
margin-left:600px;
border-radius:0 0 10px 10px;
opacity:.4;
border:2px solid #fff
}
.tarifas_right_top p {
font-size:67.48px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light
}
.tarifas_right_top p span {
font-size:12px;
color:#fff;
font-family:HelveticaNeue-Light
}
.tarifas_right_bottom p:nth-child(1) {
font-size:12px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light
}
.tarifas_right_bottom p:nth-child(1) span {
font-size:24px;
color:#fff;
font-family:HelveticaNeue-Light
}
.tarifas_right_bottom p:nth-child(2) {
font-size:24px;
color:#fff;
text-align:center;
font-family:HelveticaNeue-Light
}
.tarifas_right_bottom button {
border-radius:10px;
color:#fff;
font-size:20px;
height:39px;
margin-left:65px;
margin-top:55px;
width:155px;
font-family:HelveticaNeue-Light;
opacity:1
}
and the screenshot:
Use rgba colors rather than opacity which affects the children of an element.
So for instance
background-color: #AEABA1
opacity: .4
would translate into:
background-color: rgba(174, 171, 161, 0.4)
You can find a HEX to RGBA convertor here
For the classes .tarifas_left_top and .tarifas_left_bottom, remove the opacity and instead use background-color: rgba(#,#,#,#). For the background color #AEABA1 with opacity 0.4, this translates to background-color: rgba(174,171,161,0.4).
For IE 8 and below, you'll need to override the background with a filter property.
.tarifas_left_top {
background-color: rgba(174,171,161,0.4);
background: transparent\9;
/* This '\9' is intentional. It's a CSS hack, but
it works, and it resets the background in IE 8
and below only. */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#66AEABA1,endColorstr=#66AEABA1);
zoom: 1;
}
Effectively, this gives you cross-browser semi-transparent backgrounds without affecting the opacity of the element's children. These properties can also be used for the border-color and color properties.

Text not disappearing properly

CSS
#articlebottom {
width: 980px;
height: 250px;
}
.products{
width:980px;
margin:0px auto;
padding-left:20px;
}
#articlebottom .imgWrap {
width:295px;
height:200px;
position:relative;
float:left;
margin:10px;
background:#333;
}
#articlebottom .imgWrap img {
position:absolute;
left:5px;
top:5px;
width:285px;
height:190px;
}
#articlebottom .imgDescription1 {
position: absolute;
left:0;
letter-spacing: 2px;
background-color: rgba(255, 250, 250, 0.2);
color: rgba(255, 250, 250, 0.2);
font-weight:bold;
font-size:18pt;
line-height: 50px;
width:100%;
height:50px;
opacity: 0;
text-align:center;
text-transform:uppercase;
transition:opacity 500ms ease-in-out, color 20ms ease-in-out,height 500ms ease-in-out;
}
#articlebottom .imgWrap:hover .imgDescription1 {
opacity: 1;
height:200px;
line-height:200px;
color: #1b9bff;
}
HTML
<article id="articlebottom">
<div class="products">
<div class="imgWrap">
<a href="Products/Camphor.aspx" target="_blank"><img src="Images/Camphor_b.JPG" alt="polaroid" />
<p class="imgDescription1">Camphor</p></a>
</div>
</div>
</article>
Fiddle
What I'm having:
The Text appears on the center when i hover and going to top after hover
What i need:
When i hover on the image the appropriate text shoould appear on the center and also need to disappear on center of the image itself
Updated Fiddle
The crucial part is moving
height:200px;
line-height:200px;
color: #1b9bff;
From:
#articlebottom .imgWrap:hover .imgDescription1
To:
#articlebottom .imgDescription1
Otherwise the position of the text is set to a default/inherited value and only set to centred on hover, hence why the hover state sees it jump.

How to create a background color based border in a circle div?

I tried to create a circle which border should look same color as div color and a space between the border and div. The in between space should show the background color of what ever div it is on. the background color is changeable so we shouldn't hardcode it.
Instead i have given transparency using rgba mode. All work fine am trying to get this effect on hover of the circle but i couldn't able to get the hover because i'm trying to display:block on hover and in normal state it is display:none; This are for the after selector hence i tried this effect with after selector.
CODE
CSS
.main{
width:80px;
height:80px;
border-radius:100%;
background-color:#007eff;
text-align:center;
line-height:80px;
}
.main:hover + .main:after{
display:block;
}
.main:after{
width:86px;
height:86px;
border-radius:100%;
background:rgba(255,255,255,0.1);
border:2px solid #007eff;
position:absolute;
content:"";
z-index:-1;
top:3px;
left:3px;
display:none;
}
body{
background-color:#888;
}
HTML
<div class="main"><i class="fa fa-camera-retro fa-lg"></i>
</div>
PROBLEM STATE
ON HOVER it should become like THIS with effects if possible
If there is any tutorial to do this i'll happy to learn. Thanks
set position:relative; to the .main and set left/right/top/bottom of the .main:after to zero and add transition:all ease 0.3s for animating.
in the .main:hover:after change left/right/top/bottom to -5px.
demo
.main{
width:80px;
height:80px;
border-radius:100%;
background-color:#007eff;
text-align:center;
line-height:80px;
position:relative;
margin:6px;
}
.main:after{
border-radius:100%;
background:rgba(255,255,255,0.1);
border:2px solid #007eff;
position:absolute;
content:"";
z-index:-1;
top:0px;
left:0;
bottom:0;
right:0;
transition:all ease 0.3s;
}
.main:hover:after{
top:-5px;
bottom:-5px;
right:-5px;
left:-5px;
}
Just add .main:hover:after to display it as block on hover WORKING FIDDLE
.main:hover:after{
display:block;
}
Try something like this
CSS :
.main{
width:80px;
height:80px;
border-radius:100%;
background-color:#007eff;
text-align:center;
line-height:80px;
}
.main:hover:after{
width:86px;
height:86px;
border-radius:100%;
background:rgba(255,255,255,0.1);
border:2px solid #007eff;
position:absolute;
content:"";
z-index:111;
top:3px;
left:3px;
}
body{
background-color:#888;
}
HTML :
<div class="main"><i class="fa fa-camera-retro fa-lg"></i>
</div>
FIDDLE
you could use box-shadow instead pseudo-element :
http://jsfiddle.net/Ku6BQ/24/
.main {
width:80px;
height:80px;
border-radius:100%;
background-color:#007eff;
text-align:center;
line-height:80px;
}
.main:hover {
box-shadow: 0 0 0 4px #888888, 0 0 0 6px #007eff;
}
body {
background-color:#888;
}
If you it it transparent and show behind a gradient or an image, you may still use box-shadow : http://jsfiddle.net/Ku6BQ/25/ http://jsfiddle.net/Ku6BQ/26/
.main {
width:80px;
height:80px;
border-radius:100%;
box-shadow:inset 0 0 0 100px #007eff;
text-align:center;
line-height:80px;
}
.main:hover {
border:4px transparent solid;
margin:-4px;
box-shadow: 0 0 0 2px #007eff,
inset 0 0 0 100px #007eff;;
}
html {
background :#888 url(http://lorempixel.com/200/200/nature) repeat;
height:100%;
}
An improvement (just for the record) on he idea of a box shadow as apported by GCyrillus
.main {
width:80px;
height:80px;
border-radius:100%;
background-color:#007eff;
text-align:center;
line-height:80px;
border: solid 4px transparent;
background-clip: padding-box;
box-shadow: 0 0 0 0px white;
-webkit-transition: all 1s;
transition: all 1s;
}
.main:hover {
box-shadow: 0 0 0 6px #007eff;
}
body {
background-color:#888;
}
fiddle

-webkit-transition: property isn't working in a bubble element?

I was creating a portfolio, and I want it so that whenever someone hovers over my name, a bubble with an arrow appears. I've done that part already, but the problem is that the -webkit-transition property isn't working. The bubble is a little far to my name so I want it so that it takes a little bit of time to hide again, so someone can go to it easily because I'm thinking of making a form to contact me in it.
My HTML:
<div id="side-bar"><h1 id="ab_me">About Me</h1>
<img src="saksham.png" id="saksham">
<p id="name"><span>S</span>aksham <span>C</span>hauhan</p>
<div id="bubble">
SUP !
<div id="bubble-arrow-border">
</div>
<div id="bubble-arrow">
</div>
</div>
</div>
My CSS:
div#side-bar p
{
font-size:25;
border-bottom:2px solid red;
position:absolute;
left:10px;
color:#F63737;
}
div#side-bar p:hover
{
border-bottom:2px groove #C01F1F;
color:#C01F1F;
text-shadow:0px 1px 2px #F98378;
-webkit-transition:1s;
}
div#side-bar p span
{
font-size:40px;
}
div#side-bar p:hover ~ #bubble
{
display:block;
visibility:visible;
opacity:1;
-webkit-transition:5s;
}
div#side-bar p #bubble:hover
{
display:block;
visibility:visible;
opacity:1;
}
#bubble
{
background-color:#EDEDED;
visibility:hidden;
border:2px solid #666666;
font-size:35px;
line-height:1.3em;
padding:10px;
position:absolute;
text-align:center;
width:300px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
-moz-box-shadow:0 0 5px #888888;
-webkit-box-shadow:0 0 5px #888888;
z-index:100;
left:230px;
top:400px;
display:none;
-webkit-transition:5s;
opacity:0;
}
#bubble-arrow
{
border-color:transparent #EDEDED transparent transparent;
border-style: solid;
border-width: 15px;
height:0;
width:0;
position:absolute;
bottom:25px;
left:-28px;
z-index:100;
}
#bubble-arrow-border
{
border-color:transparent #666666 transparent transparent;
border-style: solid;
border-width: 15px;
height:0;
width:0;
position:absolute;
bottom:25px;
left:-31px;
}
When you are using a transition you must have both "before" and "after" states set (e.g. you cant transition from nothing to opacity:0 but you can from opacity:1 to opacity:0). Also, you can't have a transition on display but you can on visibility.
Here's some more about transitions: https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_transitions
You have to tell it what properties to transition. It looks like you're trying to do this:
transition:all 1s ease;
-webkit-transition:all 1s ease;
Don't post your entire code, only relevant code.
CSS transitions don't work well with display:none. When I had to use display:none, I had to use Javascript to supplement my CSS.
So, if you remove display:none from #bubble, and then use:
-webkit-transition:all 1000ms;
On #bubble, and then have #bubble:hover set to change the opacity to 1:
opacity:1;
Your bubble will fade in, and then fade out.
http://jsfiddle.net/charlescarver/nrTMg/1/