Overlap Multiple Images In A Row - css

I know there are several threads on the "overlapping images" topic, but I can't find one that addresses my specific problem.
I have five circular images and I need to display them with slight overlap, kind of like how a deck of cards looks when it's laid out in a fan.
Here is what it should look like:
Here is what I currently have:
All the code examples I've found are aimed at overlapping two square images and I can't figure out how to translate to this scenario. Any help would be greatly appreciated.
I've tried messing around with grid layout and negative margins, but it was just a huge mess.
I can't share the source code but I've recreated the exact same HTML/CSS with dummy data in this codepen.
Code:
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5" />
</div>
</div>
</div>

You can use margin-right/margin-left on the icon . To overlap, let margin-right have negative values
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
margin-right: -15px;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5">
</div>
</div>
</div>

Related

Bootstrap header will not change the image size

I'm desperate trying to make this work, but I'm not sure what I'm doing anymore. For some reason the images in the small viewports are smaller than their appearance in large viewports, so I am stumped.
<div class="container-fluid p-2">
<div class="flex-row">
<div class="d-flex justify-content-center justify-content-xl-between align-items-center flex-wrap">
<div class="d-flex p-2">
<img id="logo" class="img-fluid" src="img/croppedlogo.svg" style="min-width: 300px; max-width: 100%;">
</div>
<div class="w-100 d-none d-sm-flex d-xl-none"></div>
<div class="d-none d-sm-flex p-2">
<div>
<a class="headerLink" href="index.aspx">Home</a>
<a class="headerLink" href="index.aspx">Products</a>
<a class="headerLink" href="index.aspx">About</a>
<a class="headerLink" href="index.aspx">Blog</a>
<a class="headerLink" href="index.aspx">Contact</a>
</div>
</div>
<div class="d-flex d-sm-none p-2">
<img src="img/menu.png">
</div>
<div class="w-100 d-xl-none"></div>
<div class="p-2">
<a href="index.aspx">
<img src="img/btnLogin.png" />
</a>
<a href="index.aspx">
<img src="img/btnRequestDemo.png" />
</a>
<a href="index.aspx">
<img src="img/btnResources.png" />
</a>
</div>
</div>
</div>
</div>
Here's the small amount of extra CSS I have:
body {
margin: 0px;
font-family: Arial;
font-size: 1em;
background-color: #FBFBFD;
}
.headerLink + .headerLink {
margin-left: 10px;
}
a.headerLink {
color: black;
text-decoration: none;
font-weight: bold;
padding: 0px;
}
a.headerLink:hover {
text-decoration: underline;
}
button png images are between 100px x 50px to 200px x 50px
Header for logo is as follows:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="logo" x="0px" y="0px" viewBox="49.199989318847656 82.18773651123047 697.5000610351562 155.11227416992188" style="enable-background:new 0 0 792 330;" xml:space="preserve">
viewBox="0 0 792 330" style="enable-background:new 0 0 792 330;" xml:space="preserve">>
I am trying to get it so that the images span across the width of the screen in smaller viewports, but as it stands, the layout is even smaller in a phone than it is on the full desktop setting.
Any help would be greatly appreciated
From the way you wrote your code I understand that your problem is in smaller screens, so based on what you have I wrote the code below:
body {
margin: 0px;
font-family: Arial;
font-size: 1em;
background-color: #fbfbfd;
}
.headerLink+.headerLink {
margin-left: 10px;
}
a.headerLink {
color: black;
text-decoration: none;
font-weight: bold;
padding: 0px;
}
a.headerLink:hover {
text-decoration: underline;
}
#media all and (max-width: 768px) {
figure img {
width: 150px;
height: 50px;
object-fit: cover;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div class="container-fluid p-2">
<div class="flex-row">
<div class="d-flex justify-content-center justify-content-xl-between align-items-center flex-wrap">
<div class="d-flex p-2">
<img id="logo" class="img-fluid" src="img/croppedlogo.svg" style="min-width: 300px; max-width: 100%;">
</div>
<div class="w-100 d-none d-sm-flex d-xl-none">
<div class="d-none d-sm-flex p-2">
<div>
<a class="headerLink" href="index.aspx">Home</a>
<a class="headerLink" href="index.aspx">Products</a>
<a class="headerLink" href="index.aspx">About</a>
<a class="headerLink" href="index.aspx">Blog</a>
<a class="headerLink" href="index.aspx">Contact</a>
</div>
</div>
</div>
<div class="d-flex d-sm-none p-2">
<img src="img/menu.png">
</div>
<div class="w-100 d-xl-none"></div>
<figure class="d-flex p-2">
<a href="index.aspx">
<img src="img/btnLogin.png" />
</a>
<a href="index.aspx">
<img src="img/btnRequestDemo.png" />
</a>
<a href="index.aspx">
<img src="img/btnResources.png" />
</a>
</figure>
</div>
</div>
</div>
Note that I renamed the div responsible for the images to figure just to make the CSS work easier, but you can call it whatever you want.
You want the images to take up the entire width of the screen in smaller viewports but you said the images are between 100px and 200px wide, so it's not clear if you want to resize them, but as an example I used 150px in CSS to be able to illustrate the example.
Notice that I used object-fit: cover for the image to maintain its proportions and fill the dimension provided. But here the image can be cropped to fit. But if you want to expand them at all costs you can use a width: 100vw; object-fit: fill;
On this specific image issue I recommend you check out this link from W3 Schools: CSS The object-fit Property.
As for the .svg you provided I wasn't able to insert it into your code as I don't know its exact location.
If you have any questions, just comment here that according to your needs I will update my answer.

How to Keep divs in CSS Gallery in Line, or All The Same Size or Both?

I am working with the code below from w3schools to make a gallery. The problem I have is that if one item has a rather long description it causes the items below to become disordered and not line up properly.
As far as I can tell this can be solved by making the item boxes either all the same height or by having a set gap between each row from the bottom of the tallest on the top row to the top of all three on the bottom row. I do not know how to do either of these.
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="overflow: hidden;">
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_5terre.jpg">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="600" height="400">
</a>
<div class="desc">Add a description of the image here and make it really long to see what happens</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_forest.jpg">
<img src="https://www.w3schools.com/css/img_forest.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_lights.jpg">
<img src="https://www.w3schools.com/css/img_lights.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_mountains.jpg">
<img src="https://www.w3schools.com/css/img_mountains.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
</body>
</html>
Does anyone have a solution to how they can be kept inline neatly?
display:flex offers a really neat way to organise items like this. You can have everything stretch to the same height as the tallest item in it's row, or you can align them in a bunch of different ways with only a few lines of code to the parent container.
For more info: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.gallery-container {
display: flex;
align-items: stretch;
flex-wrap: wrap;
}
div.gallery {
margin: 5px;
border: 1px solid #ccc;
/*float: left;*/
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="gallery-container">
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_5terre.jpg">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="600" height="400">
</a>
<div class="desc">Add a description of the image here and make it really long to see what happens</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_forest.jpg">
<img src="https://www.w3schools.com/css/img_forest.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_lights.jpg">
<img src="https://www.w3schools.com/css/img_lights.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_mountains.jpg">
<img src="https://www.w3schools.com/css/img_mountains.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
</body>
</html>
The answer above works well and I want to add one more thing to it. If you want to align the description vertically, you can again use the Flexbox. I have added it in the CSS code here.
.gallery-container {
display: flex;
align-items: stretch;
flex-wrap: wrap;
}
div.gallery {
margin: 5px;
border: 1px solid #ccc;
width: 180px;
/* To align the description both horizontally and vertically*/
display: flex;
flex-direction: column;
justify-content: center;
align-items:center;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="gallery-container">
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_5terre.jpg">
<img src="https://www.w3schools.com/css/img_5terre.jpg" alt="Cinque Terre" width="600" height="400">
</a>
<div class="desc">Add a description of the image here and make it really long to see what happens</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_forest.jpg">
<img src="https://www.w3schools.com/css/img_forest.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_lights.jpg">
<img src="https://www.w3schools.com/css/img_lights.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="https://www.w3schools.com/css/img_mountains.jpg">
<img src="https://www.w3schools.com/css/img_mountains.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
</body>
</html>

Using Bootstrap Grid, Why Can I Not Space Out My Divs?

I'm working on my first web dev portfolio and am trying to incorporate the Bootstrap Grid system to the project links. I've searched through Bootstrap's documentation (v4.5), Stack Overflow, and just googling various searches to death. I've tried every solution I've found and am still getting nowhere. The closest I've come to a result is changing all three col-lg-4 to col-lg33. That did create the space, but then the padding looked super weird and it was more space than I needed. Any help would be super appreciated. I'm a but of a noob still.
<section id="projects">
<h2>My Work</h2>
<div class="container">
<div class="row justify-content-around">
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project"/>
<p class="project-title">CSS Technical Document</p>
</a>
</div>
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/Javascript30DrumKit/" target="_blank">
<img class="project-image" src="Images/JavascriptDrumkit.png" alt="project"/>
<p class="project-title">Javascript Drumkit</p>
</a>
</div>
<div class="col-lg-4 col-md-6 projects-grid">
<a href="https://briafly27.github.io/FirstPersonalSite/" target="_blank">
<img class="project-image" src="Images/FirstPersonalSite.png" alt="project"/>
<p class="project-title">First Personal Site</p>
</a>
</div>
</div>
</div>
</section>
#projects {
background: #3F3F44;
color: #f7f7f7;
font-family: 'Raleway', sans-serif;
height: 100vh;
}
#projects h2 {
text-shadow: 1px 1px #fdcb9e;
text-align: center;
padding: 60px;
}
.projects-grid {
background-color: #fdcb9e;
box-shadow: 5px 8px black;
border-radius: 10px;
padding: 1% 0;
}
.projects-grid:hover {
background-color: #cceabb;
box-shadow: 7px 10px black;
}
.projects-grid a {
text-decoration: none;
color: #3f3f44;
text-shadow: 1px 1px #cceabb;
}
.project-image {
height: 100%;
max-height: 170px;
width: 100%;
max-width: 300px;
border-radius: 10px;
border: 2px solid #cceabb;
display: flex;
margin: 0 auto;
}
.project-image:hover {
border: 2px solid #fdcb9e;
}
.project-title {
font-size: 1.5rem;
font-weight: 700;
padding-top: 8px;
padding-bottom: 4px;
margin: 0;
text-align: center;
}
Bootstrap is adding the column guttering as a 15px padding, by styling the layout there, you are also styling the padding that is the guttering, hence the project grid 'cards' are touching.
For this, to keep the guttering and to ensure nice even columns, I would style a nested div instead.
<div class="col-md-4">
<div class="projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
</div>
If the guttering is too large, you can change the sass variable (it's set to 30px by default) or you can use .no-gutters to remove all the guttering and add the padding manually to the nested divs.
<div class="row no-gutters">
<div class="col-md-4 p-2">
<div class="projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
</div>
</div>
I've created this link on Codepen to try understanding better the problem so that we can help you better:
https://codepen.io/maricaldas/pen/ExPKNzM
<section id="projects">
<h2>My Work</h2>
<div class="container">
<div class="row justify-content-around">
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/TechnicalDocumentAssignment/" target="_blank">
<img class="project-image" src="Images/TechnicalDoc.png" alt="project" />
<p class="project-title">CSS Technical Document</p>
</a>
</div>
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/Javascript30DrumKit/" target="_blank">
<img class="project-image" src="Images/JavascriptDrumkit.png" alt="project" />
<p class="project-title">Javascript Drumkit</p>
</a>
</div>
<div class="col-lg-3 col-md-6 projects-grid">
<a href="https://briafly27.github.io/FirstPersonalSite/" target="_blank">
<img class="project-image" src="Images/FirstPersonalSite.png" alt="project" />
<p class="project-title">First Personal Site</p>
</a>
</div>
</div>
</div>
</section>
Do you mean you want a space separating the project-grid columns?
If so, the first thing we need to consider is that when we use 3 columns taking 4 spaces each, we're using the full grid, which is 12, and that's why we can't see spaces around those col-lg-4 columns.
Can you please elaborate a little bit more on the result you want to achieve?
Maybe a way to add that space among the columns while using col-lg-4 is to overwrite the bootstrap pre-set width, which is 33.33%.
#media (min-width: 992px) {
.col-lg-4 {
-ms-flex: 0 0 32%;
flex: 0 0 32%;
max-width: 32%;
}
}

how to set width for item inside flex overflown [duplicate]

This question already has an answer here:
Why is a flex item limited to parent size?
(1 answer)
Closed 3 years ago.
I got code like this
.divA {
background: red;
width: 500px;
display: flex;
flex-direction: row;
overflow-y: scroll;
}
.epi {
width: 50%;
background: blue;
}
<div class="divA">
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
</div>
I'm expecting this
But I'm getting this
I want item in .divA has the width of 50% of .divA
Edit: Since you don't want it to wrap, but scroll horizontally, you can put it as overflow-x: scroll;
.divA {
background: red;
width: 500px;
display: flex;
justify-content: flex-start;
overflow-x: scroll;
overflow-y: auto;
}
.epi {
min-width: 50%;
background: blue;
}
<div class="divA">
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
</div>

How to remove blank between div?

I have a problem with CSS.
.special-banner{
width: 100vw;
position: relative;
}
.special-banner > img{
width: 100%;
height: 100%;
}
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_01_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_02_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_03_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_04_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_05_renew.png"/>
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_06_renew.png"/>
</div>
As you can see, there are some White line.
I want to remove them.
Also, I have 1 solution.
Using display: flex.
It's efficient but I can't use that.
Do you have another solution?
I guess it causes with display:block..
I don't know if you added display:block or not, but putting it in the img style removes the white line
.special-banner {
width: 100vw;
position: relative;
}
.special-banner>img {
width: 100%;
height: 100%;
display: block;
}
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_01_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_02_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_03_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_04_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_05_renew.png" />
</div>
<div class="special-banner">
<img src="http://wanho1108.dothome.co.kr/hmb/web/n_himages/sub/sub_point_use_banner_06_renew.png" />
</div>
try applying float:left for .special-banner and .special-banner > img
.special-banner,.special-banner > img{
float: left;
}

Resources