i have a parent container inside two sub containers are there each container have a fixed height and width in each sub containers i have a loader loader gif.
.parent-container{
display: flex;
justify-content: space-evenly;
border: 7px solid black
}
.sub-container-one{
width:400px;
height: 300px;
border: 3px solid blue;
}
.sub-container-two{
width: 300px;
height: 300px;
border: 3px solid red;
}
.loader{
display: block;
top: 0;
left: 0;
width: 50%;
height: 100%;
position: absolute;
background-image: url('http://loadinggif.com/images/image-selection/3.gif');
background-repeat: no-repeat;
background-position: center;
}
.second-loader{
margin-left:50%;
}
<div class="parent-container">
<div class="sub-container-one">
<div class="loader"></div>
</div>
<div class="sub-container-two">
<div class="loader second-loader"></div>
</div>
</div>
how can is show the same loader in both sub div at the center , i have added one more class, right now loader is showing not to the center.
when i have given
justify-content: center
it works , but how can i align the loader to the center of the both div making
justify-content: space-evenly;
Also for IE will this work ?
It Worked. Made the css for the loader as below, removed the position and made width to 100%
.loader{
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('http://loadinggif.com/images/image-selection/3.gif');
background-repeat: no-repeat;
background-position: center;
}
Related
So I'm more of a backend than a frontend dev,
I'm having some difficulty on css.
<div className="--Hero">
<div className="--Hero-container-text">
<h1>this is me</h1>
<p>hello</p>
note: className is because of react.
I want the text to stay relative to the background image on hero-container-text as seen below.
another example showing a different viewport.
Here's the css.
.--Hero {
width: 100%;
height: 90vh;
background-image: url("./images/homepage/manpass.svg");
background-size: contain;
background-position: bottom;
background-repeat: no-repeat;
display: flex;
justify-content: center;
align-items: center;
}
.--Hero-container-text {
position: fixed;
left: 60%;
top: 40%;
padding: 0 60px;
}
You should add position:relative; to your --hero and position:absolute; to your
--Hero-container-text
you set the div you want to technicaly be your canvas with a position: relative;
Avoid using percenteges for the positioning since they will most likely break ,instead use left 0 right 0 with auto margin , the code will look something like this :
.--Hero {
width: 100%;
height: 90vh;
background-image: url("./images/homepage/manpass.svg");
background-size: contain;
background-position: bottom;
background-repeat: no-repeat;
display: flex;
justify-content: center;
align-items: center;
position:relative;
}
.--Hero-container-text {
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
I am a beginner in html and CSS, and I will try to make a map with clickable points, but I do not get it right.
I have received a tip of using flexboxes and creating a container with the map as a background image, and creating separate containers that can hold imagebuttons for the clickable points. The solution must be responsive and work for both desktop and mobile.
I have started by trying to get the background image and points/(boxes) to resize equally and then try to set the position on the points/(boxes), but I have encountered a problem already with the background image and the parent container.
Because I can not set the height of the parent container to the same height as the background image, so now only half the image is displayed.
If I insert the height of the parent container equal to the background image in px, the background image will not resize responsive.
Does anyone know how to set the height of the background image and container to the same, or maybe know a better solution to this?
In that case, I'll be happy to hear from you :-)
My coding so far:
.map-container {
display: flex;
justify-content: center;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-image: url("Images/home/map_front.jpg");
background-size: cover;
background-repeat: no-repeat;
}
.flexbox-point {
width: 20%;
margin: 20px;
border: 3px solid #B90F12; /* Color to see the points/boxes */
}
.flexbox-point1 {
min-height: 100px;
}
.flexbox-point2 {
min-height: 100px;
}
.flexbox-point3 {
min-height: 100px;
}
<!-- Test for flexbox with map as BG-picture*---->
<div class="map-container">
<div class="flexbox-point flexbox-point1"></div>
<div class="flexbox-point flexbox-point2"></div>
<div class="flexbox-point flexbox-point3"></div>
</div>
I would recommend using a fixed width instead of % on your child because the % means it's going to take up 20% of screen width which when resizing the browser could get really small. To center your background image you can use background-position: center; See below.
.map-container{
display: flex;
justify-content: center;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-image: url("https://dummyimage.com/400x400/000/fff");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.flexbox-point{
width: 400px;
margin: 20px;
border: 3px solid #B90F12; /* Color to see the points/boxes */
}
.flexbox-point1 {
min-height: 100px;
}
.flexbox-point2 {
min-height: 100px;
}
.flexbox-point3 {
min-height: 100px;
}
<div class="map-container">
<div class="flexbox-point flexbox-point1"></div>
<div class="flexbox-point flexbox-point2"></div>
<div class="flexbox-point flexbox-point3"></div>
</div>
EX with a different height background image.
.map-container{
display: flex;
justify-content: center;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-image: url("https://upload.wikimedia.org/wikipedia/commons/c/cc/ESC_large_ISS022_ISS022-E-11387-edit_01.JPG");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.flexbox-point{
width: 400px;
margin: 20px;
border: 3px solid #B90F12; /* Color to see the points/boxes */
}
.flexbox-point1 {
min-height: 100px;
}
.flexbox-point2 {
min-height: 100px;
}
.flexbox-point3 {
min-height: 100px;
}
.container {
height: 100vh;
}
<div class="container">
<div class="map-container">
<div class="flexbox-point flexbox-point1"></div>
<div class="flexbox-point flexbox-point2"></div>
<div class="flexbox-point flexbox-point3"></div>
</div>
</div>
.wrapper{
display: inline-block;
position:relative;
}
.big-img{
width: 100%;
max-width: 100%;
border: 1px solid blue;
}
.small-img{
border: 1px solid red;
position:absolute;
right: 10%;
top: 10%;
width: 25%;
max-width:25%;
}
<div class="wrapper">
<img class="big-img" src="https://webhostingvirtualdedicatedservers.com/files/2012/09/Web-server.png" />
<img class="small-img" src="http://loosechange.co.za/wp-content/uploads/2012/06/Personal-Discount-10-lg.jpg" />
</div>
So, I want to place a logo right in the middle of a background image which is full page size (height: 100vh). I can do it in about 10 seconds using Elementor, but I have to do it on a website without any CMS, so that's hard for me. I tried literally any snippet I could find online, but it was always about how to stack an image on top of another image, not an image on top of a full-page background.
Here's an example of what I found: https://jsfiddle.net/uu3pqwpa/
I would literally use a background-imagein the CSS for the large container and apply flex settings to it (details see below) to center the smaller img tag within that div (i.e. no absolute/relative positioning, no two img tags):
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
}
.big-img {
width: 100vw;
height: 100vh;
border: 1px solid blue;
position: relative;
background: url('https://placehold.it/2000x1500/fda?text=Background-Image') center center;
background-size: cover;
display: flex;
justify-content: center;
align-items: center;
}
.small-img {
border: 1px solid red;
width: 30%;
height: 25vh;
}
<div class="big-img">
<img class="small-img" src="https://placehold.it/200x100/ab7?text=centered-Image" />
</div>
You could set the background of the wrapper using
background: url('https://webhostingvirtualdedicatedservers.com/files/2012/09/Web-server.png);
keeping it position relative, but adding:
width: 100%;
height: auto;
And then leave the small image positioned absolutely
Placing the images as background images will make it possible to use background-size: cover and have them fit in any size of the container.
Using pseudo-elements, like ::before, is just a way of clear up HTML code with elements that are mostly there for styling.
Any other kind of clarification down below in the code as comments.
html, body {
padding: 0px; /* remove default spacing */
margin: 0px;
}
.wrapper {
position: relative;
min-width: 100vw;
min-height: 100vh; /* min lets the element span beyond the page, if necessary. */
/* didn't find image */
/* background: url('https://webhostingvirtualdedicatedservers.com/files/2012/09/Web-server.png'); */
background: url('https://picsum.photos/200/300');
}
.wrapper, .wrapper::before {
box-sizing: border-box; /* needed to include border size in width and height */
border: 1px solid blue;
background-repeat: none;
background-size: cover;
}
.wrapper::before {
content: '';
position: absolute;
width: 25vw;
height: 25vw; /* make it squarish */
left: 50%;
top: 50%;
/* move element negative 50% of it's own size on both x and y coordinate */
transform: translate(-50%, -50%);
border-color: red;
/* background: url('http://loosechange.co.za/wp-content/uploads/2012/06/Personal-Discount-10-lg.jpg'); */
background: url('https://picsum.photos/200/200');
}
<div class="wrapper">
</div>
.wrapper{
display: flex;
justify-content:center;
align-items:center;
height:100vh;
}
.big-img{
width: 100%;
max-width: 100%;
border: 1px solid blue;
}
.small-img{
border: 1px solid red;
width: 25%;
height:25%;
}
body {
background-image: url("https://images.freeimages.com/images/small-previews/1c9/maine-at-4-45-am-1370871.jpg");
background-size: cover;
}
<div class="wrapper">
<img class="small-img" src="https://images.freeimages.com/images/small-previews/25d/eagle-1523807.jpg"/>
</div>
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 -->
In my webpage section i use a icon gallery. I insert an image/icon in a div and manage through css for align center (vertical and horizontal). But i found my image align center vertically not exact center in my div. See my code and css.
css
#main {
width: 170px;
height: 300px;
border: 1px solid #c3c3c3;
display: -webkit-flex;
display: flex;
align-items: flex-start;
}
#main div{
width: 70px;
height: 70px;
align-self: center;
background:red;
}
and
html
<div id="main">
<div></div>
</div>
See my Example
How to align my image in exact center in body or div?
You can use align-items: center and justify-content: center
#main {
width: 170px;
height: 300px;
border: 1px solid #c3c3c3;
display: flex;
align-items: center;
justify-content: center;
}
#main div {
width: 70px;
height: 70px;
background: red;
}
<div id="main">
<div></div>
</div>
In case you have some other elements in #main but you want div to be vertically and horizontally centered you can remove div from elements flow with position: absolute and use transform: translate().
#main {
width: 170px;
height: 300px;
border: 1px solid #c3c3c3;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
#main div,
span {
width: 70px;
height: 70px;
background: red;
}
span {
align-self: flex-start;
background: green;
}
#main div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div id="main">
<span></span>
<div></div>
</div>
I like to use this nice little transform translate trick to center things.
In your case
#main {
width: 170px;
height: 300px;
border: 1px solid #c3c3c3;
position: relative;
}
#main div {
width: 70px;
height: 70px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background:red;
}
So use position: relative on your parent element and position: absolute on the child element. On the absolute element use left: 50% and top: 50% along with transform: translate(-50%, -50%) and everything should be centered.
add "margin:0 auto;" to your image like this:
#main div{
margin: 0 auto;
}
here the fiddle: https://jsfiddle.net/px52mk5b/5/
-I hope this help
In your code there is a small change is needed to get your desire output. That is include the code margin: 0 auto; along with the #main div css. Then the css will be as below.
#main div{
width: 70px;
height: 70px;
align-self: center;
background:red;
margin: 0 auto;/*Newly added one*/
}
I've updated your jsfiddle Example. Click here