Add Two background images in a same div with same margin - html

I inserted two background images to a div and gave them the top and bottom positions. However, the issue is that I want the images to have an equal top and bottom margin. I'm not sure how to accomplish it.
I want the background images like in the SS.
html:
<div class="license-info">
</div>
css:
.license-info {
width: 100%;
height: 800px;
background: #181f2b;
background-image: url('/images/footerdiamondchain.png'), url('/images/footerdiamondchain.png');
background-repeat: repeat-x;
background-position-y: top, bottom
}

You can specify an independent background-position for each background image. So you could set them equal distance from top and bottom, respectively, via a rule like this:
background-position: center top 80px, center bottom 80px;
center top 80px sets the first image 80px from the top
center bottom 80px sets the second image 80px from the bottom.
.license-info {
width: 100%;
height: 800px;
background: #181f2b;
background-image: url('//placekitten.com/50'), url('//placekitten.com/50');
background-repeat: repeat-x;
background-size: 50px;
background-position: center top 80px, center bottom 80px;
}
<div class="license-info"></div>

you can do like that.
<div class="license-info">
<img class="first-img" src="./first/path"></img>
<img class="second-img" src="./second-img/path"></img>
</div>
.license-info {
position:relative;
}
.license-info .first-img {
position:absolute;
top:50px// change this position
}
.license-info .second-img {
position:absolute;
bottom:50px;
}

Related

Wrap an Image with transparent image without using position:absolute , top ,left ,right and bottom

Is there a way to wrap an Image with transparent image without using position:absolute and top , left ,bottom and right positions ,I have tried to add div then img with transparent image url but it shows only the second image.
for example :
<style>
.Image{
width:100px;
height:100px;
border-radius: 50%;
}
</style>
<div class="Image" style="background-image:'url(./assets/Image.png)'">
<img class="Image" src="url(./assets/trans-image.png)"/>
</div>
Something like this? You might have to change the background position of each depending on your choice of images as mine are both the same size.
.overlay-image {
width: 300px;
height: 100vh;
background-image: url(https://i.ibb.co/GvXnt0J/top-img.png), url(https://i.ibb.co/VvdwhTc/bottom-img.png);
background-repeat: no-repeat;
background-position: 0 0, 0 0;
background-size: contain;
}
<div class="overlay-image"></div>

2 stacked div's with background gradients, not displaying properly

I have an issue where I want to have to divs that act as a background. they basically wrap the entire page. both have the same gradient set as their background-image. the problem is that on div displays the gradient perfectly fine, but the other is just white.
html:
<div class="bg bg-base">
<div id="bg-animation" class="bg bg-animation">
<div class="layer-content">
<!--content here-->
</div>
</div>
</div>
CSS:
.bg {
background-position: bottom center;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
position: absolute;
}
.bg-base {
background-image: linear-gradient(to left bottom, #5533ff, #008dff, #00bdff, #00e0dd, #a4fbc9);
}
.bg-animation {
background-image: linear-gradient(to right top, #5533ff, #008dff, #00bdff, #00e0dd, #a4fbc9);
}
.layer-content {
width: 100%;
position: relative;
}
I'm doing some opacity animations with the top gradient, that's why I need 2 of them on top of each other. but if say, I set the opacity of the top gradient to 0, the bottom one isn't there. if I add a height: 5000px; to the bg-base, it does show up.
Kill the absolute positioning:
https://jsfiddle.net/cathead/1nbjdp05/4/
.bg {
background-position: bottom center;
background-repeat: no-repeat;
background-size: cover;
xposition: absolute;
width: 100%;
}

How do I align the 2 stacked elements using the same background image so it looks like one image?

The header of my website's homepage consists of the following layout:
<header>
<div class="navbar-lock"></div>
<div class="hero"></div>
</header>
Where div.navbar-lock is a fixed navigation with an initial height of 90px, and div.hero contains some header text. Visually, I want to give the appearance that one background image (2000px x 481px) spans the height and width of both. On scroll, the fixed navbar's background will be the top 90px of the image; when the scroll position is back at the top of the page, the header once again appears as one background image.
What I've tried:
Approach A:
header {
background: #F60 url(../images/header_bg.jpg) no-repeat 0 0;
background-size: cover;
}
div.navbar-lock {
background: #F60 url(../images/header_bg.jpg) no-repeat 0 0;
background-size: cover;
min-height: 90px;
padding-top: 20px;
position: fixed;
top: 0;
z-index: 100;
width: 100%;
}
Approach B (crop the image into 2):
div.navbar-lock {
background: #F60 url(../images/header_bg.jpg) no-repeat 0 0;
background-size: cover;
}
div.hero {
background: #F60 url(../images/header_bg.jpg) no-repeat 0 -90px;
background-size: cover;
position: relative;
top: 90px;
padding: 80px 0 134px; // padding to properly position its text
}
But in both attempts, I was unable to get the image(s) to line up properly. What am I missing here?
I would put the header and the hero div's into a parent div. And would put the image onto the parent div.

Percentage width and height hides background image

Demo
.moving_background
{
background-image: url("../image/quote3.jpg");
background-position: 50% center; /*Centering property*/
background-repeat: no-repeat;
height: 100px;
margin: 20px;
width: 100px;
border:1px solid;
}
If i change the width and height to 100%, it is not showing the border to me. I don't understand the reason. Please let me know this
I am trying to center this div in the body. Any other ways are also welcome except negative top, left, margin values.
Any idea?
The issue is that background-image does not count as content in your div, so what you have is an empty div, hence it has no height. A way around this is to add the image inside the div, then hide it.
HTML
<div class="moving_background">
<image src="http://placehold.it/100x100" class="background"/>
</div>
CSS
.moving_background {
background-image: url("http://placehold.it/100x100");
background-position: 50% center;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
margin: 20px;
width: 100%;
border:1px solid;
}
.background {
visibility: hidden
}
JSFiddle: http://jsfiddle.net/nhg33xek/4/

CSS: Centering a background image on top of a repeating background image

I am trying to create a header for a website. What I am trying to do is repeat a background image all the way across my page for the header background. This image is 1px wide. On top of that image I want to center another background image on top of the previous and have it centered and no repeating. The second image is the logo of the site and the title etc.
With the below code I get the top layer not centered and repeating with the bottom layer.
.mainHeaderBottomLayer
{
background-image: url("images/header.png");
background-repeat: repeat-x;
height: 107px;
text-align: center;
}
.mainHeaderTopLayer
{
background-image: url("images/headerLayer.png");
background-repeat: no-repeat;
width: 1200px;
margin: 0 auto;
}
Here is the html
<div class="mainHeaderBottomLayer">
<div class="mainHeaderTopLayer"></div>
</div>
Anyone know how this can be done?
background: url("images/headerLayer.png") no-repeat center top #fff;
or
background: url("images/headerLayer.png") no-repeat 50% 0 white;
.mainHeaderTopLayer {
background: url(images/headerLayer.png) no-repeat center top;
width: 1200px;
height: 200px;
margin: 0 auto; }
Just center the image via the background property and position attributes.
Based on comments above you need a height attribute as well....
Use background-positioning to align the logo:
.mainHeaderTopLayer
{
background-image: url("images/headerLayer.png");
background-repeat: no-repeat;
background-position: center center;
width: 1200px;
margin: 0 auto;
}

Categories