When a child element within a flex container has a relative position, the flex direction column will be overridden and

I'm having trouble with the code snippet below.

For the .container, I have set

display:flex;
flex-direction: column;

in order to position my previous and next arrows before and after the container items. However, the flex direction does not change from row.

.container {
  margin: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid green;
  display: flex;
  flex-direction: column;
}

.items {
  left: 0;
  top: 0;
  display: flex;
  flex-direction: row;
  padding: 0.5rem 0;
  position: relative;
  margin: 2px;
}

.item {
  align-items: center;
  display: flex;
  height: 60px;
  justify-content: center;
  margin: 2px;
}

.item>* {
  cursor: pointer;
  display: flex;
  max-height: 100%;
}

.item img {
  display: block;
  max-height: 100%;
}

.previous::before,
.next::before {
  color: #9e9e9e;
  font: 400 1.5rem/1 iconfont !important;
  speak: none;
  text-transform: none !important;
}
<div class="container">
  <div class="previous">S</div>
  <div class="items">
    <div class="item">
      <a href="#"><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
  </div>
  <div class="next">S</div>
</div>

Answer №1

To properly align the arrows inline with the items, you should consider removing flex-direction: column from the .container class.

.container {
  margin: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid green;
  display: flex;
  align-items: center
}

.items {
  left: 0;
  top: 0;
  display: flex;
  padding: 0.5rem 0;
  position: relative;
  margin: 2px;
  flex: 1;
  background: lightblue;
  justify-content: center
}

.item {
  align-items: center;
  display: flex;
  height: 60px;
  justify-content: center;
  margin: 2px;
}

.item>* {
  cursor: pointer;
  display: flex;
  max-height: 100%;
}

.item img {
  display: block;
  max-height: 100%;
}

.previous::before,
.next::before {
  color: #9e9e9e;
  font: 400 1.5rem/1 iconfont !important;
  speak: none;
  text-transform: none !important;
}
<div class="container">
  <div class="previous">S</div>
  <div class="items">
    <div class="item">
      <a href="#"><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
    <div class="item">
      <a href=""><img src="https://via.placeholder.com/50"></a>
    </div>
  </div>
  <div class="next">S</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

Is there a way to create a timed fadeIn and fadeOut effect for a div using HTML and CSS?

I have a single div that initially displays text, and I want it to fade out after a specific time so that another div will then fade in. However, my attempt at coding this transition is not producing the desired result: $(function() { $(".preloa ...

How to use JQuery to parse an external JSON file with array elements in Javascript

My goal is to extract information from an external JSON file using JavaScript, specifically an array and other elements. The JSON file I am working with is called 'TotalUsers.json' {"@version":"1.0", "@generatedDate":"12/20/10 5:24 PM", "day":[{ ...

Unable to conceal a div element on mobile devices

Creating a unique bootstrap theme for Wordpress and encountering an issue with hiding the "sptxt" text on mobile screens. <div class="row"> <div class="col-lg-5 col-sm-12"><div id="gr"></div></div> <div class="col- ...

Unique styling implementation for element situated underneath Angular 6 router-outlet

I'm currently working on implementing router transitions in my Angular application, and I've encountered an unusual problem. The styling for the router-outlet element is being applied to the element that comes after it in the DOM hierarchy. Here ...

Enrich your HTML using AngularJS

CSS <div class="container"> <section> <p>{{content}}</p> </section> </div> script.js (function () { var script = function ($scope){ $scope.content = "example"; } }()); I am currently ...

What could be causing the issues I am encountering while using IE8?

My website looks great on all browsers except for Internet Explorer. I am currently using Internet Explorer 8 to test it. I've tried using a conditional stylesheet (ie.css) to fix some issues, but there are a few problems that have me stumped. I am op ...

What is the best way to resize an SVG to perfectly fit the parent div container?

I need to display multiple SVGs from various sources, each with different height, width, and viewbox. I want them all to render within a fixed height and width div, filling up the available space. How can I scale these SVGs to fit the container div? For i ...

Having difficulty styling scrollbars using CSS

There is currently a scrollbar displaying over part of my page when necessary. https://i.stack.imgur.com/48Rbx.png I want to change the styling of the scrollbar to make it less bright and have a transparent background. I attempted to apply some styles, bu ...

The functionality of ellipsis, which consists of three dots, allows the text to expand

I am trying to implement a feature where the extra text is represented by three dots (...) as an ellipsis, and upon clicking the dots, the text should expand and contract. However, the current code only contracts the text and does not expand it upon clicki ...

Updating the underline style of ant.d's menu item

Currently, I am working with ant.design to build my navbar. By default, the menu items in ant design have a blue-ish underline when selected or hovered over. However, I want to change this underline color to match the overall design of my project. I was su ...

Removing the gap between the clicked point and the draw point in Html5 canvas

To better understand my issue, please refer to the image linked below: In the image, you can see that when I scroll down and click on the canvas to point a position, it creates space between the clicked point and where the line is drawn. Below is the cod ...

Using ngForm to implement multiselect options in HTML

Attempting to implement a multiselect dropdown that is tied to a dynamic property receiving data from a JSON script via service. Successfully displayed the data in the dropdown, but encountering abnormalities when adding the multiple attribute within the s ...

Retrieve all div elements by their data attribute until reaching a certain condition

I am working on an innovative jquery accordion menu using divs instead of the typical li tags. Each div contains a unique data attribute (data-level) with values ranging from 1 to 4, and so on... To achieve the desired functionality, my "toggle" function ...

What is the method for adding color to the select and option fields?

On my website, I have created a contact form and I am trying to customize the select field by adding colors like other fields. However, when I choose an option from the select field, it is not showing up. Can you please help me identify what mistake I migh ...

Identify the moment when the SPAN element reappears in sight

I have a question that may have been asked before, but I haven't found a satisfactory answer yet. Within my HTML code, I have a SPAN element with an onclick event, like so: <span onclick='loadDiv()'>Text</span> When a user cli ...

Adding -moz & -o prefixes to code that only has -webkit tags can be done by manually duplicating each line of

Imagine having a webpage located at this link: After saving the page and running the HTML file on my localhost, everything seems to work smoothly in Chrome due to the presence of -webkit prefixes in the CSS. Now the question arises - how can I ensure that ...

Tips on maintaining and hiding the vertical scrollbar when a popup is open, alongside the navigation bar positioned at the top of the page

After reviewing this pen, my goal is to create a popup that maintains access to the navigation bar (hence avoiding Bootstrap's Modal). However, I am facing the challenge of keeping the scrollbar visible while preventing scrolling in the background whe ...

Can you explain the significance of polyfills in HTML5?

What exactly are polyfills in the context of HTML5? I've come across this term on multiple websites discussing HTML5, such as HTML5-Cross-Browser-Polyfills. Essentially, polyfills refer to tools like shims and fallbacks that help add HTML5 features ...

The information from the textarea and select option is not getting through to the email

Despite following suggestions, I am still unable to figure out why my form is not functioning properly. The form I have collects various information such as name, email, phone number, a select option, and a message in a textarea input. I dynamically change ...

How can you animate a MUI v4 Grid element using CSS transitions?

I was exploring the potential of using breakpoints in the MUI v4 component to control the visibility of items in my Grid System. How can I create a smooth CSS transition for b, transitioning from 0px to a defined breakpoint size of 3 for xl? Using % works ...