Create a plus sign using 5 images that is responsive

https://jsfiddle.net/n6mhg847/2/

I would want the images to be right next to each other.

Also responsive, staying as a plus image.

Like this: https://jsfiddle.net/15ta8c4n/

But staying as a plus sign, that isn’t a plus sign in there, just shows the responsiveness I am looking for.

Bing Chat (AI) came up with this:

I am thinking there is a better way to do it than this:

.container {
  position: relative;
  width: 200px;
  height: 200px;
}

.container img {
  position: absolute;
  width: 40px;
  height: 40px;
}

.container img:nth-child(1) {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.container img:nth-child(2) {
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.container img:nth-child(3) {
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

.container img:nth-child(4) {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.container img:nth-child(5) {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}
<div class="container">
  <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
  <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
  <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
  <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
  <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
</div>

This would be closer: https://jsfiddle.net/gyv2u9xr/1/

But I am sure there is a better way.

.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}

.block {
  width: 100px;
  height: 100px;
  background-size: cover;
}

.horizontal {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
}

@media (max-width: 600px) {
  .block {
    width: 50px;
    height: 50px;
  }
}
<div class="container">
  <div class="block" style="background-image: url('https://i.imgur.com/z5MMJnv.png');"></div>
  <div class="horizontal">
    <div class="block" style="background-image: url('https://i.imgur.com/5u16syR.png');"></div>
    <div class="block" style="background-image: url('https://i.imgur.com/ygTtvme.png');"></div>
    <div class="block" style="background-image: url('https://i.imgur.com/QziKNDW.png');"></div>
  </div>
  <div class="block" style="background-image: url('https://i.imgur.com/8Jf8LLc.png');"></div>
</div>

I understand that you just want C&P replies.

index.html

<!DOCTYPE HTML>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title>images display</title>

<link rel="stylesheet" href="screen.css" media="screen">


</head>
<body>

 <h1>Page description</h1>

 <div class="container">
  <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
  <div>
   <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
   <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
   <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
  </div>
  <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
</div>

</body>
</html>

screen.css

body {
    background-color: #f9f9f9;
    font: normal 1em / 1.5  arial, helvetica, sans-serif;
 }
 h1 {
   font-size: 1.5em;
   font-weight: normal;
   color: #555;
   text-align:center;
 }
 .container {
   max-width: 56.25em;
   margin: auto;
   border:1px solid #ccc;
   background-color: #fff;
 }
.container img {
   display: block;
   margin: auto;
   width:33.33%;
   height:auto;
 }
 .container div {
   display: flex;
   justify-content: center;
 }

p.s.

The page is fully responsive.

2 Likes

Are they going to be real images or just background colors?

If it’s just colors then you don’t need images.:wink:

Real images.

How would I apply the images as a plus sign,

so that they appear after modal is clicked:

Modal code:
https://jsfiddle.net/c27v03wt/5/

Responsive images as a plus sign:

https://jsfiddle.net/ywt65fdj/2/

Where it would be centered in the middle.

That’s ambiguous again,

After the modal is clicked you split the background in half and slide it out of the way. So do you want the background not to slide but instead show your plus sign of images?. Or do you want your plus sign of images to be under the split background and hiding the other videos. If so what happens next.

Responsive in what way?

Are those image what you wanted as all I see on a small height screen is one of them. It doesn’t look right to me at all but then again I have no idea what its supposed to look like. Are those images supposed to be aligned to the viewport so that they never scroll or are they just some arbitrary size?

There are to many undefined behaviours to make a stab at this at the moment until you clarify each stage.

How it should work is,

The five images as a plus sign should be centered where it would be able to be responsive.

The images would appear on top of the linear gradient background.

The size the plus sign could be, it could be set to any number that is given to it.

After clicking modal, the plus sign as images would appear on the screen, where then it would split in half revealing the videos behind it.

Does this answer all your questions?

Responsive in what way?

Do you want just one image taking up the whole viewport but you’d have to scroll to see all the other images horizontally and vertically?

Or do you always want all 5 images to stay wholly in the viewport no matter how small or big the viewport?

That doesn’t make sense as I said because one image may be 2000x 2000 initially. It could still be responsive but it wouldn’t all fit in the viewport.

Clarity is important here.

I’m guessing you want 5 images with a fixed aspect to to always remain within the viewport. This is totally different to what you have now.

So you are not splitting the multiple squares background anymore?

This would suggest that when you click the modal then suddenly your Plus sign of images appear out of nowhere and then split in half leaving the gradient square background in place?

As you see there are still too many unanswered questions to bother offering coder yet.

Lastly if you want the 5 images to split in half then you can’t simply split them in half. You will need to use the method utilised in your previous curtains where the image needed to be duplicated on both sides and then only half of it shown.

For your plus sign of images that would mean that all the 3 middle images would need to be duplicated then cut in half and then placed side by side to make whole images as in the curtain example. That’s a lot of work!

1 Like

The plus sign would be on top of the linear gradient.

Both would be split in half.

Clicking model would reveal the plus sign that is on top of the gradient where both would split in half.

Maybe the images are each 360 by 360.

The container around it would determine how big the plus sign starts out as.

  .container {
     max-width:
}

I created a hover code it could be tested on:

https://jsfiddle.net/n9osL7xa/

Here is the responsive plus sign centered in the middle: https://jsfiddle.net/7k05bqLp/1/

Next would be, somehow, combining them both and then splitting it in half.

Do you mean this:

I’ve slowed the hover down so you can see whats happening.

2 Likes

Yes, I mean that.

How would I add that to the modal code?

If you already have code for the left and right panels to open then you don’t need to do anything as the images are sitting inside the same panels which are what you are animating. Just add the css and html and it should work.

1 Like

I almost have it working: https://jsfiddle.net/emdv2qz6/1/

These would get changed to what?

.modal:not(.open)~.panel-left {
  transform: translateX(-100%);
}

.modal:not(.open)~.panel-right {
  transform: translateX(100%);
}

This?

.container .modal:not(.open)~.panel-left {
  transform: translateX(-100%);
}

.container .modal:not(.open)~.panel-right {
  transform: translateX(100%);
}

Remove the .container that wraps the left and right panels as that is not needed andmay conflict with your other containers,

Then change the css to this:

 .modal:not(.open)~.panel-left {
  transform: translateX(-100%);
}

 .modal:not(.open)~.panel-right {
  transform: translateX(100%);
}

It’s not splitting: https://jsfiddle.net/cpybvLex/2/

What else needs to be adjusted?

.panel-left,
.panel-right {
  position: fixed;
  height: 100%;
  width: 50%;
  top: 0%;
  overflow: hidden;
  z-index: 0;
  transform: translateX(0);
  transition: transform 7s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition-delay: 1s;
}

.panel-left.slide {
  left: 0;
}

.panel-right.slide {
  right: 0;
}

.panel-left::before,
.panel-right::before {
  content: "";
  position: fixed;

  height: 100%;
  width: 200%;
  top: 0;
  left: 0;

  background-image: linear-gradient(var(--color-a) 5px, #0000 5px),
    linear-gradient(90deg, var(--color-a) 5px, #0000 5px),
    linear-gradient(var(--color-b) 10px, #0000 10px 160px, var(--color-b) 160px),
    linear-gradient(
      90deg,
      var(--color-b) 10px,
      #0000 10px 160px,
      var(--color-b) 160px
    ),
    linear-gradient(var(--color-c) 15px, #0000 15px 155px, var(--color-c) 155px),
    linear-gradient(
      90deg,
      var(--color-c) 15px,
      #0000 15px 155px,
      var(--color-c) 155px
    ),
    linear-gradient(var(--color-d) 20px, #0000 20px 150px, var(--color-d) 150px),
    linear-gradient(
      90deg,
      var(--color-d) 20px,
      #0000 20px 150px,
      var(--color-d) 150px
    ),
    linear-gradient(var(--color-a) 25px, #0000 25px 145px, var(--color-a) 145px),
    linear-gradient(
      90deg,
      var(--color-a) 25px,
      #0000 25px 145px,
      var(--color-a) 145px
    ),
    linear-gradient(var(--color-b) 30px, #0000 30px 140px, var(--color-b) 140px),
    linear-gradient(
      90deg,
      var(--color-b) 30px,
      #0000 30px 140px,
      var(--color-b) 140px
    ),
    linear-gradient(var(--color-c) 35px, #0000 35px 135px, var(--color-c) 135px),
    linear-gradient(
      90deg,
      var(--color-c) 35px,
      #0000 35px 135px,
      var(--color-c) 135px
    ),
    linear-gradient(var(--color-d) 40px, #0000 40px 130px, var(--color-d) 130px),
    linear-gradient(
      90deg,
      var(--color-d) 40px,
      #0000 40px 130px,
      var(--color-d) 130px
    ),
    linear-gradient(var(--color-a) 45px, #0000 45px 125px, var(--color-a) 125px),
    linear-gradient(
      90deg,
      var(--color-a) 45px,
      #0000 45px 125px,
      var(--color-a) 125px
    ),
    linear-gradient(var(--color-b) 50px, #0000 50px 120px, var(--color-b) 120px),
    linear-gradient(
      90deg,
      var(--color-b) 50px,
      #0000 50px 120px,
      var(--color-b) 120px
    ),
    linear-gradient(var(--color-c) 55px, #0000 55px 115px, var(--color-c) 115px),
    linear-gradient(
      90deg,
      var(--color-c) 55px,
      #0000 55px 115px,
      var(--color-c) 115px
    ),
    linear-gradient(var(--color-d) 60px, #0000 60px 110px, var(--color-d) 110px),
    linear-gradient(
      90deg,
      var(--color-d) 60px,
      #0000 60px 110px,
      var(--color-d) 110px
    ),
    linear-gradient(var(--color-a) 65px, #0000 65px 105px, var(--color-a) 105px),
    linear-gradient(
      90deg,
      var(--color-a) 65px,
      #0000 65px 105px,
      var(--color-a) 105px
    ),
    linear-gradient(var(--color-b) 70px, #0000 70px 100px, var(--color-b) 100px),
    linear-gradient(
      90deg,
      var(--color-b) 70px,
      #0000 70px 100px,
      var(--color-b) 100px
    ),
    linear-gradient(var(--color-c) 75px, #0000 75px 95px, var(--color-c) 95px),
    linear-gradient(
      90deg,
      var(--color-c) 75px,
      #0000 75px 95px,
      var(--color-c) 95px
    ),
    linear-gradient(var(--color-d) 80px, #0000 80px 90px, var(--color-d) 90px),
    linear-gradient(
      90deg,
      var(--color-d) 80px,
      #0000 80px 90px,
      var(--color-d) 90px
    ),
    linear-gradient(var(--color-a), var(--color-a));
  background-size: 165px 165px;
}

.panel-right::before {
  left: -100%;
}
.modal:not(.open) ~ .panel-left {
  transform: translateX(-100%);
}

.modal:not(.open) ~ .panel-right {
  transform: translateX(100%);
}

.inner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 200%;
  position: absolute;
  left: 0;
  z-index: 2;
}
.panel-right .inner {
  left: -100%;
}

.container2 {
  max-width: 360px;
  border: 1px solid #ccc;
}

.container2 div {
  display: flex;
  justify-content: center;
}

.container2 img {
  display: block;
  margin: auto;
  width: 33.33%;
  height: auto;
}
<div class="container">
  <div class="slide panel-left">
    <div class="inner">
      <div class="container2">
        <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
        <div>
          <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
          <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
          <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
        </div>
        <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
      </div>
    </div>
  </div>

  <div class="slide panel-right">
    <div class="inner">
      <div class="slide container2">
        <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
        <div>
          <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
          <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
          <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
        </div>
        <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
      </div>
    </div>
  </div>

Read my previous post then look at your html.

Remove slide from the panels and add it to


.container

I’m confused.

.

panel-left.slide {
  left: 0;
}

.panel-right.slide {
  right: 0;
}

I’m confused:

The only properties in the HTML and the CSS that slide should be added are?

Who said anything about remove slide???

Which then leaves it like this:

<div class="slide panel-left">
  <div class="inner">
    <div class="container2">
      <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
      <div>
        <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
        <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
        <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
      </div>
      <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
    </div>
  </div>
</div>

<div class="slide panel-right">
  <div class="inner">
    <div class="slide container2">
      <img src="https://i.imgur.com/z5MMJnv.png" alt="Image 1">
      <div>
        <img src="https://i.imgur.com/5u16syR.png" alt="Image 2">
        <img src="https://i.imgur.com/ygTtvme.png" alt="Image 3">
        <img src="https://i.imgur.com/QziKNDW.png" alt="Image 4">
      </div>
      <img src="https://i.imgur.com/8Jf8LLc.png" alt="Image 5">
    </div>
  </div>
</div>
1 Like

should vh be changed to %

in here?

Both work in the code?

.inner {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 200%;
  position: absolute;
  left: 0;
  z-index: 2;
}

It makes no difference as it stands but percent refers to the parent so if you ever changed the parents size then the vh unit wouldn’t match.

The % is the more reliable option as it matches the parent.

1 Like