What is the best way to arrange these elements and a sidebar to achieve this specific layout?

Need help aligning items in CSS to achieve this layout using flexbox. Thank you.

| Text   A | text   B | text   C | video |
| text   d | text   E | text   F | video |

The video is the same in both rows and should extend along the side as a sidebar.

.services {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  flex: 1 1 500px;
}

.serviceclasses {
  box-sizing: content-box;
  text-align: center;
  background-color: #f5f5f5;
  color: #000;
  text-align: center;
  padding: 30px;
  margin: 1px;
  color: #fff;
  border-radius: 10px;
  margin: 40px 20px;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.6);
}
<section id="s2">
  <h2>What do we do here?</h2>
  <br>
  <div id="list">
    <div class="services">
      <div><a href="" id="item1" class="serviceclasses">1</a></div>
      <div><a href="" id="item2" class="serviceclasses">2</a></div>
      <div><a href="" id="item3" class="serviceclasses">3</a></div>
      <div><a href="" id="item4" class="serviceclasses">4</a></div>
      <div><a href="" id="item5" class="serviceclasses">5</a></div>
      <div><a href="" id="item6" class="serviceclasses">6</a></div>
    </div>
    <div class="side">
      <aside class="video-sidebar">
        <figure>
          <figcaption>VIDEO</figcaption>
          <div class="video">
            <video controls>
              <source src = "felixynwa.mp4" width="20px" height="20px">
            </video>
          </div>
          <figcaption>VIDEO BOTTOM TEXT</figcaption>
        </figure>
      </aside>
    </div>
  </div>
  <br>
</section>

Answer №1

If you prefer not to modify your existing HTML structure:

#list {
  display: flex;
}

.services {
  display: grid;
  /* 2 rows of equal height, 3 columns of equal width */
  grid-template: 1fr 1fr / repeat(3, 1fr);
}

Give it a try:

#list {
  display: flex;
}

.services {
  display: grid;
  grid-template: 1fr 1fr / repeat(3, 1fr);
}


/* For demonstration purposes only */

#list, .services {
  gap: 1em;
}

.services div, .side {
  outline: 2px solid black;
}

.services a {
  display: block;
  border-radius: 10px;
  margin: 40px 20px;
  box-sizing: content-box;
  background-color: #f5f5f5;
  padding: 30px;
  text-align: center;
  color: #fff;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.6);
}
<div id="list">
  <div class="services">
    <div><a href="">1</a></div>
    <div><a href="">2</a></div>
    <div><a href="">3</a></div>
    <div><a href="">4</a></div>
    <div><a href="">5</a></div>
    <div><a href="">6</a></div>
  </div>
  <div class="side">
    <aside>
      <figure>
        <figcaption>VIDEO</figcaption>
        <div class="video">
          <video controls>
              <source width="20px" height="20px">
            </video>
        </div>
        <figcaption>VIDEO BOTTOM TEXT</figcaption>
      </figure>
    </aside>
  </div>
</div>

...or, if you decide to use display: contents:

#list {
  display: grid;
  /* 2 rows of equal height, 3 columns of equal width plus 1 column with automatic width */
  grid-template: 1fr 1fr / repeat(3, 1fr) auto;
}
#list {
  display: grid;
}
.services {
  /* Treat the element as if its children were direct children of #list */
  display: contents;
}

.side {
  /* Spans all rows, starting and ending at the last column */
  grid-row: 1 / -1;
  grid-column: -2; /* -2 denotes the second-to-last vertical grid line */
}

Test it out:

#list {
  display: grid;
  grid-template: 1fr 1fr / repeat(3, 1fr) auto;
}

.services {
  display: contents;
}

.side {
  grid-row: 1 / -1;
  grid-column: -2;
}


/* For demonstration purposes only */

#list {
  gap: 1em;
}

.services div, .side {
  outline: 2px solid black;
}

.services a {
  display: block;
  border-radius: 10px;
  margin: 40px 20px;
  box-sizing: content-box;
  background-color: #f5f5f5;
  padding: 30px;
  text-align: center;
  color: #fff;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.6);
}
<div id="list">
  <div class="services">
    <div><a href="">1</a></div>
    <div><a href="">2</a></div>
    <div><a href="">3</a></div>
    <div><a href="">4</a></div>
    <div><a href="">5</a></div>
    <div><a href="">6</a></div>
  </div>
  <div class="side">
    <aside>
      <figure>
        <figcaption>VIDEO</figcaption>
        <div class="video">
          <video controls>
              <source width="20px" height="20px">
            </video>
        </div>
        <figcaption>VIDEO BOTTOM TEXT</figcaption>
      </figure>
    </aside>
  </div>
</div>

References:

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

How can I use cookies to make an HTML div disappear when a button is clicked?

I've been attempting to conceal this message in Vue.js, but so far I haven't had any luck. Currently, I am utilizing the js-cookie library. My objective is as follows: HTML <div v-show="closeBox()"> < ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

Create personalized styles for each item within a stack with specific spacing using the @mui library

Is there a way to change both the background color and spacing area when hovering over each item in my list? https://i.stack.imgur.com/87TST.png <Stack spacing={4} divider={<Divider variant={`fullWidth`} orientation={`horizontal`} flexItem/>}> ...

You can only import Next.js Global CSS from your Custom <App> and not from any other files

Initially, my React App functioned perfectly with global CSS included. However, after running npm i next-images, adding an image, modifying the next.config.js file, and executing npm run dev, I encountered the following notification: "Global CSS cannot ...

jQuery plugin stops functioning properly following the use of the jQuery display block method

In my project, I am exploring the use of divs as tabs with jQuery. Within these divs, I also want to incorporate another jQuery plugin. Currently, I have manually created these div tabs using jQuery and set the default style for second and subsequent divs ...

Inject environment variable into SCSS file while using webpack

I'm new to webpack and I need help with reading a specific value, which is the env variable from the webpack.config.js file, in a sass file. This will allow me to have different CSS styles based on the environment. For example: If the env is set to ...

Adding alpha or opacity to the background image will give it a unique and

Is there a way to darken the background image while keeping the text color the same? Check out this code snippet on JSFiddle div { display:block; background:url('http://placehold.it/500x500') 0 0 no-repeat; background-color:rgba(0 ...

What could be causing Typed.js to not function properly in my situation?

Having an issue with typed.js not functioning properly. Here is the code snippet: <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-1.11.3.min.js"></script> <!-- Include all compiled plugins ...

Tips for decreasing the space between elements in flexbox using justify-content: space-between

I'm in the process of creating a footer for my website and I've decided to utilize flexbox for the layout. Below is the CSS code I am using for my footer: .footer { display: flex; flex-direction: row; align-items: center; justify-content ...

Grid system that adapts without distortion

My goal is to create a grid that maximizes the number of elements in its width without stretching them to fit the entire window. That's why I'm utilizing CSS grid with the auto-fill property, which is almost achieving the desired outcome. I want ...

The two <p> elements are being pushed to the right column, which is not their intended display

A snippet of less.css code is available at this link: #content { overflow: hidden; width: 100%; p { float: left; width: 465px; padding: 0px 25px 0px 35px; margin: 0px; br { line-height: 2. ...

Discover the perfect technique to employ insertString for effortlessly adding a new line onto a JEditorPane integrated with HTML functionality

Is there a difference between executing this code: conversationPane.setText(msg + conversationPane.getText()); and this code? conversationPane.setText(conversationPane.getText() + msg); I noticed that the second line does not display the message, but I ...

Steps to record and upload a video directly to the server using getusermedia

For my application, I need the user to record a video and have it saved on the server disk instead of downloading it to the client browser. I am currently using getusermedia for this purpose, with the following code: (function(exports) { exports.URL = exp ...

Center an image vertically in an AdminLte content-wrapper division

I am currently utilizing an AdminLte template as the framework for my design. In the designated area where I need to insert the main content, it is structured in the following manner: <div class="content-wrapper"> <se ...

Integrate a Google Maps API Javascript into a Flex application

I'm trying to incorporate a Google Maps API JavaScript into my Flex Application, but I have been unsuccessful so far despite looking at various examples. If anyone has any tips or guidance on how to achieve this, I would be extremely grateful for you ...

Is it advisable to incorporate the <main> element in my code?

While browsing through w3schools, I came across the <main> element. However, according to caniuse.com, this element is not supported by IE, Opera Mini, and the UC Browser for Android. Should I opt for using a <main> element instead or stick wi ...

Using JavaScript and jQuery to create a delay when handling input events

I am working on a project where I have an HTML table that retrieves its values from a database using jQuery Ajax. Here is an example: <div id="tableId"></div> Below is the JavaScript code: function showUser(rowsToShow) { request = $.get("s ...

Applying CSS transition delays to multiple images

I'm having trouble implementing a transition delay in my CSS. I've tried adding it in various places but it doesn't seem to be working as expected. This is my CSS: .imageBox { position: relative; float: left; transition ...

Place a vertical slider adjacent to an HTML element on either the left or right side

I'm struggling to bind a range slider to the left or right side of a canvas that displays video. Despite my efforts, CSS seems to be putting up a strong fight. I can handle issues like stretching and slider values, but attaching it to the canvas is pr ...

Optimizing Open Graph tags for sharing WhatsApp links

I am utilizing Open Graph tags to optimize sharing on social media platforms. The image I have specified is 1200 x 630 pixels and displays correctly on Facebook as well as Whatsapp: <meta property="og:image" content="https://emotionathlet ...