I'm planning to position some images in a circle background image but it doesn't seem to work well.
My goal is to center these images behind and inside the circle.
Any help?
div.info_image {
text-align: center;
border: none;
background: url("http://japancrystal.altervista.org/themes/crystal/imgs/colonna_sx/cerchio_descrizioneluogo.png");
background-repeat: no-repeat;
background-position: center;
height: 220px;
width: 100%;
}
img.img_place{
text-align: center;
border-radius: 100%;
width: 155px;
height: 155px;
margin-top: 30px;
margin-left: 30px;
}
<div class="info_image">
<img src="http://japancrystal.altervista.org/themes/crystal/imgs/locations/ingresso.png" class="img_place">
</div>
JSFIDDLE DEMO
RESULT DEMO
You can add this code to your img_place class :
img.img_place {
position: relative;
z-index: -1;
}
Try this :
div.info_image {
position: relative;
background: url(http://japancrystal.altervista.org/themes/crystal/imgs/colonna_sx/cerchio_descrizioneluogo.png);
background-repeat: no-repeat;
background-position: center;
height: 220px;
}
img.img_place {
position: absolute;
top: calc(50% + 3px);
left: calc(50% + 7px);
transform: translate(-50%, -50%);
border-radius: 100%;
height: 173px;
z-index: -1;
}
Try this.
div.info_image {
border: none;
background: url("http://japancrystal.altervista.org/themes/crystal/imgs/colonna_sx/cerchio_descrizioneluogo.png") no-repeat center center;
height: 220px;
width: 244px;
display: flex;
justify-content: center;
align-items: center;
}
img.img_place {
border-radius: 100%;
width: 173px;
height: 173px;
transform: translate(8px, 3px);
position: relative;
z-index: -1;
}
<div class="info_image">
<img src="http://japancrystal.altervista.org/themes/crystal/imgs/locations/ingresso.png" class="img_place">
</div>
Not sure why your images don't show in snippet, but they do in this fiddle...
FIDDLE
You can use display: grid to place them on top of each other.
Because the "ring" image isn't placed with the circle in the middle, I had to use transform: translate to move it, which changed the stacking order too. That's why there is a z-index of -1 on the city image.
For some reason, justify-content: center and align-items: center on .info_image didn't work as well as using self-justify and self-align on the images.
div.info_image {
display: grid;
grid-template-areas: "stacked";
height: 220px;
width: 100%;
}
.info_image > img {
--img-size: 155px;
border-radius: 50%;
grid-area: stacked;
width: var(--img-size);
justify-self: center;
align-self: center;
}
.info_image > .city {
--img-size: 110px;
transform: translate(5px, 2px);
z-index: -1;
}
<div class="info_image">
<img class="city" src="https://japancrystal.altervista.org/themes/crystal/imgs/locations/ingresso.png" />
<img src="https://japancrystal.altervista.org/themes/crystal/imgs/colonna_sx/cerchio_descrizioneluogo.png" />
</div>
Related
I'm trying to center text over an image; however, whenever I resize it, the text does not stay vertically centered.
.hero-image {
margin: 0 auto;
}
.hero-image img {
width: 100%;
}
.hero-text {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
<div class="hero-image">
<img src="https://content.codecademy.com/courses/freelance-1/unit-4/img-mission-background.jpg">
<div class="hero-text">
Here is the hero text
</div>
</div>
Here's what's happening:
Working properly:
Vertical centering is off when resizing:
Your css for your hero text looks good – If I'm understanding your question correctly, I think the image should be modified to use 100 viewport width / height rather than 100%.
body {
margin: 0;
}
.hero-image img {
width: 100vw;
height: 100vh;
object-fit: cover;
}
.hero-text {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
You need to set the boundary of the container for positioned child. Add position: relative to .hero-image class. Otherwise it's using the next relative parent for it.
.hero-image {
margin: 0 auto;
position: relative;
}
.hero-image img {
width: 100%;
}
.hero-text {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: red;
}
<div class="hero-image">
<img src="https://content.codecademy.com/courses/freelance-1/unit-4/img-mission-background.jpg">
<div class="hero-text">
Here is the hero text
</div>
</div>
You can try this translate-free solution:
.hero-text {
position: absolute;
top: 33vw;
text-align: center;
width: 100%;
}
If you plan to keep the image stretched over the whole width.
You can do it with "display: flex".
.hero-image {
background-image: url(https://content.codecademy.com/courses/freelance-1/unit-4/img-mission-background.jpg);
background-size: cover;
background-position: center;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.hero-image img {
width: 100%;
}
.hero-text {
}
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 !
I want to make that white check mark into the green.
I set the check's size into 100px for now.
.approvalContainer {
align-self: flex-end;
width: 24px;
height: 24px;
background-color: var(--color-background-success-dark);
vertical-align: flex-end;
}
.approvalIcon {
width: 100px;
height: 100px;
}
dom structure
<div style=approvalContainer>
<svg style=approvalIcon/>
</div>
Plenty of ways to skin a cat here. This could be one, noting that I swapped the svg to another div purely for this example. Also note that the html you provided is not syntactically correct.
.approvalContainer {
align-self: flex-end;
position: relative;
display: block;
width: 48px;
height: 48px;
background-color: #0f0;
border-radius: 50%;
vertical-align: flex-end;
}
.approvalIcon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
color: #fff;
}
<div class="approvalContainer">
<div class="approvalIcon">√</div>
</div>
I'd like to put news titles on image background like this:
What I came up with, is this:
<div class="image-container">
<img src="/path/to/img" class="img-thumbnail">
<div class="text-block">
<div class="bottom-right">My News Title</div>
</div>
</div>
CSS:
.text-block {
position: absolute;
bottom: 0px;
right: 0px;
background-color: #fff;
opacity: .8;
color: black;
width: 100%;
}
.bottom-right {
color: black;
position: absolute;
bottom: 8px;
right: 16px;
background-color: #fff;
}
Which results in this:
My problem is how to modify my code so that the title appears on a semi-transparent background which covers 1/3 of the bottom of the block, like the coffee picture above?
You could clean up the markup a bit and use a simple container element with a title (e.g. a div and a heading).
As noted by #zero298 if the image doesn't convey any information it should be defined as a background of the container
Codepen demo
Markup
<div style="background-image: url(https://.../coffee-serum-300x240.jpg)">
<h2>
The title of this article
may span across several lines.
but it's always anchored on the bottom
</h2>
</div>
CSS
div {
width: 300px;
height: 240px;
background-size: cover;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
div h2 {
background: rgba(255, 255, 255, .6);
margin: 0;
padding: 1em 1em 3em 1em;
}
Final result
Since the image is decorative, use background-image:
.card {
width: 100px;
height: 200px;
color: white;
background-color: blue;
background-image: url(https://cdn.sstatic.net/Sites/stackoverflow/img/sprites.svg);
background-size: contain;
background-position: center;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.text{
background-color: rgba(1,1,1,0.5);
}
<div class="card">
<div class="text">
<h2>Hello World</h2>
<p>Foo bar</p>
</div>
</div>
You could do the following :
.bottom-right {
color: black;
position: absolute;
bottom: 50%;
right: 50%;
background-color: #fff; }
.image-container {
position: relative;
text-align: center;
color: white; }
.text-block {
position: absolute;
top: 95%;
left: 50%;
height: 40%;
transform: translate(-50%, -50%); }
Also, I think this is very helpful form w3schools.
https://www.w3schools.com/howto/howto_css_image_text.asp
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>