How to add a responsive image using pseudo-elements - css

I try to add a box shadow and a gradient border using images and css pseudo-elements.
I tried that code:
.box:before {
content: url('box-shadow.png');
position: absolute;
width: auto;
height: auto;
max-width: 100%;
z-index: -1;
bottom: -9px;
line-height: 0;
}
.box:after {
content: url('box-border.png');
position: absolute;
width: auto;
height: auto;
max-width: 100%;
bottom: -5px;
right: 0px;
}
But the added images don't resize when the parent div resizes, whereas it works by adding the image manually.
See that fiddle http://jsfiddle.net/5TG3E/2/

I try from my side may be that's help you. Write like this:
.box:after {
content:'';
position: absolute;
z-index: -1;
bottom: -9px;
margin: 0 auto;
top:0;
left:0;
right:0;
background:url('http://dl.dropbox.com/u/4812171/box-shadow.png') no-repeat bottom center;
-moz-background-size:100% 9px;
background-size:100% 9px;
}
.box:before {
content:'';
position: absolute;
bottom: 0px;
right: 0px;
left:0;
top:0;
background:url('http://dl.dropbox.com/u/4812171/box-border.png') no-repeat bottom right;
}
Check this http://jsfiddle.net/5TG3E/6/

Related

CSS title with triangle bottom shape

im straggling to create such title style in CSS. Can someone help me please?
Totally possible with following css
.content::after{
content: "";
background: #fff;
transform: skewY(10deg);
width: 50%;
height: 80px;
position: absolute;
left: 0;
top: 75px;
}
.content::before{
content: "";
background: #fff;
transform: skewY(-10deg);
width: 50%;
height: 80px;
position: absolute;
right: 0;
top: 75px;
}
.content{
width:100%;
height:75px;
background:#fff;
overflow:hidden;
padding:20px;
}
you should check it on different screen sizes and tweak with height of after and before elements
In this case content class should be element you want to add triangle

How to show fixed element in center bottom

I want to show <div class="fe"></div> in perfect center. When I use left: 50%; its works but not showing in perfect center.
.fe {
position: fixed;
bottom: 0;
left: 50%;
width: 150px;
height: 50px;
background-color: black;
}
Method 1:
Add transform: translateX(-50%).
body {
background: #ccc;
}
.fe {
transform: translateX(-50%);
background-color: black;
position: fixed;
width: 150px;
height: 50px;
bottom: 0;
left: 50%;
}
<div class="fe"></div>
Method 2:
Use negative margin equal to half of element width. i.e as you have width of .fe 150px so use margin-left: -75px
body {
background: #ccc;
}
.fe {
background-color: black;
margin-left: -75px;
position: fixed;
width: 150px;
height: 50px;
bottom: 0;
left: 50%;
}
<div class="fe"></div>
You can translate the element to move 50% left its own size:
transform:translateX(-50%);
Like this:
.fe {
position: fixed;
bottom: 0px;
left: 50%;
transform:translateX(-50%);
width: 150px;
height: 50px;
background-color: black;
}
instead of setting left to 50%, set left=0 and right=0 and margin=auto.. this will center automatically to center.
.fe {
position: fixed;
bottom: 0px;
left: 0;
right: 0;
margin: auto;
width: 150px;
height: 50px;
background-color: black;
}
Try using margin-left and margin-right as shown below
margin-left: auto;
margin-right: auto;
Setting both these to auto will center the division. For further info in this regard, you can refer this tutorial.
you can use property align="center" for div
.fe{ align="center"
}
Or in div you can define
<div class="fe" align="center"></div>
Try this Add transform: translateX(-50%); property to your code
.fe {
position: fixed;
bottom: 0px;
left: 50%;
width: 150px;
height: 50px;
background-color: black;
transform: translateX(-50%);
margin:auto;
}

display image on middle of div

I was looking the way to create image view as have Facebook or Google Plus but i can't put the image at middle of div.
This is my code:
.overflow {
background-color: rgba(0,0,0,.9);
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.overflow .left-img-box,.overflow .right-content-box {
display: inline;
height: 100%;
}
.overflow .left-img-box {
display: block;
left: 0;
margin: auto;
position: absolute;
text-align: center;
top: 0;
vertical-align: middle;
width: 70%;
}
.overflow .right-content-box {
background: #fff;
position: absolute;
right: 0;
top: 0;
width: 30%;
}
.overflow .left-img-box img {
margin: auto;
max-height: 100%;
}
You can see the example: http://fiddle.jshell.net/N6md8/5/
You can do something css like:
img {
margin:auto;
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
max-height:100%;
max-width:100%;}
reference: http://codepen.io/shshaw/full/gEiDt
I beleive you can go with position:fixed as well :)

Page shift when showing fixed 'modal' div

So I've built my own custom modal box in backbone.marionette, but I'm running into the issue that every time I show() the modal, my page shifts down about half an inch. Very annoying. Anyone have ideas how to account for this or to fix it?
Here's my #modal and .overlay css:
#modal {
position: fixed;
top: 0;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
z-index: 1002;
width: 70%;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.85);
z-index: 1001;
}
Found a solution - If I set the modal's top property to 0 and give it a margin-top of whatever, then there's no annoying offset. Here's the final css I landed on:
#modal {
position: fixed;
top: 0;
left:0;
right:0;
margin-top: 2em;
margin-left:auto;
margin-right:auto;
z-index: 1002;
width: 70%;
}

Vertical alignment - Firefox

It works in every browser, except firefox. The size of image is not fixed. I need to center vertically any image inside <a> tag.
HTML
<a href="#" class="tip popup">
<img src="http://3.bp.blogspot.com/-IjgG5GYb7SI/UNyqFqIOHkI/AAAAAAAAEd8/aoWhNyoSYiw/s1600/Toshiba+Lightfield+Module+AJ201212270055.jpg" alt="">
</a>
CSS
.tip img {
position: absolute;
min-height: 100%;
width: 100%;
border-radius: 2px;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.tip {
position: relative;
display: block;
height: 200px;
width: 100%;
border-radius: 5px 5px 0 0;
overflow: hidden;
margin-top: -14px;
margin-left: -14px;
padding-right: 28px;
}
http://fiddle.jshell.net/Pbe7m/3/
Try to give to an image:
img{
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
margin:0;
}

Resources