I'm trying to center this popup but I can't seem to get it to work properly on smaller screens like iphone. It looks okay on desktop/laptop screens. Can anyone suggest any ideas how to use media queries to get it the popup to be centered properly regardless of screen size? thanks.
<style type="text/css">
#popup {
display: none;
background: #FFF;
border: 5px solid #444;
padding: 0 15px 15px 15px;
position: fixed;
top: 20%;
left:35%;
width: 25%;
min-width: 210px;
z-index: 100000;
box-shadow: 0 0 10px #000;
border-radius: 5px;
text-align: center;
}
#popup-overlay {
display: none;
background: #000;
opacity: 0.5;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
}
</style>
The easiest way to do this is to use a transform to centre the element. This will work no matter the width / height of the element
html, body {
height: 100%;
margin: 0;
}
#popup {
/*display: none;*/
background: #FFF;
border: 5px solid #444;
padding: 15px;
position: fixed;
width: 25%;
min-width: 210px;
z-index: 100000;
box-shadow: 0 0 10px #000;
border-radius: 5px;
text-align: center;
top: 50%;
left:50%;
transform: translate(-50%, -50%)
}
#popup-overlay {
/*display: none;*/
background: #000;
opacity: 0.5;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
}
<div id="popup-overlay"></div>
<div id="popup">Look at me!</div>
Can you try this,
#popup {
display: none;
background: #FFF;
border: 5px solid #444;
padding: 0 15px 15px 15px;
position: fixed;
top: 20%;
left: 50%;
width: 25%;
margin-left: -25%;
min-width: 210px;
z-index: 100000;
box-shadow: 0 0 10px #000;
border-radius: 5px;
text-align: center;
box-sizing: border-box;
}
Note:
It is better to add some jsfiddle like url instead of providing partial details make easy to understand and workout.
left:50%;
margin-left:-120px;
(210 / 2) + 15 = 120
I would move the object to the center and then to the right the half of its size.
As the object width is not fixed, use transform to do that:
#popup {
...
left:50%;
transform: translate(-50%);
...
}
Despite transform is not available in IE8 and below, may be a good solution.
http://jsfiddle.net/fvLtd068/
For html5 enabled browsers use:
#popup {
background: #FFF;
border: 5px solid #444;
padding: 0 15px 15px 15px;
position: fixed;
/* top: 20%; */ //Remove
/* left: 35%; */ //Remove
/* width: 25%; */ //Remove
left: 50%; // Insert
top: 50%; // Insert
transform: translate3d(-50%, -50%, 0); // Insert
min-width: 210px;
z-index: 100000;
box-shadow: 0 0 10px #000;
border-radius: 5px;
text-align: center;
}
Related
I am building a webpage with cards arranged in a grid.
However, I would like my cards to have a unique shape, rather than just being rectangles. The shape I would like them to be is the shape of a manilla folder (pictured below)
Is there any relatively simply way to make a div with this shape?
Here is a start using only html and css:
body {
padding: 50px;
}
div {
position: relative;
z-index: 1;
white-space: nowrap;
}
div .slant {
position: relative;
display: inline-block;
color: inherit;
text-decoration: none;
margin: 0 -14px -4px;
width: 40px;
}
div .slant::before,
main {
border: 0.2em solid #000;
background: #000;
}
div .slant::before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0.5em;
left: 0;
z-index: -1;
border-bottom: none;
border-radius: 5px 5px 0 0;
background: #000;
transform: perspective(5px) rotateX(2deg);
transform-origin: bottom;
}
div.left .slant {
padding: 1.5em 2em 1em 1em;
}
div.left .slant::before {
transform-origin: bottom left;
}
main {
display: block;
margin: -8px 0 30px -14px;
padding: 1em;
border-radius: 0 5px 5px 5px;
width: 200px;
height: 300px;
}
<div class="left">
<div class="slant"></div>
</div>
<main>
</main>
It took me about 10 minutes just to do that, so if you have the motivation to improve it, feel free to do so. It is possible to do it with divs and positioning with CSS. It's just a matter of playing with z-index and shapes, but unless you just wan't to impress yourself for achieving it, the easiest way is to create a background image and move your html content over it.
I am not the best front-end programmer either so don't be arshe! I'm sure someone else could improve it even better with outline borders and stuff.
div#panel {
position: absolute;
border: 3px solid black;
border-radius: 10px;
width: 200px;
height: 200px;
background-color: white;
top: 50%;
left: 50%;
z-index: 3;
transform: translate(-50%, -50%);
}
div#box {
position: absolute;
border: 3px solid red;
z-index: 0;
border-radius: 10px;
width: 200px;
height: 200px;
top: 48.5%;
left: 50%;
z-index: ;
transform: translate(-50%, -50%);
}
div#box2 {
position: absolute;
border: 3px solid red;
border-radius: 10px;
width: 80px;
height: 200px;
background-color: white;
top: 47%;
left: 46.9%;
z-index: 1;
transform: translate(-50%, -50%);
}
<div id="panel"></div>
<div id="box">
<p style="padding-left: 5px;"> Some text here</p>
</div>
<div id="box2"></div>
You can use this shape as the background-image of the card. Remove the card default property like background-color, box-shadow...
HTML:
<div class="main-class">
<div class="card">
.....
</div>
</div>
CSS:
.main-class .card{
background-image: url("path");
background-repeat: no-repeat;
background-size: cover;
background-color: transparent;
box-shadow: none;
}
Is it possible to create a shape like this using the CSS border?
I saw some other stack overflow posts regarding making some border modifications, but nothing specifically like this. Can someone point me in the right direction?
Thanks
Based on https://css-tricks.com/examples/ShapesOfCSS/:
#base {
background: red;
display: inline-block;
height: 30px;
margin-left: 20px;
margin-top: 55px;
position: relative;
width: 200px;
text-align: center;
}
#base:before {
border-bottom: 15px solid red;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
content: "";
height: 0;
left: 0;
position: absolute;
top: -15px;
width: 0;
}
<div id="base"><span>BACK TO TOP</span></div>
Just modify the width and height for your needs, it is really easy.
You can create this shape using css :before and :after selectors:
#back {
background: #fff;
border:1px solid #333;
display: inline-block;
height: 20px;
margin-left: 20px;
margin-top: 55px;
position: relative;
width: 120px;
text-align: center;
}
#back:before {
border-bottom: 15px solid #fff;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
content: "";
height: 0;
left: 0;
position: absolute;
top: -15px;
width: 0;
z-index:2;
}
#back:after {
border-bottom: 15px solid #333;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
content: "";
height: 0;
left: 0;
position: absolute;
top: -16px;
width: 0 ;
z-index:1;
}
<div id="back"><span>Back to Top</span></div>
Fully adaptive and transparent...
* {
margin: 0;
padding: 0;
}
body {
position: relative;
width: 100vw;
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, .7) 0, rgba(0, 0, 0, .7) 100%), url('http://beerhold.it/1024/600');
background-repeat: no-repeat;
background-size: cover;
}
.border-arrow-top {
display: inline-block;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: white;
text-align: center;
font-size: 6vh;
text-transform: uppercase;
padding: 0 10vw;
padding-bottom: 2vh;
border: 3px solid white;
border-top: none;
position: relative;
}
.border-arrow-top:before,
.border-arrow-top:after {
content: '';
position: absolute;
top: 0%;
border-top: 3px solid white;
width: 50%;
}
.border-arrow-top:before {
left: 0;
transform-origin: -3px -50%;
/* x-coord: -[size of border] */
transform: skewy(-10deg);
}
.border-arrow-top:after {
right: 0;
transform-origin: calc(100% + 3px) -50%;
/* x-coord: 100% + size of border */
transform: skewy(10deg);
}
<div class="border-arrow-top">
Back to Top
</div>
I had written a tutorial for the same, arrow heads and triangles with CSS which can be read here: http://time2hack.com/2014/10/triangles-and-arrow-heads-css.html.
The trick works on the basis of borders and their colors. The direction in which arrow has to point; border of that side can be 0 and rest of the sides will create the arrow head.
The main role will be of opposite side border; if arrow has to point to top, border-bottom will create the arrow and rest can be transparent and if arrow has to point to bottom, the border-top will be of some color and other will be transparent. Similar is for arrow pointing left and right.
The transparent color will work fine in all browser except IE8 and below; for this you can set the color to the matching background, so that it is not visible.
By customizing the fiddle http://jsfiddle.net/95Xq8/ The given below is the output
Check the fiddle
.arrow-wrap{ width:125px; margin:auto; padding:100px 0;}
.arrow-button {
width: 125px;
height: 50px;
line-height: 50px;
position: relative;
background: #f00;
text-align: center; text-decoration:none; color:#000; display:block;
color:#fff;
}
.arrow-tip {
display: block;
width: 101px;
height: 115px;
margin: 0;
-webkit-transform: rotate(45deg) skew(-18deg,-23deg);
}
.arrow-tip-container {
display: block;
width: 125px;
height: 40px;
position: absolute;
top: -40px;
left: 0px;
overflow: hidden;
}
.arrow-tip-grad {
display: block;
width: 100%;
height: 100%;
background: red;
}
<div class="arrow-wrap">
<a href="#" class="arrow-button">Back to top
<span class="arrow-tip-container">
<span class="arrow-tip">
<span class="arrow-tip-grad"></span>
</span>
</span>
</a>
</div>
I've looked at some other threads, but nothing seems to work. I'm trying to center a lightbox of an unknown width in the center of the page (horizontally). Any help would be appreciated. The code is as follows.
HTML
<div class="backdrop"></div>
<div class="box">
<div class="close">x</div>
<img src="../pics/placeholder.png">
</div>
CSS
.backdrop {
position: absolute;
text-align: center;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: #000;
opacity: .0;
filter:alpha(opacity=0);
z-index: 50;
display: none;
}
.box {
position: absolute;
top: 20%;
width: auto;
height: auto;
background: #ffffff;
z-index: 51;
padding: 2px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 5px #444444;
-webkit-box-shadow: 0px 0px 5px #444444;
box-shadow: 0px 0px 5px #444444;
display: none;
}
.close {
position: absolute;
padding-left: 5px;
padding-top: 5px;
margin-left: 98%
margin-top: 4px;
cursor: pointer;
font-family: sans-serif;
}
• To center an element horizontally with position: relative use:
.element {
position: relative;
display: inline-block;
margin: 0 auto; /* We don't care about 0, but we do care about auto. */
}
• To center an element horizontally with position: absolute or position: fixed use:
.element {
position: fixed; /* Lightboxes usually use position: fixed. */
left: 50%;
transform: translateX(-50%);
}
How can I do a folded-corner with external shadow which continues to the parent div shadow, like that :
Thanks.
CSS Backgrounds and Borders Module Level 4 introduces the corner-shape property:
By default, non-zero border-radii define a quarter-ellipse that rounds
the affected corners. However in some cases, other corner shapes are
desired. The corner-shape property specifies a reinterpretation
of the radii to define other corner shapes.
In your case, you should set it to bevel:
Border radii define a diagonal slice at the corner.
The code would be something like
corner-shape: bevel;
border-radius: 0 0 30px;
box-shadow: 0 0 5px #000;
However, this spec is a draft not ready for implementation. So browsers haven't implemented it. But you can use corner-shape preview to see how it would look like.
tried this one, a bit complex, but it works
.box {
width: 200px;
height: 100px;
position: relative;
padding: 25px;
background: none;
}
.box .content {
position: relative;
z-index: 2;
}
.box .the_background {
position: absolute;
left: 0;
top: 0;
z-index: 1;
width: 100%;
height: 100%;
}
.box .the_background .square-top-right {
width: 250px;
height: 125px;
position: absolute;
top: 0;
left: 0;
background: #fff;
display: block;
z-index: 3;
}
.box .the_background .square-bottom-left {
width: 225px;
height: 150px;
position: absolute;
bottom: 0;
left: 0;
background: #fff;
display: block;
z-index: 3;
}
.box .the_background:after {
content: '';
width: 35px;
height: 35px;
background: #ddd;
position: absolute;
z-index: 2;
right: 7px;
bottom: 7px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-box-shadow: 0px 0px 10px #000;
-moz-box-shadow: 0px 0px 10px #000;
box-shadow: 0px 0px 10px #000;
}
.box .the_background .square-shadow {
position: absolute;
left: 0;
top: 0;
z-index: 1;
width: 100%;
height: 100%;
}
.box .the_background .square-shadow:before {
content: '';
position: absolute;
left: 0;
width: 250px;
height: 125px;
-webkit-shadow: 0px 0px 10px #000;
-moz-shadow: 0px 0px 10px #000;
box-shadow: 0px 0px 10px #000;
}
.box .the_background .square-shadow:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 225px;
height: 25px;
-webkit-shadow: 0px 0px 10px #000;
-moz-shadow: 0px 0px 10px #000;
box-shadow: 0px 0px 10px #000;
}
<div class="box">
<div class="content">
Lorem ipsum...
</div>
<div class="the_background">
<div class="square-top-right"></div>
<div class="square-bottom-left"></div>
<div class="square-shadow"></div>
</div>
</div>
Live site- http://uposonghar.com/new-video/
If you go to that site then hover on embedded YouTube video then 2 sharing button will appear, 1 for facebook & 1 for twitter. After clicking on that button instant share window appear & after 5 second another popup will appear like that-
But that popup doesn't appear on right position, i want to make it center on vertically+horizontally.
My css code-
#reveal-modal-bg {
position: fixed;
height: 100%;
width: 100%;
background: #000;
background: rgba(0,0,0,.8);
z-index: 100;
display: none;
top: 0;
left: 0;
}
.reveal-modal {
visibility: hidden;
top: 100px;
left: 50%;
margin-left: -300px;
width: 520px;
background: #eee;
position: fixed;
z-index: 101;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px rgba(0,0,0,.4);
-webkit-box-shadow: 0 0 10px rgba(0,0,0,.4);
-box-shadow: 0 0 10px rgba(0,0,0,.4);
text-align:center;
padding:20px 15px 30px;
}
If you declare the height, you could do this to keep the overlay div always be centralized both vertically and horizontally:
.reveal-modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
height: 340px; /* must be declared */
}
Check out the demo on JSFiddle.
That is a great article by Stephen Shaw with several ways of achieving absolute centering.
Easiest way I can see would be to copy the way you centered it horizontally:
.reveal-modal { top: 50%; margin-top: -186px; }
This is assuming the box height is usually consistent
Try :
.reveal-modal {
visibility: hidden;
top: 50% !important; // there
-webkit-transform: translateY(-50%); // and there
transform: translateY(-50%); // and there
left: 50%;
margin-left: -300px;
width: 520px;
background: #eee;
position: fixed;
z-index: 101;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px rgba(0,0,0,.4);
-webkit-box-shadow: 0 0 10px rgba(0,0,0,.4);
-box-shadow: 0 0 10px rgba(0,0,0,.4);
text-align:center;
padding:20px 15px 30px;
}
:)
You dont need to absolute center the element. Neither use CSS3 formulas. Just work with display:table-cell and vertical-align: middle.
Here is a concept of vertical and horizontal centering divs:
<div class="modal-bg">
<div class="modal">
<div class="window">Test</div>
</div>
</div>
And css:
.modal-bg
{
display:table;
width: 100%;
height: 100%;
position:fixed;
left: 0px;
top: 0px;
}
.modal
{
position: relative;
display: table-cell;
vertical-align: middle;
width: 100%;
height: 100%;
}
.window
{
margin: 0 auto;
width:200px;
height: 200px;
background-color: red;
}
Try it out... It will do the trick
http://jsfiddle.net/69skp/1/
first of all remove the top:300px inline style then define the height as height:50% and top:25% and it will become centered