I want to make a "roll over text" when you hover the image container.
I did it fine, but only with position absolute, but i cant get it right with position relative.
Now the Text comes after the Image but i need the text as an small overlay to the bottom of the image
<div class="ce_image team block">
<figure class="image_container">
<img src="assets/images/c/De****-D1-6a7e730c.jpg" width="300" height="300" alt="">
<figcaption class="caption" style="width:300px">The text i want to display on hover</figcaption>
</figure>
</div>
css: (ps: i quess my css is really bad, never made smth like this)
.image_container {
position: relative;
display: inline-block;
padding: 0.75em;
border: 1px solid #b2b9c4;
border-radius: 2px;
background: #ffffff;
background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.team .image_container figcaption, .team .image_container .caption {
width: 100% !important;
padding: 0.42857em 0 0;
font-size: 1.0em;
display: none !important;
display: fixed;
color: #000000;
font-weight: bold;
position: static !important;
text-align: center;
top: 100px;
z-index: 999;
opacity: 0;
transition: opacity 0.2s linear !important;
left: 0px;
background: rgba(255, 255, 255, 0.9);
position: relative;
}
.team .image_container:hover figcaption, .team .image_container:hover .caption {
width: 100% !important;
padding: 0.42857em 0 0;
font-size: 1.0em;
color: #000000;
font-weight: bold;
text-align: center;
top: -31px;
z-index: 999;
opacity: 1;
left: 0px;
background: rgba(255, 255, 255, 0.9);
position: relative;
display: block !important;
}
Fiddle with css here:
https://jsfiddle.net/vm73gfhn/
I updated some of your CSS so that the text sits at the bottom. You need position absolute rather than position relative:
.image_container {
position: relative;
display: inline-block;
padding: 0.75em;
border: 1px solid #b2b9c4;
border-radius: 2px;
background: #ffffff;
background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.team .image_container figcaption, .team .image_container .caption {
display: none !important;
}
.team .image_container:hover figcaption, .team .image_container:hover .caption {
width: 100% !important;
padding: 0.42857em 0 0;
font-size: 1.0em;
color: #000000;
font-weight: bold;
text-align: center;
bottom: 0px;
z-index: 999;
opacity: 1;
left: 0px;
background: rgba(255, 255, 255, 0.9);
position: absolute;
display: block !important;
}
JSFIDDLE
Additional
If you want it to work for mobile and tablets then use media queries:
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
Related
I designed this button in Figma but when I copy the CSS properties from the inspect section from Figma I won't get the same output, what I'm doing wrong here?
Figma file: https://www.figma.com/file/r3z3qwUsYGsn9SVDefWVoM/problem?node-id=2%3A6
div {
display: flex;
justify-content: center;
align-items: left;
height: 100%;
text-align: center;
}
button {
width: 300px;
height: 64px;
border: none;
line-height: 23px;
text-align: center;
letter-spacing: 0.666667px;
color: #000000;
font-weight: 400;
font-size: 16px;
background: linear-gradient(135.37deg, rgba(0, 0, 0, 0.35) 4.29%, rgba(255, 255, 255, 0.35) 95.6%);
background-blend-mode: soft-light;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.15), -5px -5px 10px #FAFBFF, 5px 5px 10px rgba(190, 106, 255, 0.3);
border-radius: 20px;
}
<div>
<button>Wednesday</button>
</div>
I want the button to be like that
and this is what i'm getting right now
Unfortunately, button shadows won't show through the button's body, even if the body is transparent. You will have to find another way to render a very rich button like that.
See my proof of concept below.
You can also find a detailed explanation at https://stackoverflow.com/a/9573440/46915
body {
background: #777;
}
div {
display: flex;
justify-content: center;
align-items: left;
height: 100%;
text-align: center;
}
button {
position: absolute;
width: 300px;
height: 64px;
background-color: transparent;
background-repeat: no-repeat;
border: none !important;
/*background: linear-gradient(135.37deg, rgba(0, 0, 0, 0.35) 4.29%, rgba(255, 255, 255, 0.35) 95.6%);*/
background-blend-mode: soft-light;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.15), -5px -5px 10px #FAFBFF, 5px 5px 10px rgba(190, 106, 255, 0.3);
border-radius: 20px;
}
<div>
<button>Wednesday</button>
</div>
To get figures on one above the other, currently I am using the below method:-
<div id="box_cgf" class="box red"><figure class="c-green" id="cg1"><figure class="c-yellow" id="cy1"></figure></figure></div>
This is like, making one figure as parent and another as child. But, I do not want to use parent-child method. I would like to use as below:
*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.clearfix::after {
clear: both;
content: "";
display: table;
}
.container {
width: 500px;
height: 500px;
margin: auto;
margin-top: 80px;
cursor: pointer;
/* border: 1px solid black; */
}
.container-row1,
.container-row3 {
width: 100%;
height: 40%;
}
.row1-col1,
.row1-col3,
.row3-col1,
.row3-col3 {
height: 100%;
width: 40%;
}
}
.row1-col1,
.row1-col2,
.row1-col3,
.row2-col1,
.row2-col2,
.row2-col3,
.row3-col1,
.row3-col2,
.row3-col3 {
float: left;
}
.row1-col1,
.row1-col3,
.row3-col1,
.row3-col3 {
display: flex;
justify-content: center;
align-items: center;
}
.row1-col1-child,
.row1-col3-child,
.row3-col1-child,
.row3-col3-child {
width: 70%;
height: 70%;
}
.row1-col1-child>div,
.row1-col3-child>div,
.row3-col1-child>div,
.row3-col3-child>div {
width: 35%;
height: 35%;
float: left;
margin: 7.5%;
/* box-shadow: -2px 14px 28px rgba(0, 0, 0, 0.25), -2px 10px 10px rgba(0, 0, 0, 0.22); */
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
}
.row1-col1-child>div:hover,
.row1-col3-child>div:hover,
.row3-col1-child>div:hover,
.row3-col3-child>div:hover {
box-shadow: -2px 14px 28px rgba(0, 0, 0, 0.25), -2px 10px 10px rgba(0, 0, 0, 0.22);
}
.row1-col2>div,
.row3-col2>div {
width: 33.333%;
height: 16.667%;
float: left;
border: 1px solid black;
}
.red {
background-color: #dc2418;
}
.white {
background-color: #fff;
}
.card {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
}
.card:hover {
box-shadow: 0 19px 38px rgba(0, 0, 0, 0.30), 0 15px 12px rgba(0, 0, 0, 0.22);
}
.c-yellow {
display: flex;
align-items: center;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 50%;
height: 90%;
width: 90%;
background: rgb(246, 243, 0);
background: radial-gradient(circle, rgba(246, 243, 0, 1) 5%, rgba(246, 243, 0, 1) 100%);
box-shadow: 1px 1px #888888;
}
.c-green {
display: flex;
align-items: center;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 50%;
height: 90%;
width: 90%;
background: rgb(97, 194, 31);
background: radial-gradient(circle, rgba(97, 194, 31, 1) 5%, rgba(97, 194, 31, 1) 100%);
box-shadow: 1px 1px #888888;
}
<!DOCTYPE html>
<html>
<body>
<div class="container card">
<!-- First row -->
<div class="container-row1 clearfix">
<div class="row1-col3">
<div class="row1-col3-child clearfix white">
<div id="box_cgf" class="box red">
<figure class="c-green" id="cg1"></figure>
<figure class="c-yellow" id="cy1"></figure>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
If you see its not getting one above the other, and its coming out of the div too.
Expected result is:-
I am trying to create a button like this image with PURE CSS. Please could you help me with the CSS ?
This Image
I am trying using below but not giving exact same result -
.styled {
border: 0 !important;
line-height: 2.5;
font-weight: bold;
text-align: center !important;
color: rgba(11,44,20,255) !important;
border-radius: 8px !important;
padding: 5px 16px 5px 16px;
transition: 0.2s all;
background-image: linear-gradient(to top left,
rgba(0, 0, 0, .2),
rgba(0, 0, 0, .2) 100%,
rgba(0, 0, 0, 0)) !important;
box-shadow: inset 7px 7px 3px rgba(255, 255, 255, .6),
inset -7px -7px 3px rgba(0, 0, 0, .7) !important;
}
This is closest as I can get without the button background. You can try experimenting with CSS gradients until you hit the actual angle.
#button{
width: 69px;
height: 34px;
position: relative;
background: #3F4E4C;
background: -webkit-radial-gradient(bottom right, #3F4E4C, #7CD9BA);
background: -moz-radial-gradient(bottom right, #3F4E4C, #7CD9BA);
background: radial-gradient(to top left, #3F4E4C, #7CD9BA);
border: none;
outline: none;
border-radius: 8px;
}
#external{
position: absolute;
top: 6px;
left: 6px;
background: #3ade66;
width: calc(100% - 12px);
height: calc(100% - 12px);
border-radius: 6px;
text-align:center;
color: black;
line-height: 2.2;
font-size: 10px;
font-weight: bold;
}
<button id="button">
<div id="external">Start</div>
</button>
Add an onclick event to the image.
function myFunction() {
alert("Button clicked");
};
img {
/*Disables dragging of the image*/
-webkit-user-drag: none;
-khtml-user-drag: none;
-moz-user-drag: none;
-o-user-drag: none;
user-drag: none;
/*Sets the mouse to pointer when hovered*/
cursor: pointer;
}
<img src="https://i.stack.imgur.com/Rggof.png" onclick="myFunction();">
Got the similar view using -
.styled {
border: 0 !important;
line-height: 2.5;
font-weight: bold;
text-align: center !important;
color: rgba(11,44,20,255) !important;
border-radius: 10px !important;
transition: 0.2s all;
background-image: linear-gradient(to top left,
rgba(0, 0, 0, .2),
rgba(0, 0, 0, .2) 100%,
rgba(0, 0, 0, 0)) !important;
box-shadow: inset 6px 6px 1px rgba(255, 255, 255, .3),
inset -6px -6px 1px rgba(0, 0, 0, .3) !important;
}
The below code works well on all browsers except Internet Explorer.
In IE the wording seems to be compressed to 1px height or covered by the hr gradient.
What's causing this problem?
.hr-how {
text-align: center;
border: 0;
height: 1px;
margin-bottom: 40px;
margin-top: 40px;
background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
}
.hr-how:after {
content: "HOW TO USE IT";
display: inline-block;
position: relative;
top: -0.7em;
font-size: 0.9em;
padding: 0 0.6em;
background: white;
}
<hr class="hr-how" id="hr-how">
http://jsfiddle.net/y8nx51rf/
This is happening because the default setting for overflow on hr tags is visible in Chrome and Firefox but hidden in IE. This causes any content outside the height of the hr to be cut off in IE.
To make this work in IE add overflow: visible; to .hr-how so the text can extend outside the boundaries of the hr.
.hr-how {
background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
border: 0;
height: 1px;
margin-bottom: 40px;
margin-top: 40px;
overflow: visible;
text-align: center;
}
.hr-how:after {
background: white;
content: "HOW TO USE IT";
display: inline-block;
font: "BodoniXT" !important;
font-size: 0.9em;
padding: 0 0.6em;
position: relative;
top: -0.7em;
}
<hr class="hr-how" id="hr-how" />
I want to apply this code:
/* Glossy overlay */
html {
min-height: 100%;
background: linear-gradient(#000, #445);
}
figure {
width: 162px;
height: 162px;
margin: 24px auto;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
border-radius: 5px;
}
figure img {
display: block;
border-radius: 5px;
}
figure:after {
position: absolute;
pointer-events: none;
content: '';
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 5px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
-webkit-mask-image: linear-gradient(#000, transparent);
mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<figure>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</figure>
But I don't want to apply it on a div element, I want to apply it on every single photo (through a img How can I do that?
I want to apply it on every single photo (through a img)
If every image is inside an <a>, all you need to do is change the CSS to target a, a img and a:after. Ensure that the <a> is display: block or display: inline-block;
Example
/* Glossy overlay */
html {
min-height: 100%;
background: linear-gradient(#000, #445);
}
a {
display: inline-block;
width: 162px;
height: 162px;
position: relative;
box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
border-radius: 5px;
}
a img {
display: block;
border-radius: 5px;
}
a:after {
position: absolute;
pointer-events: none;
content: '';
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 5px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
-webkit-mask-image: linear-gradient(#000, transparent);
mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
<img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>