I want to set two background images to div and then make them changing while hovering with fade effect like this.
.kid {
max-width:50%;
position:relative;
}
.kid img {
display:block;
opacity:1;
height: auto;
transition:.6s ease;
width:100%;
position:absolute;
z-index:12;
}
.kid img:hover {
opacity:0;
}
.kid img + img {
display:block;
opacity:1;
position:relative;
z-index:10;
}
<div class="kid">
<img src="https://cdn.pixabay.com/photo/2017/12/16/16/37/mountain-3022908_960_720.jpg" alt="Kid" itemprop="image" width="600" height="750" />
<img src="https://cdn.pixabay.com/photo/2020/02/04/16/14/leaves-4818626_960_720.jpg" alt="Adult" width="600" height="750" />
</div>
Here it's done by putting image in html code. I have to do this in css as background-image, because I made two column grid gallery (50% width and 100vh) and it doesn't works with <img>.
Here is my code. Help me to get the same effect like in first fiddle.
body{
margin: 0 auto;
width: 100%;
height: 100vh
}
.left{
float: left;
}
.right{
float: right
}
.col-half-width{
width: 50%;
height: 100vh;
}
.project-01{
background: #ccc url('https://cdn.pixabay.com/photo/2017/12/16/16/37/mountain-3022908_960_720.jpg') no-repeat center center;
background-size: cover;
}
.project-02{
background: url('https://cdn.pixabay.com/photo/2020/02/04/16/14/leaves-4818626_960_720.jpg') no-repeat center center;
background-size: cover;
}
.project-01,
.project-02 img{
max-width:100%;
}
<div class="col-half-width left project-01"></div>
<div class="col-half-width right project-02"></div>
Try it using CSS :hover and transition. Note: perhaps you should preload the image so that it works smoothly on the first time aswell.
body{
margin: 0 auto;
width: 100%;
height: 100vh
}
.left{
float: left;
}
.right{
float: right
}
.col-half-width{
width: 50%;
height: 100vh;
}
.project-01{
background: #ccc url('https://cdn.pixabay.com/photo/2017/12/16/16/37/mountain-3022908_960_720.jpg') no-repeat center center;
background-size: cover;
transition: 0.5s;
}
.project-01:hover{
background: url('https://cdn.pixabay.com/photo/2020/02/04/16/14/leaves-4818626_960_720.jpg') no-repeat center center;
background-size: cover;
}
.project-01,
.project-02 img{
max-width:100%;
}
<div class="col-half-width left project-01"></div>
The CSS property background-image is not animatable:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
I believe you'll have to do something much more cumbersome. We can use the opacity on a nested positioned object to get the desired effect. Any other content in the parent div will need a z-index value higher than the animated background.
body {
margin: 0 auto;
width: 100%;
height: 100vh
}
.left {
float: left;
}
.right {
float: right
}
.col-half-width {
width: 50%;
height: 100vh;
}
.project-01 {
background: #ccc url('https://cdn.pixabay.com/photo/2017/12/16/16/37/mountain-3022908_960_720.jpg') no-repeat center center;
background-size: cover;
display: inline-block;
position: relative;
}
div.innerAnimate {
background: url('https://cdn.pixabay.com/photo/2020/02/04/16/14/leaves-4818626_960_720.jpg') no-repeat center center;
background-size: cover;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
z-index: 0;
transition: 0.5s;
}
.project-01:hover div.innerAnimate {
opacity: 1;
}
.project-01,
.project-02 img {
max-width: 100%;
}
div.innerContent {
color: white;
padding: 20pt;
position: relative;
z-index: 100;
}
<div class="col-half-width left project-01">
<div class="innerAnimate"></div>
<div class="innerContent">
<p>My content here.</p>
</div>
</div>
Related
hello i'm trying to set one image to the center bottom on another background image.
image contain one (ktm)Bike background image and on that another image of car which is at center bottom).
i have also tried background-position property as center bottom but still not working. i don't know how to do that. i have provided image in the comment box that what i'm exactly trying to make please refer that image don't ignore. and also provided my code what i have tried yet. please can anyone give show me example that how i do sorry but i'm really new to cascading style sheets. and do i need use to absolute property for that?
JSFiddle: jsfiddle.net/vr50vza2/1
.f4-pos {
position: absolute;
background-position: center bottom;
}
.footer {
background-image: url("../images/footer.png");
}
.foot4 {
background-image: url("../images/iauro-footer-logo.png");
}
.ban {
height: 800px;
background-size: 100% 100%;
}
.im3 {
height: 100px;
width: 300px;
}
.norep {
background-repeat: no-repeat;
}
<div class="footer ban norep">
<div class="foot4 f4-pos im3 norep"></div>
</div>
Like this? I removed some unnecessary css and the image, but you can return them later.
.footer {
position: relative;
border: 1px solid red;
}
.foot4 {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 0);
}
.ban {
height: 500px;
}
.im3 {
height: 100px;
width: 200px;
background-color: blue;
}
<div class="footer ban norep">
<div class="foot4 f4-pos im3 norep"></div>
</div>
Please Check out the FIDDLE : https://jsfiddle.net/NayanaDas/jw3dqb71/
.f4-pos
{
position: absolute;
background-position:center bottom;
}
.footer1
{
background-image: url("http://pre09.deviantart.net/49b5/th/pre/i/2015/160/1/9/skies__backround_practice__by_darklatias61-d8wm1wr.png");
}
.foot4
{
text-align: center;
position:fixed;
bottom:0;
width: 100%;
height:50px;
background-image: url("http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/watercolor-grunge-000100-glossy-rust.jpg");
background-size:100%;
}
.ban
{
height: 800px;
background-size:100% 100%;
}
.im3
{
height: 100px;
width : 300px;
}
.norep
{
background-repeat: no-repeat;
}
.footerWrap {
width:100%;
position:fixed;
bottom: 0px;
}
.footer {
width:400px;
margin:auto;
}
.footerContent {
float:left;
width:100%;
padding:20px 0;
}
.footer p {float:left; width:100%; text-align:center; }
You can do this with CSS Flexboxes. Please see my code below. Note that the magic is in the CSS for #img2Container. Also, see the JSFiddle.
<!doctype html>
<html>
<head>
<style type="text/css">
html, body {
margin: 0px;
padding: 0px;
height: 100%;
}
#img1 {
width: 100%;
height: 100%;
}
#img2Container {
position: absolute;
bottom: 0px;
height: 100px;
width: 100%;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-justify-content: center;
justify-content: center;
}
#img2 {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<img id="img1" src="http://lorempixel.com/600/600/" />
<div id="img2Container">
<img id="img2" src="http://lorempixel.com/100/100/" />
</div>
</body>
</html>
It's reasonable to believe that you could also wrap the image in another element and use margin: 0 auto. However, I like this method better because of the flexibility of CSS Flexboxes, allowing you to center more than one image and have them all centred evenly.
Please note that the img2Container has position absolute, which means that it scrolls with the page. If you would prefer, you could set it to sticky so that the remains in the viewing pane and positions it to the viewpane rather than the document.
I was wondering how to center 3 divs inside a div.
Here is my code example
body {
position: fixed;
height: 100%;
width: 100%;
}
#container {
border: 3px solid black;
height: 90%;
width: 90%;
}
.plaatje {
width: 30%;
height: 70%;
border: 2px solid black;
float: left;
text-align: center;
}
#plaatje1 {
background-image: url("http://image.prntscr.com/image/c3d5dbc04f664a3386b372d8e4ceb4c7.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
#plaatje2 {
background-image: url("http://image.prntscr.com/image/2bcfd124f98a448cbae822337818ff4e.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
#plaatje3 {
background-image: url("http://image.prntscr.com/image/e1b7059d626f47cb94535bbba9887cc1.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
<div id="container">
<div id="plaatje1" class="plaatje">
</div>
<div id="plaatje2" class="plaatje">
</div>
<div id="plaatje3" class="plaatje">
</div>
</div>
The problem is, there is still a white space on the right hand-side of the picture, I have marked it so you know what i'm talking about.
It also needs to scale, so if I resize the window, that the third image doesn't pops below the first or that the space exists when I resize it fully.
Any help is appreciated.
I have created a jsFiddle which demonstrates how you can do this using flexbox. It doesn't require floating the elements and gives you with exactly what you're looking for.
I have added a wrapper around the images (.images) and given it the flex properties required to align its contents, then removed the floats and a few other unnecessary things.
Here is the browser support for flexbox: caniuse:flexbox
body {
position: fixed;
height: 100%;
width: 100%;
}
#container {
border: 3px solid black;
height: 90%;
width: 90%;
}
.images {
height: 90%;
display: flex;
justify-content: center;
}
.plaatje {
width: 30%;
height: 70%;
border: 2px solid black;
background-size: 100% 100%;
background-repeat: no-repeat;
}
#plaatje1 {
background-image: url("http://image.prntscr.com/image/c3d5dbc04f664a3386b372d8e4ceb4c7.png");
}
#plaatje2 {
background-image: url("http://image.prntscr.com/image/2bcfd124f98a448cbae822337818ff4e.png");
}
#plaatje3 {
background-image: url("http://image.prntscr.com/image/e1b7059d626f47cb94535bbba9887cc1.png");
}
<div id="container">
<div class="images">
<div id="plaatje1" class="plaatje"></div>
<div id="plaatje2" class="plaatje"></div>
<div id="plaatje3" class="plaatje"></div>
</div>
</div>
You could just simply try adding text-align:center; to your container div
There are many ways to do this, and you should probably start with http://www.w3schools.com/css/css_align.asp - this elementary level question often gets flagged as not appropriate for SO.
But! Welcome. Here's one way you could do this - I've added comments to explain what's going on. Basically your float: left by definition made the .plaatjes impossible to center; and the text-align: center needs to be on the containing element
body {
position: fixed; /* probably don't actually want */
height: 100%;
width: 100%;
margin: 0; /* add */
}
#container {
border: 3px solid black;
height: 90%;
width: 90%;
margin-left: 5%;
text-align: center; /* add */
}
.plaatje {
width: 30%;
height: 70%;
border: 2px solid black;
/* float: left; // remove
text-align: center;*/
display: inline-block; /* add */
}
#plaatje1 {
background-image: url("http://image.prntscr.com/image/c3d5dbc04f664a3386b372d8e4ceb4c7.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
#plaatje2 {
background-image: url("http://image.prntscr.com/image/2bcfd124f98a448cbae822337818ff4e.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
#plaatje3 {
background-image: url("http://image.prntscr.com/image/e1b7059d626f47cb94535bbba9887cc1.png");
background-size: 100% 100%;
background-repeat: no-repeat;
}
<div id="container">
<div id="plaatje1" class="plaatje">
</div><div id="plaatje2" class="plaatje">
</div><div id="plaatje3" class="plaatje">
</div>
</div>
<!-- removed spaces between the divs -->
The page open with scroll. I want to make the page appear fully responsive without any scroll bar. I tried to set the height to 100% with no luck.
html {
height: 100%;
width: 100%;
}
body{
width:100%;
hight:100%;
margin: 0;
padding:0;
}
.main{
background-image: url("http://www.ghadaalsamman.com/new/images/bg.gif");
background-repeat: no-repeat;
background-position: center center;
margin: 0;
padding-top: 30vw;
background-size: 100%;
}
.marquee {
display: block;
position: relative;
width: 51vw;
margin: auto;
}
marquee{
width: 100%;
margin: auto;
display: block;
}
#btn1 {
background: url("http://www.ghadaalsamman.com/new/images/enter.gif") no-repeat scroll center center ;
display: block;
height: 53px;
margin: 0 auto;
position: relative;
width: 50%;
background-size: 100%;
margin-top: 33%;
margin-bottom:1%;
}
.button {
padding: 5px;
}
.container {
display: block;
height: 100%;
margin: 0 auto;
max-width: 960px;
position: relative;
}
#media screen and (max-width:500px) {
#btn1{
background-size: 100% auto;
}
}
<div class="main">
<div class="container">
<div class="marquee">
<marquee scrollamount="3" direction="right" dir="ltr">
<h3 align="center" style="color:#804000;font-size:large;margin-top:0px;"><strong>
<img height="auto" width="200%" src="http://www.ghadaalsamman.com/new/images/image21.png">
</strong></h3>
</marquee>
</div>
<a class="button" id="btn1" href="http://ghadaalsamman.com/new/site.html"></a>
</div>
</div>
This is the problem
body {
width: 100%;
hight: 100%; <----- 'hight' make it 'height'
margin: 0;
padding: 0;
}
Replace with this
body {
width:100%;
height:100%;
margin: 0;
padding:0;
}
the ratio of your image will make it difficult i believe.
Since you started using vw units, maybe it's an hint to use vh units and max-width too.
Because of your image, too much like a square, the container needs too be a bit smaller to stay in sight. Because of , vw units, i would propose to use display:fle to easily center you container :
DEMO of my idea
CSS updated :
html {
height: 100%;
width: 100%;
}
body {
width:100%;
height:100%;/* UPDATED*/
margin: 0;
padding:0;
display:flex;/* UPDATED*/
}
.main {
background-image: url("http://www.ghadaalsamman.com/new/images/bg.gif");
background-repeat: no-repeat;
background-position: center center;
margin: 0;
padding-top: 15vh;/* UPDATED*/
background-size: 100%;
width:100vh;/* UPDATED*/
margin:auto;/* UPDATED*/
max-width:100vw;/* UPDATED*/
overflow:hidden;/* UPDATED hide marquee*/
}
.container {
display: block;
height: 100%;/* useless when parent has no height given */
margin: 0 auto;
position: relative;
}
This seemed simple in my head.. But it's not. I have 2 div's. floating next to eachother
The right div should have an image that is always sticking to the footer
It's not even applying the 100% Height of my .block div, the parent div ( body ) is also set at 100%
For some reason this is not working with my following code.
JSFIDDLE
HTML
<div class="header">
Header
</div>
<div class="block">
<img src="http://www.zwaldtransport.com/images/placeholders/placeholder1.jpg" />
</div>
CSS
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: url('background.jpg') no-repeat center center fixed;
background-size: cover;
}
.header {
float: left;
height: 100%;
width: 40%;
background: red;
}
.block {
float: left;
width: 60%;
height: 100%;
background: green;
}
.block img {
max-width: 100%;
}
You can try this. check and let me know, have you asked for this:
.header {
height: 100%;
width: 40%;
background: red;
}
.block {
position:absolute;
bottom:0;
width: 60%;
height: auto;
background: green;
}
How to center (vertically,horizontally) properly over an image in a ?
<div class="category-info">
<div class="image">
<h1>Title</h1>
<img src="image.jpg" />
</div>
</div>
CSS
.category-info {
text-align: center;
height: 200px;
width: 770px;
overflow: auto;
margin-bottom: 20px;
}
The image is 770px width and 200px height. I don't what to do next with . I tried several things, without success.
Here you go: http://jsfiddle.net/QjLuP/4/
The CSS:
.image{
position: relative;
background: green; /* IE */
}
.image h1{
z-index: 2;
position: absolute;
top: 50%;
left: 0;
right: 0;
font-size: 20px;
width: 100%;
height: 26px;
padding: 0;
margin: 0;
margin-top: -13px; /* 1/2 height */
text-align: center;
background: red;
background: rgba(170, 0, 0, 0.8); /* CSS3 */
}
.image img{
z-index: 1;
width: 100%;
height: 100%;
position: absolute;
top:0;
right:0;
bottom:0;
left:0;
background:green
}
I threw a position relative on the .image class and set the width and height on the image element (that way it doesn't resize when it loads). I changed the table back to the h1 and added your line-height of 200px. That is the only downside, you'll still have to manually set the line-height of the h1.
HTML:
<div class="category-info">
<div class="image">
<h1>Title</h1>
<img src="http://placekitten.com/770/200" />
</div>
</div>
CSS:
.category-info {
text-align: center;
margin-bottom: 20px;
}
.image{
position:relative;
}
.image img{
width:770px;
height:200px;
}
.image h1{
position:absolute;
width:100%;
color:white;
line-height:200px;
margin:0;
}
JSFiddle: http://jsfiddle.net/5wGwL/2/
Have you tried this?
h1 { text-align:center; }
html
<h1 style="background-image:url(your php source.img)">Title</h1>
css :
h1 {
height: 200px;
width: 770px;
margin-bottom: 20px;
text-align:center;
vertical-align:middle;
line-height:200px;
background:transparent no-repeat scroll 50% 50%;
}
and nothing else