CSS images and texts hovering both - html

I'm trying to apply an effect to my pics when I put the cursor over them. What I want is a greyscale filter and a that a text appears. I've used this code:
HTML:
<div class="upic_wrap">
<img class="upic" src="foo.jpg">
<div class="upic_text">Avenida Central</div>
</div>
CSS:
.upic_text {
position:absolute;
top: 50%;
left: 50%;
transform:translate(-50%, -50%);
visibility:hidden;
opacity:0;
}
.upic:hover {
opacity:0.5;
-webkit-filter:grayscale(100%);
filter:grayscale(100%);
}
.upic_wrap:hover .upic_text {
visibility:visible;
opacity:1;
color:#000;
text-align:center;
text-shadow:1px 1px yellow;
}
I get this:
(out of pic)
(hover pic, yes! what I want!)
Which is perfect, but the problem is when the cursor is over the text. That's what happen:
(hover text, noooo!)
I would like to always get the effect of "hover pic" (the second) when I hover the pic or the text.
How could I solve that?
Thanks!

This should fix the issues. The thing is to set :hover of the .upic_wrap selector.
This snippet is based on your initial code, but I think it needs some changes to look like the pictures you posted.
.upic_text {
position:absolute;
top: 50%;
left: 50%;
transform:translate(-50%, -50%);
opacity:0;
}
.upic_wrap:hover .upic {
opacity:0.5;
-webkit-filter:grayscale(100%);
filter:grayscale(100%);
}
.upic_wrap:hover .upic_text {
visibility:visible;
opacity:1;
color:#000;
text-align:center;
text-shadow:1px 1px yellow;
}
<div class="upic_wrap">
<img class="upic" src="https://i.stack.imgur.com/DKgfx.png">
<div class="upic_text">Avenida Central</div>
</div>

.upic_wrap
{
border: 1px solid red;
width: 40%;
position: relative;
cursor: pointer;
}
.upic
{
width: 100%;
height: 250px;
}
.upic_text {
position:absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
}
.upic_wrap:hover .upic {
opacity:0.5;
-webkit-filter:grayscale(100%);
filter:grayscale(100%);
}
.upic_wrap:hover .upic_text {
display: block;
opacity:1;
color:#000;
text-align:center;
text-shadow:1px 1px yellow;
}
<div class="upic_wrap">
<img class="upic" src="http://tech21info.com/admin/wp-content/uploads/2013/03/chrome-logo-200x200.png">
<div class="upic_text">Avenida Central</div>
</div>
your query is convert in to fully responsive and solved to something changes in css.

Related

Why the overlay div cannot take the parent's dimensions

I am trying to create a button.
When the the mouse hovers the wrapper div (ks-wrapper), another div (ks-overlay) (that at the start is hidden) will be appeared and the based div (ks-button) hides.
Its also necessary the button not have fixed dimensions.
Any suggestions?
HTML
<div class="ks-wrapper">
<div class="ks-button">
<div class="ks-header">
Header
</div>
<div class="ks-content">
Text
</div>
</div>
<div class="ks-overlay">
"K"
</div>
</div>
CSS
.ks-wrapper {
position: relative;
float: left;
height: 85px;
width: 100%;
}
.ks-button {
position: absolute;
color: white;
width: 100%;
height: 100%;
}
.ks-header{
border-top-left-radius:10px;
border-top-right-radius:10px;
background-color:yellow;
max-height:20px;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
}
.ks-content{
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
background-color:grey;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
height:100%;
}
.ks-wrapper .ks-overlay {
transition: visibility 0s, opacity 0.5s ease-in-out;
position: absolute;
color: yellow;
background-color: green;
width: 97.5%;
height: 85px;
visibility: hidden;
opacity: 0;
border-radius:10px;
padding:10px;
overflow:hidden;
}
.ks-wrapper:hover .ks-overlay {
visibility: visible;
opacity: 1;
}
UPDATE
For start I want to thank you all for your fast responses to my issue.
Secondly, I would like to make myself more clear... and also to add a couple of problems that I figure them out...
1)This button its gonna used in a responsive template.
Is it possible the button not to have a fixed height, and the overlay to follow this height?
2)how can accomplish to have transition and to mouse leave (transition works only in hover)??
3)This button stays on top of the following elements
This is the link in the fiddle that represents the issues.
Thank you a lot for your time
the header is taking 20 px on the top.. you need tho add these to your .ks-wrapper .ks-overlay {
.ks-wrapper {
position: relative;
float: left;
height: 85px;
width: 100%;
}
.ks-button {
position: absolute;
color: white;
width: 100%;
height: 100%;
}
.ks-header{
border-top-left-radius:10px;
border-top-right-radius:10px;
background-color:yellow;
max-height:20px;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
}
.ks-content{
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
background-color:grey;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
height:100%;
}
.ks-wrapper .ks-overlay {
transition: visibility 0s, opacity 0.5s ease-in-out;
position: absolute;
color: yellow;
background-color: green;
width: 97.5%;
height: 105px;
visibility: hidden;
opacity: 0;
border-radius:10px;
padding:10px;
overflow:hidden;
}
.ks-wrapper:hover .ks-overlay {
visibility: visible;
opacity: 1;
}
<div class="ks-wrapper">
<div class="ks-button">
<div class="ks-header">
Header
</div>
<div class="ks-content">
Text
</div>
</div>
<div class="ks-overlay">
"K"
</div>
</div>
Might be you are saying about .ks-overlay which overflow browser width after certain screen size, if so then that's because of padding added in that, use css box-sizing property as below,
The box-sizing property is used to alter the default CSS box model
used to calculate width and height of the elements.
.ks-wrapper {
position: relative;
float: left;
height: 85px;
width: 100%;
}
.ks-button {
position: absolute;
color: white;
width: 100%;
height: 100%;
}
.ks-header{
border-top-left-radius:10px;
border-top-right-radius:10px;
background-color:yellow;
max-height:20px;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
}
.ks-content{
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
background-color:grey;
font-size:20px;
font-weight:bold;
text-align:center;
color:black;
padding:5px;
height:100%;
}
.ks-wrapper > .ks-overlay {
transition: visibility 0s, opacity 0.5s ease-in-out;
position: absolute;
color: yellow;
background-color: green;
width: 100%;
height: 85px;
visibility: hidden;
opacity: 0;
border-radius:10px;
padding:10px;
overflow:hidden;
left:0;
box-sizing:border-box;
}
.ks-wrapper:hover .ks-overlay {
visibility: visible;
opacity: 1;
}
<div class="ks-wrapper">
<div class="ks-button">
<div class="ks-header">
Header
</div>
<div class="ks-content">
Text
</div>
</div>
<div class="ks-overlay">
"K"
</div>
</div>

Slants cross over responsive

Is there anyway to create similar to the attached with HTML/CSS, that works responsive? without using am image?
Unable to get the oragne border & content added in
CSS
.left {
border-bottom: 70px solid #3488b1;
border-right: 1000px solid transparent;
height: 0;
position: absolute;
bottom:0;
width: 1px;
opacity:.5;
}
.right {
border-bottom: 70px solid #3488b1;
border-left: 1000px solid transparent;
height: 0;
width: 1px;
position: absolute;
bottom:0;
}
.footer {height:100px;}
& HTML
<div class="footer">
<span class="left"> </span>
<span class="right"></span>
</div>
One way is to use transforms.
html, body {
height:100%;
width:100%;
}
#responsive {
position:relative;
height:25%;
width:80%;
overflow:hidden;
min-height: 80px;
}
#triOne {
position:absolute;
background-color:aqua;
height:300%;
width:300%;
transform: rotate(10deg);
top:55%;
left:-100%;
}
#triTwo {
position:absolute;
background-color:blue;
height:300%;
width:300%;
border: 5px solid orange;
transform: rotate(-10deg);
top:45%;
right:-100%;
}
#content {
position:absolute;
right:10px;
bottom:10px;
color:white;
}
<div id="responsive">
<div id="triOne"></div>
<div id="triTwo"></div>
<div id="content">content</div>
</div>
It's not really responsive, but I think with a few tweaks you should be able to get it the way you want it.

How can I make this shape?

How can I make the following with HTML and CSS, when I have been provided with background-image.
<span class='some-cl'> defence personnel </span>
So a variation of it is possible with CSS, but my version is the ugliest piece of shit you'll find. Check it out: http://jsfiddle.net/7s4L0jhy/
I have an extra element for the half circle thing, but other than that, it's all variable according to the text in your element.
.p {
border: 3px solid #fff;
border-top: 0;
display: inline-block;
margin: 0 auto;
padding: 30px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
And then I create the top bar, but leave space for the circle:
.p:before {
content: '';
position: absolute;
right: calc(50% + 35px);
left: -3px;
height: 3px;
top: 0;
background: #fff;
}
.p:after {
content: '';
position: absolute;
left: calc(50% + 35px);
right: -3px;
height: 3px;
top: 0;
background: #fff;
}
And lastly, the fake circle thingy:
.p .bar {
position: absolute;
height: 70px;
width: 70px;
border-radius: 50%;
border: 3px solid #fff;
border-left: 0;
border-bottom: 0;
border-right: 0;
top: -30px;
left: 50%;
transform: translateX(-50%);
}
As per the other answer, an image would definitely be easier for you, but this should work for anything ie10+. Good luck.
There are many approaches to solve this. However I think the requirement here is high scalability, that is we can change the size of the outside element (the wrapper) and the shape should keep scaling accordingly. Doing so requires a little trick relating to overflow:hidden, the top shape includes a nearly half circle at center and the 2 lines besides, the trick here is we need to fix the ends (of the 2 lines) connecting to the nearly half circle and let the other ends free, so that when scaling up/down the overflow:hidden will cut off those ends if there is any error in calculation.
Here is the code:
HTML:
<div class='frame'>
<div class='top'>
<div class='peak'></div>
</div>
<div class='content'>
Defense personnel
</div>
</div>
CSS:
.frame > .top, .top > .peak {
position:absolute;
}
.frame {
position:relative;
}
.frame > .top {
overflow:hidden;
left:-3px;
right:-3px;
padding-top:100%;
bottom:100%;
}
.frame > .top:before, .frame > .top:after {
content:'';
position:absolute;
border-top:3px solid white;
width:30%;
bottom:0;
}
.frame > .top:before {
right:70%;
}
.frame > .top:after {
left:70%;
}
.top > .peak {
border:3px solid white;
border-radius:50%;
left:50%;
width:40%;
padding-top:40%;
bottom:0;
-webkit-transform:translate(-50%,44%);
}
.frame {
width:300px;
height:200px;
margin-top:100px;
border:3px solid white;
border-top:0;
}
.frame > .content {
width:100%;
height:100%;
text-align:center;
padding-top:20px;
font-size:30px;
color:white;
}
body {
background:url(http://lorempixel.com/800/600);
}
Demo.
Try resizing the .frame and you'll see how flexable it is.
.some-cl{background:#003 /*bg color*/ url(your_image.jpg) no-repeat 50%; text-transform:uppercase; text-align:center; padding-top:40px /*adjust at will */ }
there are better and more complex methods, but since you're asking extremely basic CSS questions, I assume this should be enough

how to make a div with transform: translate 3d stack up on top of a masked layer ( not working despite Z-index being higher)

I am trying to make a div with transformation(CSS) stack up on top; here is the markup, I need only the green div to show up on top of blue div. Basically the blue is a masked layer and the green is a dialog that shows up on top of it.
I tried setting the z-index, which din't work. The blue always shows up on top of the green.
Also if I change the blue div to be the sibling of the the green div then it works, but I want to keep the mark up the same i.e the blue div is a sibling parent to green div
Any pointers?
Here is the js fiddle link...
http://jsfiddle.net/YRTxt/9/
CSS
#wrapper{
width:100%;
}
#red, #green{
height:200px;
width:400px;
}
#red{
background-color:red;
position:absolute;
-webkit-transform: scale(1);
}
#pink{
background-color:pink;
height:250px;
width:150px;
top: 50px;
position:absolute;
-webkit-transform: translate3d(0%,0px,0px);
-webkit-perspective: 1000;
}
#green{
background-color:green;
position:absolute;
-webkit-transform: translate3d(0,0,0);
top:100px;
right: 0px;
left: 0px;
z-index: 1111;
}
#blue{
background-color: blue;
width: 100%;
height: 100%;
opacity: 0.8;
position: absolute;
top:0px;
right: 0px;
z-index: 100;
}
HTML
<div id="wrapper">
<div id="red">
<div id="pink">
<div id = "green"/>
</div>
</div>
</div>
<div id="blue">
</div>
For z-index to work you have to have a z-index for both elements. I updated the http://jsfiddle.net/rTkyR/, where I only added the z-index to the CSS two the blue and the green divs.
HTML
<div id="wrapper">
<div id="red">
<div id="pink">
<div id = "green"/>
</div>
</div>
</div>
<div id="blue">
</div>
CSS
#wrapper{
position:relative;
width:100%;
}
#red, #green{
height:200px;
width:400px;
}
#red{
background-color:red;
position:relative;
}
#pink{
background-color:pink;
height:250px;
width:150px;
top:50px;
right:20px;
position:absolute;
}
#green{
background-color:green;
position:absolute;
-webkit-transform: translate3d(0,0,0);
top:0px;
right: 0px;
left: 0px;
z-index: 1;
}
#blue{
background-color: blue;
width: 100%;
height: 100%;
opacity: 0.8;
position: absolute;
top:0px;
right: 0px;
z-index: 0;
}

Thumbnail rollover with text

I'm using the following CSS code to do a rollover effect with text:
.thumb {
position:relative;
}
.thumb img:hover {
filter:alpha(opacity=0);
-moz-opacity:0;
-khtml-opacity:0;
opacity:0;
}
.thumb:hover {
background:#f00;
}
.thumb span {
z-index:-10;
position:absolute;
top:10px;
left:10px;
}
.thumb:hover span {
z-index:10;
color:#fff;
}
HTML code:
<div class="thumb">
<img src="thumbnail.jpg" />
<span>Text</span>
</div>
Everything is working well except when I hover over the text: the rollover effect disappears and I can see the image again.
Any ideas?
Thanks in advance
I guess that is too much of styles for simple overlay effect, if you are interested to see a demo I've made from scratch than here you go
Demo
HTML
<div class="wrap">
<img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
<div class="overlay">Hello This Is So Simple</div>
</div>
CSS
.wrap {
position: relative;
display: inline-block;
}
.overlay {
opacity: 0;
background: rgba(0,0,0,.8);
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
transition: opacity 1s;
color: #fff;
text-align: center;
}
.wrap:hover .overlay {
opacity: 1;
}