Aligning with the parent element and adjusting slightly towards the left side

.parent-div {
  box-sizing: border-box;
  min-width: 0px;
  padding: 1rem;
  min-height: 1px;
  margin: 0;
  border: solid 1px;
}

.child-div-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  min-height: 400px;
  display: flex;
  border: solid 1px;
}

.child-div-one-of-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  flex: 1 0 calc(18% - 60px);
  margin-right: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.child-div-one-of-one-of-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  -ms-flex-direction: column;
  flex-direction: column;
  height: 395px; // this is dynamically calculated it can become any value bw 380 and 400px
  position: relative;
  display: -ms-flexbox;
  display: flex;
}

.button-new-one {
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  min-width: 120px;
  border-radius: 2px;
  cursor: pointer;
  padding: 6px 16px;
  position: absolute;
  bottom: 0;
}

.child-div-one-of-two {
  box-sizing: border-box;
  margin: 0 auto;
  min-width: 0px;
  -ms-flex: 1 0 82%;
  flex: 1 0 82%;
  display: -ms-flexbox;
  display: flex;
  border: solid 1px;
}

.child-div-two {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  display: -ms-flexbox;
  display: flex;
}
  
.child-div-two-of-one {
  box-sizing: border-box;
  min-width: 0px;
  margin: 0 auto;
}
<div class='parent-div'>
  <div class='child-div-one'>
    <div class='child-div-one-of-one'>
      <div class='child-div-one-of-one-of-one'>
        <button class='button-new-one'>New One</button>
      </div>
    </div>
    <div class='child-div-one-of-two'></div>
  </div>
  <div class='child-div-two'>
    <div class='child-div-two-of-one'>
      <button class='button-less'>Less</button>
      <button class='button-more'>More</button>
    </div>
  </div>
</div>

In the provided code, although there is a margin: 0 auto, the button is not centered within the child-div-one-of-two. I am looking to adjust its positioning so that it sits perfectly in the middle of the div. Would adding a margin-left help achieve this, or should the button be centered at 82% instead of 100%?

To clarify, both the "Less" and "More" buttons need to be precisely centered within the above div. Additionally, if the content within the above div increases, the buttons should move down accordingly. How can I accomplish these tasks effectively? Any guidance would be highly appreciated.

Answer №1

If you have a known value of 82%, simply include padding-left: 9% to the .child-div-two-of-one class.

.parent-div {
  box-sizing: border-box;
  min-width: 0px;
  padding: 1rem;
  min-height: 1px;
  margin: 0;
  border: solid 1px;
}

.child-div-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  min-height: 400px;
  display: flex;
  border: solid 1px;
}

.child-div-one-of-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  flex: 1 0 calc(18% - 60px);
  margin-right: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.child-div-one-of-one-of-one {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  -ms-flex-direction: column;
  flex-direction: column;
  height: 395px; // this is dynamically calculated it can become any value bw 380 and 400px
  position: relative;
  display: -ms-flexbox;
  display: flex;
}

.button-new-one {
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  min-width: 120px;
  border-radius: 2px;
  cursor: pointer;
  padding: 6px 16px;
  position: absolute;
  bottom: 0;
}

.child-div-one-of-two {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  -ms-flex: 1 0 82%;
  flex: 1 0 82%;
  display: -ms-flexbox;
  display: flex;
  border: solid 1px;
}

.child-div-two {
  box-sizing: border-box;
  margin: 0;
  min-width: 0px;
  display: -ms-flexbox;
  display: flex;
}

.child-div-two-of-one {
  box-sizing: border-box;
  min-width: 0px;
  margin: 0 auto;
  padding-left: 9%;
}
<div class='parent-div'>
  <div class='child-div-one'>
    <div class='child-div-one-of-one'>
      <div class='child-div-one-of-one-of-one'>
        <button class='button-new-one'>New One</button>
      </div>
    </div>
    <div class='child-div-one-of-two'></div>
  </div>
  <div class='child-div-two'>
    <div class='child-div-two-of-one'>
      <button class='button-less'>Less</button>
      <button class='button-more'>More</button>
    </div>
  </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

The dilemma of selecting objects in Three.js

Currently, I am developing a small web application that utilizes three.js. However, I have encountered an issue: I created a prototype with my three.js content and everything functions correctly (the canvas size in the prototype matches the browser window ...

The Chart.js graph fails to appear when placed within an ngIf directive

I have encountered an issue with my simple scatter line chart created using Chart.js within a bootstrap panel. It works perfectly fine until I place it inside an ngIf div. Has anyone faced this problem before? Is there a solution to make the chart display ...

Display the value of a shortened string

My Goal I aim to develop a method for determining the amount of a string visible before it gets cut off. Motivation In my project, there is a collection of items that can be chosen. A panel presents a concatenated string of the selected item names separa ...

What could be the reason for Internet Explorer pulling styles from the media=print CSS?

The HTML below incorporates a DHTML behavior into a CSS class. Unfortunately, Internet Explorer (specifically version 8 in compatibility mode) does not read the top style exclusively; instead, it also recognizes the @media print. <!--[if IE]> < ...

Swap out the image for a div element if the image is not found

Is there a way to accurately display an image if it's available, and use a div as a replacement if the image is not present? // How can I determine `imageExists` without encountering cross-origin issues? (imageExists) ? (<img class="avatar-img" sr ...

Looping Issue in WordPress

Here is the code snippet I am currently working with: <?php query_posts("order=ASC&cat=4"); ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <?php if(get_post_custom_values("show") != NULL): ?> ...

Styling jQuery Draggable and Droppable <li> elements

I am facing a challenge with my drag and drop functionality using jQuery. While the drag drop feature works perfectly, I need to display two separate pieces of information from a database on each "li" item in different styles. My goal is to include a "tra ...

Adjust color scheme of drop-down menu

Having trouble changing the background color for my drop down menu. I tried to change the color for the sub div but it's not working. Can anyone help me fix this issue? Here is the code snippet: http://jsfiddle.net/3VBQ6/4/ #nav li:hover ul.sub li { ...

Having issues with my JavaScript timer - seeking assistance in troubleshooting the problem

Trying to set a timer for my little game, but facing some difficulties. The timer causes the balance to randomly increase from 0 to 13000 + some extra amount. <script> var coins = 0; var speed = 1; </script> <center> <h4> ...

Cross-Platform: Varied functionalities in disabled input fields (avoiding any direct replication)

My input HTML field is disabled, but I've noticed that in some browsers (such as Chrome, Edge, Internet Explorer, and Opera), it's still possible to select and copy the text. However, in Firefox, this functionality does not work. To test this yo ...

AngularJs - Show the response only upon verifying the correct answer

Let me provide an overview of what has been implemented so far: When a user selects an answer in radio buttons and clicks on "Check Answer", the system displays either "Correct" (in green) or "Incorrect" (in red) in the first answer field. Additionally, th ...

Creating a dynamic visual experience with Angular 2: How to implement multiple font colors

I have a text area which is connected to one string, with the default text color set to white. <textarea style="background-color: black;color:#fff;" [(ngModel)]="outputText"></textarea> The connected string contains multiple variables. retur ...

Expand a div without causing any displacement to surrounding elements

If you have 4 colored divs (red, yellow, green, blue), with 2 per row, and need to expand the second (yellow) without creating a gap under the red, check out this solution. The blue will be positioned underneath the expanded yellow. For a live example, vi ...

What causes Safari to display a black border around resized videos?

I've come across a strange issue while using Safari. Whenever I try to play an MP4 video with dimensions of 1920 * 1080, and resize the Safari window to a width of 937px, something strange happens: https://i.stack.imgur.com/oI50i.png A black border ...

Leveraging an external Typescript function within Angular's HTML markup

I have a TypeScript utility class called myUtils.ts in the following format: export class MyUtils { static doSomething(input: string) { // perform some action } } To utilize this method in my component's HTML, I have imported the class into m ...

Bring in a video file in order to watch it on your web page (HTML)

Is there a way to upload and play a video file using the video element? I am looking to add a video file to my webpage that can be played using a video element. <input type="file"> <h3>Video to be imported:</h3> <video width="320" ...

A sleek and streamlined scrollspy that dynamically updates the active class exclusively for anchor tags

Can anyone help me with this coding problem? I'm currently working on a minimalistic scrollspy code that adds an active class when the content is offset.top. The code works fine, but I want to change the active class to apply to the "a" tag instead of ...

What improvements does IE7 offer compared to IE6?

Many developers in the web development industry often express frustration when it comes to developing for IE6. But when working with a powerful JavaScript framework such as jQuery, does the process of developing for IE6 differ significantly from that of ...

What is the best way to utilize Django forms with a <select> value that is frequently used?

I am currently developing an application that enables users to interact with a database of information, including searching and saving entries. Within the search feature of the application, there are multiple fields where users should specify comparison o ...

Guide to parsing the HTML structure of a webpage from a different domain

Struggling with parsing the DOM of a remote webpage using AJAX. Can't find any examples or tutorials on this process. My goal is to navigate through the DOM of a remote page, locate a tag with a specific id/class, extract the content within that tag, ...