The alignment issue arises when using Grid-column-end with items of a set width

I am facing an issue with aligning an item in a specific column while maintaining a fixed width. When I attempt to right-align the item, it overflows the designated space. Removing the width attribute resolves the problem, but that is not a viable solution for me.

Although using grid-column helps to set the width, I prefer to have more precise control over the size of the item if possible.

Another approach I tried was setting the container to span grids 1/4 and aligning content inside it, but it seems I made a mistake as it did not work as intended.

* {
  margin: 0;
  box-sizing: border-box;
}

.container {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  grid-gap: 1rem;
  align-content: start;
  height: 100vh;
  width: 100%;
  padding: 1rem;
  background-color: firebrick;
}
.section {
  display: flex;
  justify-content: center;
  align-items: center;
 
  height: 8rem;

  background-color: white;
}

.section-1 {
    grid-column: 1/4;
}
.section-2 {
  grid-column: 1/4;
}
.section-3 {
  grid-column: 4/6;
  grid-row-start: 1;
}

.controls {
  width: 9rem;
  height: 3rem;
  grid-column-end: 4;
  background-color: white;
}
<div class="container">
  <div class="section section-1">Section 1</div>
  <div class="controls">
    <div class="control-btn"></div>
    <div class="control-btn"></div>
    <div class="control-btn"></div>
  </div>
  <div class="section section-2">Section 2</div>
  <div class="section section-3">Section 3</div>
</div>

https://i.sstatic.net/49RtS.png

Explore CodePen demo

Answer №1

make sure to include justify-self: end; in that element, although be cautious of potential overflow on the left side

* {
  margin: 0;
  box-sizing: border-box;
}

.container {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  grid-gap: 1rem;
  align-content: start;
  height: 100vh;
  width: 100%;
  padding: 1rem;
  background-color: firebrick;
}
.section {
  display: flex;
  justify-content: center;
  align-items: center;
 
  height: 8rem;

  background-color: white;
}

.section-1 {
    grid-column: 1/4;
}
.section-2 {
  grid-column: 1/4;
}
.section-3 {
  grid-column: 4/6;
  grid-row-start: 1;
}

.controls {
  width: 9rem;
  height: 3rem;
  grid-column-end: 4;
  background-color: white;
  justify-self:end;
}
<div class="container">
  <div class="section section-1">Section 1</div>
  <div class="controls">
    <div class="control-btn"></div>
    <div class="control-btn"></div>
    <div class="control-btn"></div>
  </div>
  <div class="section section-2">Section 2</div>
  <div class="section section-3">Section 3</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

excess padding in the Twitter Bootstrap

While working with Twitter Bootstrap, I stumbled upon an unusual issue where everything looked fine on desktop screens but appeared differently on Samsung Galaxy S5 or displays of similar sizes (360 x 640 or 640 x 360 in this case). There was a strange rig ...

Datepicker from Bootstrap is not visible even after implementation of a function

My code is available on js fiddle https://jsfiddle.net/9n3c8726/. I am trying to get the datepicker to appear as soon as I click on the field. I have already enclosed it in a function, but it doesn't seem to be working. Any assistance would be greatly ...

Issues with displaying Angular 6 NGX chips correctly

Currently, I am utilizing `ngx-chips` in my projects and storing my objects in an array. This allows me to use the following example: <div> <h3>Tags within an autocomplete component (clear on blur events)</h3> <tag-inp ...

Refresh WebPage automatically after a Servlet successfully uploads and processes an image

I have a webpage that includes an image and a button. When the button is clicked, it uploads the image by submitting a form to a file upload servlet. However, after successfully uploading the image, the servlet does not display it in the img tag. Here is ...

Selenium or Splinter: Is it possible to retrieve the current HTML page after clicking a button?

My attempt to scrape the website "" proved challenging as I discovered that the page dynamically updates. Clicking the "More" button reveals new content, but using splinter didn't automatically update the browser.html with the latest data. Is there a ...

Creating efficient browser caching for static elements like CSS, JavaScript, and images

Just to clarify, I am utilizing Django with an Apache server. During testing of a website on Pingdom Tools, I encountered the following error messages: The cacheable resources mentioned below have a short freshness lifetime. It is recommended to specify ...

Input field unexpectedly finds its way into a div surrounded by labels in Internet Explorer 11

CSS Code: .wrapper { margin-right: 75px; float: left; position: relative; } .input-large { width: 210px; } .label-a { float: left; } .label-b { float: right; } HTML Code: <div class="wrapper"> <div> <la ...

Tips for aligning placeholder and text at the center in a React Material UI TextField

Existing Layout: https://i.stack.imgur.com/Zv4Tg.png Desired Layout: https://i.stack.imgur.com/Xuj6O.png The TextField element is displayed as follows: <TextField multiline={false} autoFocus placeholder={props.defaultAmt} ...

What could be causing my HTML website to load slowly and freeze when I switch to another program?

I am in the process of creating three websites. Two of them are functioning perfectly fine, but I am encountering a speed issue with the third one. Sometimes it loads slowly initially, but if I wait a bit longer, it eventually loads and works well. However ...

What is the process for including CSS in the .ashx.cs code-behind file in ASP.NET?

How can I insert a css class in the .ashx file while the .aspx UI page displays it as a string? What is the method to include css in the code behind of the .ashx page? I would like the text "Cook" to be displayed in red. Problem: https://i.sstatic.net ...

Continuously animate a series of CSS properties

Here's the code snippet I'm working with: @keyframes ball1 { 0% { transform: translateX(0px); opacity: 0%; } 50% { opacity: 100%; } 100% { transform: translateX(120px); opacity: 0%; } } @keyframes ball2 { 0 ...

Scrolling of div restricted to only horizontal direction

I'm attempting to create a div that contains a paragraph within it. My goal is to have the ability to scroll down when there is overflow due to the content of the paragraph, thus preventing it from extending beyond the boundaries of the DIV. However, ...

Tips for adding event listeners to dynamically-loaded content using AJAX

I need help with the following code snippet: $("#contantainer").load("some_page.txt"); Inside some_page.txt, I have the following content: <div class="nav"> <ul id="nav_ul"> <li><a class="nav_a" href="#home" id="home"> ...

Modifying CSS property values by handling a returned validation error

Allow me to describe a scenario I've created. Please excuse any language errors in my explanation. I have designed a form for users to submit values. Within this form, users can choose an option - one of which is "Others specify...". When this option ...

Align Bootstrap 4 dropdowns with their parent element

Is there a way to match the width of a bootstrap dropdown menu with its parent input group? <div id="ddl_1" class="input-group"> <input type="text" class="form-control "> <div class="input ...

Change the order of columns using CSS in a mobile-first approach

Is there a way to achieve the layout shown in the image using only HTML and CSS? I attempted rearranging the stacked elements for larger screens by: #2: float: left #1: display: inline-block #3: float: right However, this approach did not yield the desi ...

Switch up the animation direction after the vimeo video finishes playing

My video module has a splash screen that reveals a full-screen video when clicked for screen sizes 667+. I want to reverse the animation after the video ends and return to the splash screen. I'm unsure of how to approach this or if it's even poss ...

Utilize JQuery to transfer a cell that currently resides in one row to a new row

I need to relocate a cell within a table from one row to another. The table currently has only one row with four cells, and I specifically want to move the third cell to a new row. Here is the existing markup: <table class="sbtable"> <tbody> ...

What could be causing scrollTo to function in my ClickListener but not in AfterViewInit?

I was pondering about why the code snippet below is functioning properly: scroll(){ window.scrollTo(0, this.ypos); // executes without any issues } And in my html.component: <button (click)="scroll()">Scroll</button> but the cod ...

In Mobile View, I want to swap out my current image for text to keep it hidden

I am attempting to include text that is only visible in Mobile View as a replacement for my logo. Below is the code I am using: CSS: @media only screen and (max-width:1024px) { header .logo { display: none; } header .logo a { display: non ...