Good morning everyone
How can I place the different DIVs on top of each other?
I have a row that contains left and right DIVs.
In the right I have image and in the left text.
I also have a DIV that needs to be placed between the text and the background.
I've tried and gotten a few things, but I can't get the right DIV sticky-top in the right place.
I don't want to use Java but only CSS
.infosite-container {
margin: 0 auto;
width: 100%;
position: relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background: red;
top: 50%;
left: 50%;
z-index: 999;
transform: translate(-50%, -50%);
}
.infosite-left-content {
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index: 99;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index: 99;
}
.uptxt {
position: relative;
z-index: 9999;
}
<section class="infosite" id="infosite-section">
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="">
</div>
</div>
<div class="sticky-top">
<p>Sticky Top</p>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Can I get some help. I am sorry but I am not an expert.
Thanks
It's not working because you're parent is way larger than it's child. Because the div's could have different widths I suggest you to put the sticky-top div into the infosite-left-content class.
Like this:
<div class="container-fluid infosite-container">
<div class="row">
<div class="col-md-6 infosite-left-content">
<div class="sticky-top">
<p>Sticky Top</p>
</div>
</div>
<div class="col-md-6 infosite-right-content">
<div class="uptxt">
</div>
</div>
</div>
</div>
</section>
Second you need to adjust you css accordingly:
/* InfoSite ---------------------------------- */
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:999;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:99;
}
.uptxt {
position: relative;
z-index:9999;
}
/* ---------------------------------------------- */
I hope this works for you :D
Thank you for your response and possible solution.
Unfortunately it doesn't work as I would like, the sticky DIV stays on top of everything and not between the two divs.
I attach a picture of the result of how I would like its visualization.
Insert the sticky DIV between the background and the descriptive text that should appear as the last layer.
A possible solution is to use a single background DIV, ok it works, but I would like to have two of them so I can insert two images for example.
Thanks
Your css should be like this:
.infosite-container {
margin: 0 auto;
width: 100%;
position:relative;
}
.infosite-container .row {
display: table;
}
.infosite-container [class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
.sticky-top {
height: 150px;
width: 150px;
position: absolute;
background:red;
top:50%;
right:-75px;
z-index:500;
transform: translateY(-50%)
}
.infosite-left-content {
position: relative;
background-color: blue;
padding-top: 175px;
padding-bottom: 175px;
padding-left: 120px;
text-align: left;
background-image: url(../../images/img-01.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
min-height: 680px;
/* height: 680px; */
z-index:100;
}
.infosite-right-content {
padding-top: 175px;
padding-bottom: 175px;
padding-right: 120px;
padding-left: 60px;
text-align: left;
background-color: #bebebe;
min-height: 680px;
/* height: 680px; */
position: relative;
z-index:900;
}
.uptxt {
position: relative;
z-index:9999;
}
You can change the order in which the elements are stacked on top of each other with z-index - the greater it is, the higher the element will be !
Related
I want to display a dashboard using a card layout. Ideally, I want to achieve the following layout.:
HTML File:
<div id="overallCanvasWrapper" class="statistic-container">
<p ng-show="emptyAlltimeStats">No data available for given filters</p>
<div ng-show="!emptyAlltimeStats">
<div class="header-piechart">Pie Chart</div>
<canvas id="pieCombined" class="chart chart-pie" chart-data="combinedData" chart-labels="labels" chart-options="options"
chart-colours="colours">
</canvas>
<div class="chart-legend">
<ul>
<li class="blue">Blue</li>
<li class="red">Red</li>
</ul>
</div>
</div>
</div>
CSS file:
canvas{
width: 100% !important;
max-width: 450px;
height: auto !important;
}
.statistic-container {
padding: 10px;
margin-top: 20px;
margin-bottom: 20px;
margin-left: 0px;
margin-right: 0px;
padding-left: 5px;
padding-right: 5px;
height: 340px;
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
background-color: rgba(240,240,240,0.8);
background-blend-mode: soft-light;
}
.blue:before { background-color: #00aef3; }
.red:before { background-color: #d8171e; }
.chart-legend li:before {
display: block;
width: 5px;
height: 16px;
position: absolute;
left: 0;
top: 3px;
content: "";
}
However, I want to place chart-legend in the center (horizontally and Vertically) of the remaining part of the card even when the window is resized. How can I achieve that?
give the canvas element a fixed width (ex: width=300px) and use the rules margin:auto; for example:
canvas{
width: 200px;
margin-left: auto;
margin-right:auto;
}
.!emptyAlltimeStats{
text-align:center;
}
achieve centre alignment of div using position: absolute;
canvas{
width: 100% !important;
max-width: 450px;
height: auto !important;
position: relative;
}
.statistic-container {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
}
I've looked for a previous answer that helped me but couldn't find one.
HTML:
<section id="pane_one">
<h1 id="logo">lel</h1>
<h2 id="hello"><span>Hello.</span> You’ve reached my page.</h2>
</section>
CSS:
section#pane_one {
display: block;
position: relative;
width: 100%;
text-align: center;
min-height: 450px;
height: 700px;
}
h1#logo {
position: absolute;
z-index: 0;
width: 200px;
height: 200px;
background-color: #000;
text-indent: -9999px;
top: 35%;
left: 44.5%;
margin-top: -65px;
margin-left: -33px;
background: url('https://i.imgur.com/RMQi9Js.jpg') center center no-repeat;
background-size: 100%;
border-radius: 50%;
border: solid black;
}
How do I set it up so that no matter the zoom of the page, the div/image is always horizontally aligned with the text below it?
The site is: http://libeclipse.me/
<html>
<head>
<style>
section#pane_one {
display: block;
position: relative;
width: 100%;
text-align: center;
min-height: 450px;
height: 700px;
}
h1#logo {
position:relative;
z-index: 0;
width: 200px;
height: 200px;
background-color: #000;
text-indent: -9999px;
top: 200px;
display: inline-block;
background: url('https://i.imgur.com/RMQi9Js.jpg') center center no-repeat;
background-size: 100%;
border-radius: 50%;
border: solid black;
}
h2#hello {
position:absolute;
top:0px;
width:100%;
margin:auto;
}
</style>
</head>
<body>
<section id="pane_one">
<h1 id="logo">lel</h1>
<h2 id="hello"><span>Hello.</span> You’ve reached my page.</h2>
</section>
</body>
<html>
Review this and make note of the margin:auto (Centered the h2text in absolute position) and display:inline-block(Centered the bunny image).
Removed the left % and margins that were present from h1#logo.
Enjoy.
Thanks.
On the h1#logo rule change the left to 50% and the margin-left to -100px
Look at the following JSFiddle
.container {
width: 100%;
background-color: yellow;
}
.classic {
display: block;
position: relative;
margin-left: auto;
margin-right: auto;
background-position: center center;
background-image: url("http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg");
background-size: contain;
background-repeat: no-repeat;
}
.classic-img {
display: block;
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
top: 0%;
left: 0%;
}
.classic-img img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.top-menu {
width: 100%;
height: 50px;
position: relative;
background-color: red;
}
.top-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 50%;
text-align: center;
}
.top-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.top-menu-buttons span {
display: inline-block;
vertical-align: middle;
font-size: 25px;
color: white;
}
.bottom-menu {
width: 100%;
height: 50px;
position: relative;
background-color: green;
}
.bottom-menu-buttons {
position: absolute;
margin-left: auto;
margin-right: auto;
bottom: 0;
left: 0;
right: 0;
width: 80%;
text-align: center;
}
.bottom-menu-buttons .button {
display: inline-block;
vertical-align: middle;
font-size: 35px;
color: white;
padding-left: 10px;
padding-right: 10px;
}
<div class="list">
<a class="item">
<div id="container" class="container">
<div class="top-menu">
<div class="top-menu-buttons">
<button>-</button>
<span>20</span>
<button>+</button>
</div>
</div>
<div id="classic" class="classic">
<div id="classic-img" class="classic-img">
<img src="http://bc03.rp-online.de/polopoly_fs/1.4643662.1415087612!httpImage/2100575733.JPG_gen/derivatives/d540x303/2100575733.JPG" />
</div>
</div>
<div class="bottom-menu">
<div class="bottom-menu-buttons">
<button class="button button-icon ion-eye">1</button>
<button class="button button-icon ion-refresh">2</button>
<button class="button button-icon ion-crop">3</button>
<button class="button button-icon ion-android-options">4</button>
<button class="button button-icon ion-social-tumblr">5</button>
</div>
</div>
</a>
</div>
CSS:
What i want to achieve is something like the following:
The red area should be a top menu. It should not be a fixed top position it should just always be on top of the image.
As you can see the image has a white background and a black forground. It should look like a polaroid.
The green area should be a menu at the bottom but also not fixed to the bottom it should just always be underneath the image. If there is not enough space it should simply scroll not clinch or esize any of the divs. I guess the main problem is the div in the middle where the image with the background image is.
I try for ages now to get the correct css but unfortunately im very unexperienced and all i can do at the moment is try and error but i cant get it working.
remove position: absolute from .classic-img and .classic-img img
add margin: 100px auto; adjust 100px as per your need, also you have set background-size: contain and the aspect ratio of bg image is almost equal to the image, therefore you would see only small portion of bg image here in the fiddle - jsfiddle.net/18vg13dt/3
additionally if you want gap from left and right also the use - margin: 100px 50px; similarly according to your needs.
jsfiddle
I guess this is what you want?
.classic {
background: url("http://www.pulsarwallpapers.com/data/media/3/Alien%20Ink%202560X1600%20Abstract%20Background.jpg")no-repeat center center;
background-repeat: no-repeat;
background-size: cover;
}
.classic-img {
padding: 10px;
box-sizing: border-box;
}
.classic-img img {
display:block;
width:100%;
height:100%;
}
You need to set the height for the class .classic-img
Try this :
.classic-img {
display: block;
position: relative; /*---absolute to relative*/
overflow: hidden;
width: 100%;
height: 100px; /*----Adjust the height---*/
top: 0%;
left: 0%;
}
If you still face the issue, do come back and let us know.
I'm trying to achieve something but in vain. I have put the image below, it's worth a thousand words.
Basically I'm trying to center div 3, which is in div 2, between div 1 and 2 exactly to achieve the following result
Now, here's my HTML and CSS code:
HTML
<div id="container">
<div id="leftSide">
<!-- 1. -->
</div>
<div id="rightSide">
<!-- 2. -->
<div id="circle">
<!-- 3. Contains the image -->
</div>
</div>
</div>
CSS
#container{
width: 600px;
float: left;
padding: 0;
margin: 0 auto;
}
#leftSide{
width: 300px;
height: 300px;
float:left;
background-color: blue;
}
#rightSide{
width: 300px;
height: 300px;
float:left
background-color: red;
}
#circle{
width: 100px;
height: 100px;
margin-left: 30px;
background-color: black;
}
I don't have a clear idea on how to achieve it. Any help is appreciated. Thanks.
You could always try using the CSS position property?
CSS
#container{
width: 600px;
float: left;
padding: 0;
margin: 0 auto;
position:relative;
}
#leftSide{
width: 300px;
height: 300px;
float:left;
background-color: blue;
}
#rightSide{
width: 300px;
height: 300px;
float:left
background-color: red;
}
#circle{
width: 100px;
height: 100px;
margin-left: 30px;
background-color: black;
position:absolute;
top:/* VALUE GOES HERE */;
left:/* VALUE GOES HERE */;
}
top:50px; drops the element down 50px
left:50px; moves the element to the right 50px
Can be done with position:absolute;(along with the positions as shown below) to the #circle and position:relative to the #container.
Here's the fiddle: http://jsfiddle.net/a081j6bv/1/
#container{
position:relative;
}
#circle{
position:absolute;
left:0;
top:0;
bottom:0;
right:0;
margin:auto;
}
Assuming that you are going to have the "circle" div set as a static height/width you can do it by positioning it absolutely 50% left and top and then set a negative margin to half the size of the circle div.
HTML:
<div id="container">
<div id="leftSide">
<!-- 1. -->
</div>
<div id="rightSide">
<!-- 2. -->
</div>
<div id="circle">
<!-- 3. Contains the image -->
</div>
</div>
CSS:
#container{
width: 600px;
float: left;
padding: 0;
margin: 0 auto;
position:relative;
}
#leftSide{
width: 300px;
height: 300px;
float:left;
background-color: blue;
}
#rightSide{
width: 300px;
height: 300px;
float:right;
background-color: red;
}
#circle{
width: 100px;
height: 100px;
background-color: black;
position:absolute;
top:50%;
left:50%;
margin-top:-50px;
margin-left:-50px;
}
JSFiddle
You need to give the #container a relative positioning and an absolute positioning to the circle.
#container{
width: 600px;
float: left;
padding: 0;
margin: 0 auto;
position: relative;
}
#leftSide{
width: 300px;
height: 300px;
float:left;
background-color: blue;
}
#rightSide{
width: 300px;
height: 300px;
float:right;
background-color: red;
}
#circle{
width: 100px;
height: 200px;
position: absolute;
left:0;
right: 0;
top:0;
bottom:0;
margin: auto;
background-color: black;
}
#circle img{
width: 100px;
height: 100px;
}
<div id="container">
<div id="leftSide">
<!-- 1. -->
</div>
<div id="rightSide">
<!-- 2. -->
<div id="circle">
<!-- 3. Contains the image -->
<img src="http://i.imgur.com/lrg4uy5.jpg"/>
<img src="http://i.imgur.com/RLKixQW.png"/>
</div>
</div>
</div>
According to your tastes and needs, you may choose one of the 4 following templates:
#1 Center circle using position, top, bottom, left, right and margin properties
#container {
height: 300px;
/* prepare #container to center #circle */
position: relative;
}
#leftSide {
background-color: blue;
float: left;
height: 100%;
width: 50%;
}
#rightSide {
background-color: red;
float: right;
height: 100%;
width: 50%;
}
#circle {
background-color: black;
border-radius: 50%;
height: 140px;
width: 140px;
/* center #circle inside #container */
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
<div id="container">
<div id="leftSide"></div>
<div id="rightSide">
<div id="circle"></div>
</div>
</div>
#2 Center circle using position, top, left, margin-top and margin-left properties
#container {
height: 300px;
/* prepare #container to center #circle */
position: relative;
}
#leftSide {
background-color: blue;
float: left;
height: 100%;
width: 50%;
}
#rightSide {
background-color: red;
float: right;
height: 100%;
width: 50%;
}
#circle {
background-color: black;
border-radius: 50%;
height: 140px;
width: 140px;
/* center #circle inside #container */
position: absolute;
top: 50%;
left: 50%;
margin-top: -70px;
margin-left: -70px;
}
<div id="container">
<div id="leftSide"></div>
<div id="rightSide">
<div id="circle"></div>
</div>
</div>
#3 Center circle using position, top, left and transform properties
#container {
height: 300px;
/* prepare #container to center #circle */
position: relative;
}
#leftSide {
background-color: blue;
float: left;
height: 100%;
width: 50%;
}
#rightSide {
background-color: red;
float: right;
height: 100%;
width: 50%;
}
#circle {
background-color: black;
border-radius: 50%;
height: 140px;
width: 140px;
/* center #circle inside #container */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div id="container">
<div id="leftSide"></div>
<div id="rightSide">
<div id="circle"></div>
</div>
</div>
#4 Center circle using Flexbox
Note that the following HTML snippet is different from the previous ones.
#container {
height: 300px;
background: linear-gradient(90deg, blue 50%, red 50%);
/* prepare #container to center #circle */
display: flex;
align-items: center;
justify-content: center;
}
#circle {
background-color: black;
border-radius: 50%;
height: 140px;
width: 140px;
}
<div id="container">
<div id="circle"></div>
</div>
hey guys i had the same problem as a beginner..so to achieve the effect i had to set the container's position to relative and the image's position to absolute...works like magic
-ENJOY!
I have a div which has a background of a map. The map is centred and has a background size of 'contain'. The page is responsive so when the window resizes, so does the map. I need to be able to have a div on top of a certain country on the map, and on resize of the background map, the div stays directly on top of it.
So far I have
<div id="map-holder">
<div class="content">
<div class="placeholder"></div>
</div>
</div>
The div with the class of placeholder is the div i wish to keep on top of a certain country. The div with map-holder for ID is the div with the map background. Content is just to keep it all in place.
CSS
.content {
text-align: center;
width: 1200px;
margin: 0 auto;}
#map-holder {
position: relative;
height: 1000px;
width: 100%;
background: #F0F0F0;
background-image: url(../images/image-mapster.min.png);
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
padding: 30px;
}
.placeholder {
position: absolute;
right: 30px;
background: #fff;
width: 80px;
height: 50px;
border: 1px solid #000;
margin: 5px;
padding: 5px;
padding: 0;
cursor: pointer;
}
.placeholder img {
width: 100%;
height: 100%;
padding: 0;
}
.placeholder:before {
position: absolute;
top: 30%;
left: 45%;
font-weight: bold;
content: '+';
}
The only solution I can think if actually putting an image over the map.
You can do this by having multiple CSS backgrounds. Just change your code for #map-holder to this:
#map-holder {
position: relative;
height: 500px;
width: 500px;
background: #F0F0F0;
background-image: url(this_image_goes_on_top.png), url(your_map.jpg);
background-size: contain, contain;
background-position: center center, center center;
background-repeat: no-repeat, no-repeat;
padding: 30px;
}
I made a little JSFiddle out of your code for demonstration: https://jsfiddle.net/zamofL9g/1/
Basically, it's a little difficult, as I recall, when using background images.
Since the image is, technically speaking "content" you can use an inline image and suitable wrapping divs. The 'pins' can then be positioned using % based positioning values.
Here's a Codepen demo I made some time ago. This one has a tooltip too!
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.map {
width: 90%;
margin: 10px auto;
position: relative;
}
.map img {
max-width: 100%;
}
.box {
width: 2%;
height: 5%;
background-image: url(http://www.clipartbest.com/cliparts/ncX/qyL/ncXqyLdcB.png);
background-position: top center;
background-repeat: no-repeat;
background-size: contain;
position: absolute;
}
#pin-1 {
top: 25%;
left: 38%;
}
.box:hover > .pin-text {
display: block;
}
.pin-text {
position: absolute;
top: -25%;
left: 110%;
width: 300%;
display: none;
}
.pin-text h3 {
color: white;
text-shadow: 1px 1px 1px #000;
}
<div class="map">
<img src="http://connect.homes.com/wp-content/uploads/2012/05/200392710-0012.jpg" alt="" />
<div id="pin-1" class="box">
<div class="pin-text">
<h3>My House</h3>
</div>
</div>
</div>