Tips for aligning elements in a row with various positioning

I am facing a challenge with my container where the child elements have col-md-2 and col-lg-3 classes applied dynamically. On larger screens with 3 columns, I want the middle one to be centered and the last one on that row aligned to the end. When there are only 2 columns on a medium screen, the second element of each row should remain aligned to the center. On small screens, all elements should be aligned to the center.

Check out what I have tried so far here

.list-container {
  min-height: 100px;
}

.el-row-container {
  width: 95%;
}
.el-row-container .el-container {
  width: 410px;
  margin-bottom: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
}
.data {
  position: relative;
  min-width: 291px;
  height: 36px;
  display: inline-block;
  padding: 10px 11px;
  border-radius: 4px;
  font-weight: 400;
  letter-spacing: 0.15px;
  font-size: 14px;
  line-height: 16px;
  background: rgba(0, 0, 0, 0.6);
  }
   @media (min-width: $breakpoint-lg) {
  .align-middle {
    justify-content: center;
  }
  .align-end {
    justify-content: flex-end;
  }
}
<div class="container">
  <div class="col-xs-12 list-container">
    <div class="row el-row-container">
      <div class="el-container  col-md-2 col-lg-3"  ng-repeat="data in els"  ng-class="{'align-middle': $index%3 ===1, 'align-end': $index%3 === 2}">
        <div class="data">1</div>
      </div>
    </div>
  </div>
</div>

I am currently assigning the align-middle and align-end classes based on index values, but I am wondering if there is an easier way to achieve this alignment?

Answer №1

It appears that utilizing the align-self css property would be more suitable for your situation rather than using justify-content

For reference, you can check out this example: https://jsfiddle.net/bmu0rdoc/3/

However, it seems like your implementation of bootstrap is a bit unconventional. Adding a .col-{breakpoint}-{size} class typically results in Bootstrap trying to fill the parent with {size} rows. By introducing a fixed width, you may disrupt the column system. More information can be found here: https://getbootstrap.com/docs/3.4/css/#grid

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

transfer data from one HTML page to another through the database

I have an HTML page in Flask that pulls applicant information from a SQLAlchemy database. I would like to be able to click on an applicant's name on the first page and have another page open with specific details for that applicant. While I was succe ...

When using Flexbox with a column wrap and setting the height to min-content, the wrapping behavior may not

I'm facing a CSS challenge. I have divs of varying heights and I want the parent element to adjust its height based on the tallest child element, while keeping the rest of the elements aligned properly. The code provided below achieves this for rows b ...

How to make QWebView background translucent

My goal is to make the background of a QWebView element transparent. +---------------------------+ | x | Window title | <<< Hidden borders and title bar +---------------------------+ view->setWindowFlags(Qt::FramelessWindowHint); | ...

What are the best methods for structuring my inaugural AngularJS project?

My objective is to develop a single page application utilizing AngularJS. While I understand the concepts of AngularJS, I am in need of practical experience when it comes to planning and executing a full project using this framework. The layout is relativ ...

Controlling multiple bx-sliders with a single pager using only JavaScript

Is there a way to control 3 sliders using the same pager? I attempted to use the following code but it did not work: <script language="javascript"> $('.mobile_left_mble,.mobile_right_mble,.text_btn').bxSlider({ //pagerCustom: '#bx- ...

Is there a way to modify the color of a specific section of a font icon?

Currently, I am in the process of implementing an upvote button using fa fa signs. However, I have encountered an issue where the background color of the up vote button is bleeding outside of the sign (possibly due to padding on the icon), and I am strivin ...

Manipulating an HTML <div> element to display its value as a suffix in another <div> within the HTML code

I'm attempting to combine and show text along with content from another <div> as the modal-header, but it's not displaying correctly. When I give an ID to the modal-header, the *&times;* symbol disappears. This is how my modal-header l ...

Is there a way to determine if a variable includes Chinese or Japanese characters?

Is there a way to determine if a variable includes Chinese or Japanese characters? I have found this line effective: if (myVariable.match(/[\u3400-\u9FBF]/)) My goal is to apply the same concept to a specific variable, rather than the entire do ...

Using the MVC framework, create a hyperlink with custom CSS styling by

Having trouble getting a specific class to override the default styles for a:link @Html.ActionLink("Back to List", "Index", null, new { @class = "htmlactionlink" }) CSS a:link, a:visited, a:active, a:hover { color: #333; } .htmlactionlink { co ...

Instructions for inserting text into a donut chart created with Google, utilizing basic HTML, JavaScript, or jQuery syntax

Are there any attributes in Google Chart that I should know about? I am just starting to use Google Charts and would appreciate some guidance. Here is the code snippet I am working with: function drawChart() { var data = google.visualization.arrayTo ...

Commence {{@index}} at 1 instead of 0 in Handlebars, without any template specified

Currently, I am utilizing the @each loop to go through items but would like to start with an index of 1 instead of 0. I attempted to resolve this by including the following code snippet: var Handlebars = require('handlebars'); Handlebars.regist ...

Executing a protractor test on Safari results in the message "Angular was not located on the webpage https://angularjs.org/"

Recently, I encountered an issue while trying to run a Protractor test on Safari, even when following the official example provided at http://www.protractortest.org/. Below are my conf.js and todo-spec.js files. The problem arises when I set browser.ignor ...

Having trouble with md-autocomplete not functioning properly

Whenever a user enters a movie name in the autocomplete box, this code is used to search for movies. The search results are displayed on the console, but the item text is not showing up in the HTML. <md-autocomplete md-selected-item="selectedMovie" ...

transferring information back and forth between a javascript array and php

Currently, I am developing a design website that allows users to create designs on an HTML5 canvas and save them on the server. All user information is stored in a MySQL database, while the designs are saved in a JavaScript array. My goal is to seamlessly ...

Visibility of image changes after selecting from dropdown menu

Whenever I choose a language from the dropdown menu, the corresponding language image should display in a div next to it, while hiding the irrelevant images. I've been experimenting with CSS properties like display: none; and block;, as well as jQuery ...

Populate Vue components in auto-generated HTML code

Utilizing a WYSIWYG article editor, I generate HTML content for articles that is saved in the database and displayed to users at a later time. However, I am facing an issue where I need to embed Vue components within this generated HTML in order to showca ...

Transmit information between controllers during pageload in AngularJS without utilizing $rootscope

I currently have 2 controllers set up as follows: app.controller('ParentMenuController', function ($scope,MenuService) { $scope.contentLoaded = false; $scope.showButton = false; $scope.showButton = MenuService ...

Create identical buttons using Bootstrap 4

I am trying to create uniform left and right buttons, but I am facing issues with making them look the same on both PC and mobile devices. Here is the current appearance: View the current button design <h3> <a href="" ...

Websocket issues with onopen function not consistently triggering in AngularJS application

I am currently working on an application that is reading data from an external device. My chosen JavaScript framework is AngularJS and I am using angular-ui for routing purposes. To ensure that the web socket can be accessed across multiple screens, I am ...

Inquiries about ngshow and the scope concept

I have a question about using AngularJS. I have multiple sections and only want to display one at a time using <section ng-show="section6_us"> </section> and <section ng-show="section7_us"> </section>. My scope has many variables. ...