Creating a Stunning Image Collage with Bootstrap and NuxtJS

I'm currently working on creating an image mosaic using a combination of Bootstrap, CSS, and NuxtJS. I have a total of five square images, with the first one needing to be positioned in the center. Specifically, two images should be aligned to the left side and two images to the right side relative to the central image. While I have managed to write some code for this layout, I am facing challenges in making it responsive for both mobile and desktop screens. Additionally, I am struggling to properly center the first image. Any assistance or guidance on how to address these issues would be greatly appreciated. Thank you!

  <div class="container d-flex flex-md-column flex-lg-row">
    <div class="small-tiles flex-md-row flex-lg-column">
      <img
        src="../../assets/images/image2.png"
        alt="The second image"
      />
      <img
        src="../../assets/images/image3.png"
        alt="The third image"
      />
    </div>
    <div class="center-tile d-flex flex-column">
      <img
        src="../../assets/images/image1.png"
        alt="The first image"
      />
    </div>
    <div class="small-tiles flex-md-row flex-lg-column">
      <img
        src="../../assets/images/image4.png"
        alt="The fourth image"
      />
      <img
        src="../../assets/images/image5.png"
        alt="The fifth image"
      />
    </div>
  </div>
</template>

<script>
export default {
}
</script>

<style lang="scss" scoped>

.container {
  width: 100%;
}

.small-tiles {
  @media only screen and (max-width: 576) {
    width: 100%;
    height: 25%;
  }
  @media only screen and (min-width: 576px) {
    width: 25%;
    height: 100%;
  }
}

.center-tile {
  @media only screen and (max-width: 576) {
    width: 100%;
    height: 50%;
  }
  @media only screen and (min-width: 576px) {
    width: 50%;
    height: 100%;
  }
}
</style>

Answer №1

Assuming all the images are square and of the same size, this code snippet generates a layout using only CSS:

https://i.sstatic.net/QMK0R.png

The grid consists of 3 columns: the first column has two areas, the second has one, and the third has two. Each area is filled with an image as a background. You can adjust the spacing and sizing according to your needs.

body {
  width: 100vw;
  height: 100vh;
}

.grid-container {
  width: 30%;
  aspect-ratio: 1;
  display: grid;
  grid-template-areas: 'pictl piccenter pictr' 'pictl piccenter pictr' 'picbl piccenter picbr' 'picbl piccenter picbr';
  grid-gap: 10px;
  background-color: white;
  padding: 10px;
  height: auto;
}

*[class^="pic"] {
  background-repeat: no-repeat no-repeat;
  background-size: contain;
  background-position: center center;
}

.pic1 {
  grid-area: pictl;
}


/* top left */

.pic2 {
  grid-area: picbl;
}


/* bottom left */

.pic3 {
  grid-area: piccenter;
}


/* center */

.pic4 {
  grid-area: pictr;
}


/* top right */

.pic5 {
  grid-area: picbr;
}


/* bottom right */

.pic1 {
  background-image: url(https://picsum.photos/id/1015/200/200);
}

.pic2 {
  background-image: url(https://picsum.photos/id/1016/200/200);
}

.pic3 {
  background-image: url(https://picsum.photos/id/1018/200/200);
}

.pic4 {
  background-image: url(https://picsum.photos/id/1019/200/200);
}

.pic5 {
  background-image: url(https://picsum.photos/id/1022/200/200);
}
<div class="grid-container">
  <div class="pic1"></div>
  <div class="pic2"></div>
  <div class="pic3"></div>
  <div class="pic4"></div>
  <div class="pic5"></div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discovering the art of incorporating various color palettes within a single stylesheet using HTML

I'm curious about incorporating multiple color schemes into a single stylesheet that can be activated by clicking, similar to the functionality found in platforms like WordPress and Magento. These platforms offer themes with various color options avai ...

Struggling with vertical alignment issues in a div element

Can anyone help me figure out how to vertically align a div? I've been struggling with it and can't seem to get it right. What am I missing? body { border: 1px solid red; height: 500px; } #contactUs { border: 1px solid blue; vertical-align: bo ...

The variation in CSS output between Google Chrome on Windows and Ubuntu

My code includes a div tag: <a href="#"><div class="field btn half green" id="register-btn">Register</div></a> Here is the CSS code for the tag: .field { position: absolute; width: 205px; left: 22px; color: #eaeae ...

Display the gridview using <div> elements rather than tables

Does anyone have a code snippet that can display a gridview within a <div> element instead of a table? I would greatly appreciate any assistance with this. I am trying to create a graph similar to the one I have included and would like some functi ...

Tips on updating the highlighted color of the item currently selected in NavBarDropdown using react-bootstrap

I've been utilizing the react-bootstrap NavDropDown component from this source. Although I initially set it up correctly, I'm struggling to customize the background color of the navdropdow-items when they are in their normal or active (selected) ...

Steps to keep the gridlines in the chart from moving

Take a look at the example provided in the following link: Labeling the axis with alphanumeric characters. In this particular instance, the gridlines adjust dynamically based on the coordinate values. How can we modify this so that the chart remains static ...

Build a photo carousel similar to a YouTube channel

Is there a way to create an image slider similar to the one on YouTube channels? I've noticed that when there are multiple videos on a channel, YouTube displays them in a slider with back and forth buttons to navigate through the videos that aren&apos ...

What could be causing the tooltip to malfunction in jQuery?

The tooltip is not appearing as expected, only the title is displaying in the browser. What can be done to fix this? Below is the code snippet: HTML Code: <form action="/validate.php" method="post" id="myform"> <table width="100%" border="1"> ...

Enter the variable into the parameter

I'm working with some Javascript code: document.getElementById("Grid").style.gridTemplateRows = "repeat(3, 2fr)"; I'm trying to insert a variable as an argument to modify my CSS style. When I attempt the following: "repe ...

Is it possible to position my label above my text box input?

Having trouble aligning the checkbox label with the edge of the text area in my login form code. It always ends up on the right side, outside of the div container when inspected. I've attempted setting a left value for the label, but it causes issues ...

Positioning a bootstrap badge flawlessly inside a block of text

The issue arises when adding a badge in the image below, as there seems to be more space above the badge than below it. Even though the Bootstrap 4 code is clean and untouched, it doesn't work seamlessly. Despite my attempts to adjust margins and line ...

Issue with the Z-Index property not functioning as expected on unordered lists within a dropdown menu

I have a dropdown menu that opens to the left, but it is displaying underneath the content. I attempted adjusting the z-index of the content to 1 and the dropdown to 2, however, this did not resolve the issue. Here is a sample in jsFiddle: https://jsfiddl ...

Having an absolute element can lead to overflow causing a scroll

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .wrap { ...

Apply CSS code to create a fading effect for a container

Below is the code for my accordion list, created using only CSS and HTML. Whenever a heading is clicked, the text slides in with a different background color. How can I make it so that the container with the text and different background color fades in and ...

Creating a Responsive Layout with Bootstrap Grid System and Incorporating HTML5 Elements and

I am currently working with the Bootstrap 4 grid system, and I have a specific layout in mind. I want to position an aside element along the right side of the screen. At the moment, my main content is enclosed in a col-xl-3 column. I would like the aside ...

Google Chrome - Automatically scroll to the bottom of the list when new elements are added in *ngFor loop

I have a basic webpage showcasing a list of videos. Towards the bottom of the page, there is a button labeled "Load more". When a user clicks on this button, an HTTP request is triggered to add more data to the existing array of videos. Here is a simplifi ...

CSS briefly displays overridden styles before applying the final styling

Presently, I have implemented a third-party library directive for a UI toggle button. I made some adjustments to the background color and positioning of the toggle button to align with my business requirements. Instead of the default light green for true a ...

Issue with absolute positioning occurs when the screen resolution or window size is altered, causing the feature to

Take a look at the code snippet below: <div style="position: relative;"> <div style="position: absolute; left: 10px; top: 18px;"> <img id="ImgTachoMetre" src="/Images/u174_normal.png"> </div> </div> I have wr ...

Tips for positioning an image in the TOP Right corner below the navbar using CSS

I am currently in the process of learning HTML and CSS, and I would like to practice and conduct research whenever I encounter difficulties. Recently, I have been attempting to style my landing page based on a screenshot that I took. However, I have been u ...

After submitting the form, Axios sends multiple requests simultaneously

Recently, I embarked on a small project that involves using Laravel and Nuxt Js. The main objective of the project is to create a form for adding users to the database. Everything seems to be progressing smoothly, but there's a minor issue that I&apos ...