Creating an Instagram-style frame effect for your HTML page using CSS

https://i.sstatic.net/SnkO7.jpg

Trying to figure out how to align images like in the picture above. Here's the code I've been working with:

<html>
<head>
<style>
.main
{
    width: 634px;
    height: 634px;
}
.img1
{
    width: 315px;
    height: 315px;
}
</style>
</head>
<body>
<img src="photo/01.jpg" class="main"><br>
<img src="photo/05.jpg" class="img1">
<img src="photo/01.jpg" class="img1">
<img src="photo/01.jpg" class="img1">
</body>
</html>

Looking to achieve an instaframe effect on my HTML page. Struggling to add images to the right side though.

Answer №1

To achieve the desired effect, you can utilize floating in your design:

.main {
  width:80%; /* set the width as needed */
  overflow:auto; /* clear the floats */
}

.main img {
  width:33.33%; /* make the images responsive, typically 3 images per row */
  height: auto; /* maintain image proportion by resizing height based on width */
  float:left; /* float the images to the left */
  border:2px solid white; /* add an optional border */
  box-sizing:border-box; /* ensure the border does not affect the total width */
}

.main img.big {
  width:66.66%; /* allocate 2/3 of the grid size to a big image */
}
<div class="main">
  <img src="https://placehold.it/100x100" class="big">
  <img src="https://placehold.it/100x100">
  <img src="https://placehold.it/100x100">
  <img src="https://placehold.it/100x100">
  <img src="https://placehold.it/100x100">
  <img src="https://placehold.it/100x100">
</div>

It's advisable to enclose the floated elements within a common parent to prevent them from affecting other page elements. In this example, the parent is <div class="main">.

Check out the demo on jsFiddle

Answer №2

To achieve this layout, you can utilize CSS3 flexbox. Check out the code snippet below; it's advisable to use % or ems instead of fixed height/width:

While floating elements, as mentioned in the previous answer, may result in a visually appealing layout, flexbox offers an alternative approach to attain the same results.

Take a look at the demo: jsFiddle

.main {
  width: 300px;
  height: 300px;
}

.img {
  width: 150px;
  height: 150px;
}

.rowContainer {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.columnContainer {
  display: flex;
  flex-direction: column;
}

.mainContainer {
  width: 450px
}
<div class="mainContainer">
    <div class="columnContainer">

      <div class="rowContainer">
        <img class="main">
        <div class="columnContainer">
          <img class="img">
          <img class="img">
        </div>
      </div>

      <div class="rowContainer">
        <img class="img">
        <img class="img">
        <img class="img">
        <img class="img">
        <img class="img">
        <img class="img">
      </div>
    </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

Basic stacked or segmented bar in HTML

Instead of starting from scratch, I'm in search of insights on how to develop a stacked/segmented bar or find an existing control for this purpose. Here are my requirements: Horizontal bar Standard html Color-coded segments using CSS Segments propor ...

Find a solution to splitting the area in half, with one side designated for the icon and the other for text

https://i.sstatic.net/Ov3yF.png I'm currently working on a code to assign tasks to employees, and I have created a login form with multiple text fields, each accompanied by an icon. However, there seems to be a layout issue as shown in the image. The ...

Ways to resolve the issue of being unable to retrieve data using jQuery

My code is working, but I am facing a little annoying problem that I can't solve on my own. The problem is that I can only retrieve the first record (id) from my data grid, but I can't retrieve the second or any other record id. For example: W ...

Delay the rendering of the MUI DataGrid column until after the DataGrid is visible on the screen

Would it be feasible to asynchronously load a column of data in the MUI DataGrid after the table is displayed on the screen? Retrieving this additional data from the database is time-consuming, so I aim to have it appear once the table has fully loaded. T ...

Exploring the depths: Retrieving nested object attributes using ngFor

Trying to display the "type" value in the ngFor table resulted in receiving object '[object Object]' of type 'object.' NgFor only supports binding to Iterables such as Arrays. json [{ "id": 123, "name": "Paul", "cars": { ...

Running a CSS keyframes animation can be achieved by removing the class associated with it

Is there a way to reverse the CSS animation when a class is removed? I'm trying to achieve this on my simple example here: https://codepen.io/MichaelRydl/pen/MWPvxex - How can I make the animation play in reverse when clicking the button that removes ...

When it comes to adjusting the height of an element, there are two ways to go about it: using $(element).height

function adjustHeight(){ var headerHeight=$(element).find('.header').outerHeight(); console.log(headerHeight); var temp=$(window).height()-headerHeight; console.log(temp); $('.users ...

Using Javascript to dynamically add SVGs from an array

Having issues with displaying SVG images in a quiz I'm building. I have a folder full of SVGs that correspond to each multiple choice option, but I can't seem to get the pathway right for them to show up properly. I've tried using template l ...

displaying a div upon checking the checkbox

How can I make a div push the content below it when it is in the show state? Currently, when I check the checkbox, the textarea covers the submit button, hiding it. Is there a way for the textarea to push the button down instead? You can find my code here: ...

Looking to sanitize an array of objects in Node.js? If you find that manually iterating through it only returns 'object Object', there are alternative methods to properly

I have a collection of items structured like this: var data = [ { msg: 'text' }, { src: 'pic.jpg',id: 21,title: 'ABC' } ]; My goal is to cleanse the values by manually iterating throug ...

What is the best way to retrieve the inner HTML or text content of a tag?

How can I retrieve the text value of an anchor tag in HTML using only golang.org/x/net/html, without external libraries? In my code sample below, I am able to extract the values of href and title with html.ElementNode. However, I need a way to specifically ...

The stacking order of React components

I am having an issue with the Z-index in my component-based React app. I currently have a list component that contains items, and I want to adjust the CSS scale and z-index to display one item in front of the others. The problem arises when the hovered it ...

Transforming the appearance of a clickable link when tapped

Is there a simple way in Bootstrap 5 to change the style of a clicked link to an "active" style while reverting the previously clicked link back to normal? Or is this something that would require custom CSS/JS? <ul class="nav nav-pills flex-column& ...

Is it possible to use the same identifier for both the name and id attributes in HTML?

In the world of coding, the "name" attribute is often used in server-side programming to send name/value pairs in requests. On the other hand, the "id" attribute is commonly utilized in client-side programming such as Javascript and CSS. However, both att ...

Divs that are floated and only partially visible at the end

My layout consists of 6 Divs floated left to create 6 columns. The width of all these floats combined may extend beyond the window width for most users, especially with the 6th column included. Is there a way for this 6th column to be partially visible ( ...

Align the text vertically in a Bootstrap button

Can anyone lend a hand with vertically aligning text in a Bootstrap button? When I use the align-middle class, the text is aligned as desired. However, if I use the align-top class, the text remains top-aligned no matter what I do. Any suggestions? Here& ...

Leverage Hubspot and Google Analytics to transfer session source and medium data

Is there a way to track session source and medium information in HubSpot to identify where a specific visit originated from before a form is filled out or another conversion event occurs? Ideally, this process would involve transferring the session and me ...

Getting real-time comments after they have been submitted in ReactJS

Is it possible to dynamically display newly added comments in real-time without refreshing the page after submitting them to the database through an API? Here's a snippet of the code I currently have: const PostWidget = ({ post }) => { ...

Dimensions of Bootstrap carousel

I am attempting to create a Bootstrap carousel with full-width images (width: 100%) and a fixed height. However, when I set the width to 100%, the height automatically takes on the same value. I am unsure if the issue lies within my files. <div id="m ...

Scaling down the screen for a smaller display

Having trouble achieving a specific effect and could use some assistance. My goal is to create an action where, upon clicking on the nav element (for simplicity, I've set it to be triggered by clicking anywhere on the body), the following should occur ...