I would like to make an overlay on my site to prevent user from clicking somewhere. It's sometimes very handy. In the middle of the overlay I want to place a message like "please wait.." or "loading...".
I've made a div, which covers the whole screen and a span inside of it, which contains the message. I managed to center the span inside the div horizontally, but I'm struggling with the vertical alignment of it. The message should be also vertically centered.
Here is my code so far:
HTML:
<div id="overlay">
<span>Please wait...</span>
</div>
CSS:
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: center;
background-color: #000;
filter: alpha(opacity=50);
-moz-opacity: 0.5;
opacity: 0.5;
}
#overlay span {
padding: 5px;
border-radius: 5px;
color: #000;
background-color: #fff;
}
Here is the jsfiddle.
So, how do I get the span with the message vertically centered?
LIke this
DEMO
add below select in position:relative or top:50%;
CSS
#overlay span {
padding: 5px;
border-radius: 5px;
color: #000;
background-color: #fff;
position:relative;
top:50%;
}
Besides that if the Center object is bigger in height & width, you can give negative margins exactly half of the same.
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: center;
background-color: #000;enter code here
filter: alpha(opacity=50);
-moz-opacity: 0.5;
opacity: 0.5;
}
#overlay span {
padding: 5px;
border-radius: 5px;
color: #000;
background-color: #fff;
height:100px;
width:100px;
position:absolute;
top:50%;
left:50%;
margin-left:-50px;
margin-top:-50px;
display:block;
}
Related
I'm required to have a rounded "growing" effect upon hovering over a button.
Please see this link for a reference of how I need the button to work.
http://demo1.wpopal.com/corpec/home-4/
Currently I have achieved the "Not this" effect upon hover; though my employer wants the effect to have that bit of rounding.
I used the following css on the "not this" button to achieve the growing effect, though i need the edges to be rounded.
.Custom-Button a {
position: relative;
display: inline-block;
padding: 15px 70px;
border: 1px solid #fdc900 !important;
color: white;
font-size: 30px;
font-family: arial;
background-image: linear-gradient(#fdc900, #fdc900);
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: 0% 100%;
transition: background-size .5s, color .5s;
}
.Custom-Button a:hover {
background-size: 100% 100%;
color: black;
}
<div class="Custom-Button">
BUTTON
</div>
I'm only allowed to use CSS to achieve the following effect and have already spent a day trying to get this to work.
applying pseudo element for button solve it ! hope this help!
.Custom-Button{
position: relative;
display: inline-block;
padding: 15px 70px;
border: 1px solid #fdc900 !important;
color: white;
font-size: 30px;
font-family: arial;
border-radius:50px;
position:relative;
}
.Custom-Button a{
z-index:99;
text-decoration:none;
transition:color 1s;
}
.Custom-Button:hover:after{
width:100%;
}
.Custom-Button:hover a{
color:black;
}
.Custom-Button:after{
width:0%;
transition: width 1s;
height:100%;
z-index:-1;
content:"";
position:absolute;
border-radius:50px;
top:0;
left:50%;
transform:translateX(-50%);
background-image: linear-gradient(#fdc900, #fdc900);
}
<div class="Custom-Button">
BUTTON
</div>
You can achieve this effect, by combining z-index, and transitions of position and width of an underlying element:
When hovering, the child of the filler, will transition from
position: absolute; left: 50%;
to
position: absolute; left: 0;
while also resizing from width: 0; to width: 100%;
This is what will give you the desired effekt of "growing from the middle"
also you need to apply a border radius to your growing element
a {
position: relative;
display: inline-block;
padding: 15px 70px;
border: 1px solid #fdc900 !important;
color: black;
font-size: 30px;
font-family: arial;
border-radius: 32px;
}
.text {
position: relative;
z-index: 2000;
}
.filler {
position: absolute;
z-index: 1000;
top: 0;
left: 50%;
width: 0;
height: 100%;
border-radius: 32px;
/* half of <a> height */
background-color: #fdc900;
transition: width .5s, color .5s, left .5s;
}
a:hover .filler {
z-index: 500;
width: 100%;
left: 0;
color: black;
}
a:hover .text {
color: white;
}
<a href="#">
<div class="text">
BUTTON
</div>
<div class="filler">
</div>
</a>
I have a div which has an image as the background and some text over it in an other div. Here is the HTML
.profilePic{
width:190px;
height: 190px;
border-radius: 50%;
background: #FFF;
float: left;
margin:12px;
background: #ededed;
background-image: url("https://www.meggle-pharma.com/images/meggle_icons/company-aktiv-190x190.png");
}
.profilePic:hover{
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
color:#FFF;
}
.name{
font-family: Tahoma;
font-size: 1.5em;
color: red;
margin-top: 42%;
display: none;
}
.profilePic:hover .name {
display:block;
}
<div class='profilePic one'>
<center>
<div class='name'>Name</div>
</center>
</div>
With this code, when I hover on the div named profilePic, the div gets a filter applied on top of it. I dont what the filter on the text, i.e, the div named name but only on the profilePic div. How can I do it?
You need to separate the text from the picture.
Use a container div with a div inside that has the image with background-image.
Use another div inside to display the text
Apply all the effect on container hover
DO NOT use margin-top in percentage but instead, if you want to center the text, add position:relative; to the container and this to the text:
position: absolute; to positioned it.
top: 50%; to place it at 50% of the left
left: 50%; to place it at 50% of the top
transform: translate(-50%, -50%); to pull it at 50% of its width and height to the left and top because when you do left: 50%: for example, it will put the left border of the element at 50% and not the middle of it.
So you need to pull it left a 50% of its proper width to have it horizontally centered according to its parent.
.profilePic{
display: inline-block;
width:190px;
height: 190px;
border-radius: 50%;
background: #FFF;
margin:12px;
background: #ededed;
background-image: url("https://www.meggle-pharma.com/images/meggle_icons/company-aktiv-190x190.png");
}
.profilePicContainer {
position: relative;
display: inline-block;
}
.profilePicContainer:hover .profilePic{
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
color:#FFF;
}
.profilePicContainer:hover .name {
display: block;
}
.name{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: Tahoma;
font-size: 1.5em;
color: red;
display: none;
}
<div class="profilePicContainer one">
<div class="profilePic"></div>
<div class="name">Name</div>
</div>
You can use a pseudo-element as an overlay above the background and below the text and apply CSS on it. Doing this you will only affect the background and not the text.
Here is an example where the overlay will also contain the same background image with the filter applied on it and I simply show it on hover:
.profilePic {
width: 190px;
height: 190px;
border-radius: 50%;
background: #FFF;
float: left;
text-align:center;
margin: 12px;
background: #ededed;
position:relative;
overflow:hidden;
background-image: url("https://www.meggle-pharma.com/images/meggle_icons/company-aktiv-190x190.png");
}
.profilePic:before {
content:"";
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
background-image: url("https://www.meggle-pharma.com/images/meggle_icons/company-aktiv-190x190.png");
transition:0.5s;
filter:grayscale(100%);
opacity:0;
}
.profilePic:hover::before {
opacity:1;
}
.profilePic:hover {
color: #fff
}
.name {
font-family: Tahoma;
font-size: 1.5em;
color: red;
margin-top: 42%;
display: none;
position:relative;
z-index:1;
}
.profilePic:hover .name {
display: block;
}
<div class='profilePic one'>
<div class='name'>Name</div>
</div>
You can also simply use a background color with opacity:
.profilePic {
width: 190px;
height: 190px;
border-radius: 50%;
background: #FFF;
float: left;
text-align:center;
margin: 12px;
background: #ededed;
position:relative;
overflow:hidden;
background-image: url("https://www.meggle-pharma.com/images/meggle_icons/company-aktiv-190x190.png");
}
.profilePic:before {
content:"";
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
transition:0.5s;
}
.profilePic:hover::before {
background:rgba(0,0,0,0.7);
}
.profilePic:hover {
color: #fff
}
.name {
font-family: Tahoma;
font-size: 1.5em;
color: red;
margin-top: 42%;
display: none;
position:relative;
z-index:1;
}
.profilePic:hover .name {
display: block;
}
<div class='profilePic one'>
<div class='name'>Name</div>
</div>
I have a div that displays an image and then has a half height semi transparent block on which I write text. This is done using some code from this site that utilizes "before". How do I hide this transparent block on hover? I've tried all I can think of. I can't use a standard transparent image because the image is different on each instance of the div and they aren't on site. The use of :before in this way is not something I fully understand but suspect it is complicating matters.
.summary_props_trans {
position: relative;
font-family:'Melbourne', Arial, sans-serif;
font-size: 2vmin;
color: black;
font-weight:normal;
z-index: 0;
width: 220px;
height: 165px;
margin: 5px;
float: left;
padding: 5px 10px 10px 5px;
background-repeat: no-repeat;
background-size:cover;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
}
.summary_props_trans:hover {
filter:alpha(opacity=80);
-moz-opacity:0.8;
-khtml-opacity: 0.8;
opacity: 0.8;
}
.summary_props_trans:before{
content:'';
display: block;
position: absolute;
background: white;
opacity: .5;
filter:alpha(opacity=50);
top: 0; right: 0; bottom: 0; left: 0;
margin: 0px 0px 50px 0px;
z-index: -1;
}
If you simply wish to apply styles to .summary_props_trans :before pseudo-element when the .summary_props_trans element matches a pseudo-class, you need to write .summary_props_trans:hover:before or .summary_props_trans:visited:before instead. Notice the pseudo-element comes after the pseudo-class (and in fact, at the very end of the entire selector).
so, Simply add
.summary_props_trans:hover:before{
display:none;
}
or
.summary_props_trans:hover:before {
filter:alpha(opacity=0);
-moz-opacity:0;
-khtml-opacity: 0;
opacity: 0;
}
Here's an Example http://jsfiddle.net/dyaa/kn0z52ya/
I'm trying to get a trapezoidal perspective shape to have the whole area be clickable. I've gotten it to work in Firefox and even IE, but Chrome isn't cooperating too well.
Here's a fiddle with the shape and a link: http://jsfiddle.net/9n9uh6f6/1/
As you can tell, the link doesn't become active until you hover over the 'area' part of the text. In other browsers, the whole height of the shape is clickable.
I read that Chrome renders a perspective image differently and perhaps that's why it's not doing what it's supposed to.
Here's my CSS:
.prodcaptions {
width:136px;
height: 85px;
position:relative;
left:10%;
text-transform:uppercase;
text-align:center;
letter-spacing: 1.6px;
color: #000;
}
.prodcaptions:before {
content:"";
position:absolute;
border-radius:1px;
box-shadow:0 0 0 3px #27628e;
top:-5%;
bottom:-11%;
left:-1%;
right:-5%;
-webkit-transform:perspective(40em) rotateX(-45deg);
transform:perspective(40em) rotateX(-45deg);
}
.prodcaptions a {
z-index:999;
position:relative;
height: 85px;
display: block;
padding-top: 25px;
}
Please have look at this code:
.prodcaptions {
position: relative;
height: 150px;
width: 150px;
margin: 50px;
padding: 10px;
perspective: 150px;
perspective-origin: 50% 0;
}
a{
padding: 50px;
position: absolute;
border: 1px solid black;
transform: rotateX(-15deg);
}
Seems to work the way you want it. fiddle
Try this shape for link trapazoid shape - jsFiddle
Advantage - you can change skew property to change angle of shape! Easy and effective! Reverse value for reverse shape!
html
Click Here!
css
a {
display: block;
z-index: 1;
position: relative;
/* custom sizes */
width: 136px;
height: 85px;
/* demo-only decoration */
margin: 100px auto;
font: 16px/50px Arial, sans-serif;
text-transform: uppercase;
text-align: center;
background-color: orange;
}
a:before, a:after {
content:'';
position: absolute;
top: 0;
left: 0;
width: 100%;
bottom: 0;
z-index: -1;
/* demo-only decoration */
border-radius: 4px;
background-color: orange;
}
a:before {
transform: skew(-20deg);
left: 25px;
}
a:after {
transform: skew(20deg);
right: 25px;
left: auto;
}
I have an image wrapper in which i want to show a button on mouse hover with a black background. I tried to do it but it added a white space to the container at the bottom, i dont know why.
HTML:
<div class="tour-box-wrapper" style="margin-right:45px">
<div class="image-wrapper">
<img src="http://static.teambuy.ca/deal/540x254/other/28165573-2014-03-03-28144457-boxhouse-10b.jpg" />
<a><button type="button" class="view-deal-button" >View Deal</button></a>
</div>
</div>
CSS:
.tour-box-wrapper
{
width:45%;
border: 1px solid #BBB;
padding:2px;
background-color: #E7E7E7;
background-image: -webkit-gradient(linear,left top,left bottom,from(#FFFFFF),to(#E7E7E7));
background-image: -webkit-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -moz-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -ms-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: -o-linear-gradient(top,#FFFFFF,#E7E7E7);
background-image: linear-gradient(to bottom,#FFFFFF,#E7E7E7);
float:left;
display:block;
}
.image-wrapper
{
border:1px solid #E0E0E0;
padding:2px;
display: block;
}
.image-wrapper img
{
width:100%;
}
a.grayscale {
display: inline-block;
background: black;
padding: 0;
}
a.grayscale img {
display: block;
}
a.grayscale:hover img
{
opacity: 0.5;
}
.view-deal-button
{
border: none;
text-align: center;
border-radius: 6px;
text-align: center;
z-index: 999;
position: relative;
left: 343px;
bottom: 36px;
background-color: #CD277B;
padding:6px;
}
.view-deal-button a
{
color:white;
font-size:14px;
}
Note ignore the Javascript which i know will be used to display button on mouse enter but i just want to fix this extra space below the image and want to bring the button to the bottom right corner of the image.
JSFiddle
Your button having a position of 'relative' is what's creating the space that the bottom. It's 'mass' is affecting its parent container. If you don't want it having any 'mass', try positioning it 'absolute' relative to the parent.
This happens because of the relative positioning and the bottom property.
.view-deal-button {
background-color: #CD277B;
border: medium none;
border-radius: 6px;
bottom: 36px;
left: 343px;
padding: 6px;
position: relative;
text-align: center;
z-index: 999;
}
Moving the button right and under the image.
.view-deal-button {
border: none;
border-radius: 6px;
text-align: center;
float: right;
margin: 5px 0;
background-color: #CD277B;
padding:6px;
}
http://jsfiddle.net/b4r3p/3/
Try this css for button
.view-deal-button
{
border: none;
text-align: center;
border-radius: 6px;
text-align: center;
z-index: 999;
position: relative;
left: 343px;
bottom: 36px;
background-color: #CD277B;
padding:6px;
margin: 0% 0% 0% -80%;
}
check this fiddle