Increasing the Gap Between Two Inline-Block Elements

I am facing an issue with my modal button and header alignment. The button, which has inline-block display, needs to be positioned further to the right while keeping the header element centered.

Adjusting the padding of the item container did not yield the desired result. What other solutions can I try?

.btn.btn-info.btn-md {
    background: #104723;
    border-color: #104723;
    border-radius: 3px;
    float: right;
    display: inline-block;
    position: absolute;
    
}
.btn.btn-info.btn-md:active {
    background: #104723;
    border-color: #104723;
    border-radius: 3px;
    float: right;
    display: inline-block;
    position: absolute;
    margin-right: -40px;
}

  .pageheadh {
      font-size: 30px;
      font-weight: bolder;
      color: black;
      text-align: center;
      display: inline-block;
  }
  .pageheadp {
      text-align: center;
      color: black;
      font-weight: bold;
  }
  .center {
    align-items: baseline;
    justify-content: center;
    text-align: center;
    padding-right: 10px;
  }
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
    <!-- Datatables -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <script src="https://nightly.datatables.net/js/dataTables.bootstrap.js"></script>
<!-- Trigger the modal with a button -->
<div class="center">
<h3 class="pageheadh">Fitness Tracker</h3>
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>
</div>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog modal-lg">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">
        <embed src="https://ak.picdn.net/shutterstock/videos/3998236/thumb/3.jpg" frameborder="0" width="100%" height="100%">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

            <p class= "pageheadp">Click on any of the tabs to track your progress in that category. </p>
        <!--<input type="text" class="global_filter" id="global_filter">-->
        <div class="clearfix"></div>
        ...

Answer №1

To ensure the button is properly positioned with absolute positioning, start by adding position: relative to the .center class.

Next, include the following ruleset for the .btn.btn-info.btn-md selector:

top: 0;
bottom: 0;
height: 40px;
margin: auto auto auto 50px;
.btn.btn-info.btn-md {
    background: #104723;
    border-color: #104723;
    border-radius: 3px;
    float: right;
    display: inline-block;
    position: absolute;
    top: 0;
    bottom: 0;
    height: 40px;
    margin: auto auto auto 50px;
}

.btn.btn-info.btn-md:active {
    background: #104723;
    border-color: #104723;
    border-radius: 3px;
    float: right;
    display: inline-block;
    position: absolute;
    margin-right: -40px;
}

.pageheadh {
    font-size: 30px;
    font-weight: bolder;
    color: black;
    text-align: center;
    display: inline-block;
}

.pageheadp {
    text-align: center;
    color: black;
    font-weight: bold;
}

.center {
    align-items: baseline;
    justify-content: center;
    text-align: center;
    padding-right: 10px;
    position: relative;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" />
<!-- Datatables -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://nightly.datatables.net/js/dataTables.bootstrap.js"></script>
<div class="center">
    <h3 class="pageheadh">Fitness Tracker</h3>
    <button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#myModal">Prize Plaza</button>
</div>

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title"></h4>
            </div>
            <div class="modal-body">
                <embed src="https://ak.picdn.net/shutterstock/videos/3998236/thumb/3.jpg" frameborder="0" width="100%" height="100%" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<p class="pageheadp">Click on any of the tabs to track your progress in that category.</p>
<div class="clearfix"></div>
<ul class="nav nav-tabs">
    <li class="active"><a href="#1" data-toggle="tab">Weekly Weight &Delta;</a></li>
    <li><a href="#2" data-toggle="tab">Total Weight &Delta;</a></li>
    <li><a href="#3" data-toggle="tab">Weekly Steps</a></li>
    <li><a href="#4" data-toggle="tab">Total Steps</a></li>
    <li><a href="#5" data-toggle="tab">Weekly Minutes</a></li>
    <li><a href="#6" data-toggle="tab">Total Minutes</a></li>
    <li><a href="#7" data-toggle="tab">Step Points</a></li>
    <li><a href="#8" data-toggle="tab">Exercise Points</a></li>
    <li><a href="#9" data-toggle="tab">Weekly Winners</a></li>
</ul>

Answer №2

To enhance your button, consider incorporating absolute positioning:

.btn.btn-info.btn-lg {
     background: #104723;
     border-color: #104723;
     border-radius: 3px;
     float: right;
     display: inline-block;
     position: absolute;
     right:15px;
     top: 10px;
}

Answer №3

Maybe consider inserting a

<br>

between the two divs. If not, you could try making this adjustment.

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>

change to

<button type="button" class="btn btn-info btn-lg ml-5" data-toggle="modal" data-target="#myModal" >Prize Plaza</button>

If that doesn't work, adjust your CSS to

.btn.btn-info.btn-lg {
            background: #104723;
            border-color: #104723;
            border-radius: 3px;
            float: right;
            display: inline-block;
            position: absolute;
            right:15px;
            top: 10px;
            margin-right: 50px;
        }

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

HTML - Unable to Load Image/ Image Not Displayed After Refreshing Page

After successfully creating a background slider that worked perfectly when viewed as a local file, I decided to test it on localhost using XAMPP. Initially, everything seemed fine upon the first load, but when I tried to refresh the page, the images in the ...

A total of 12 columns within the Foundation grid layout, with ample space for customization

My layout structure is as follows: <div class="row"> <div class="columns small-12 large-6 medium-12 panel-wrapper"> Box no 1 </div> <div class="columns small-12 large-6 medium-12 panel-wrapper"> Box n ...

What is the best way to create some distance between a div element and the bottom of the body?

Hello, I am attempting to center a div within my body. The div has a minimum height of 400px, but its size can expand based on the content it holds. When I add more content to the div, it grows accordingly, but it ends up touching the bottom of the div. I ...

What is the best way to combine table cells in HTML to create a "T" shape?

Is there a way to merge the two blank cells (one above 'Be' and one above 'B') with a large blank space in the middle? I attempted using colspan and rowspan in various ways without success. https://i.stack.imgur.com/tw5SE.png This is m ...

Assigning a height of 100% to a div element results in the appearance of

In a div within the body, there are only 3 lines of text. The background color was only filling up to those 3 lines of text. To make the color fill up the entire vertical space of the browser, I adjusted the CSS height properties of html & body to be ...

Potential Bug Detected in Internet Explorer on Mouseenter Event

I'm facing a challenge with my HTML/CSS code. I have a carousel that includes two li elements positioned absolutely on each side for navigation but they are not displaying correctly in IE versions 7-9 - they appear behind the main element regardless o ...

Accordion Caption Image Gallery powered by Jquery

I have been searching for a jQuery image gallery plugin with an accordion caption on the right side, similar to this (please check it out). Despite my efforts, I haven't been able to find one that meets my needs. I came across some relevant plugins li ...

Custom background images override title slide text formatting settings

I have made some changes to the CSS in order to customize the title slide. My goal is to incorporate a background image, adjust the positioning of the title, and modify the font colors for both the title and author/date text. --- title: "Mechanical Re ...

Tips for creating sections of an image that appear to glow when hovered over

I have a client who is affiliated with a local legion and specializes in restoring military regiment photos. He wants me to create a website where users can hover over each person in the photo, causing their outline to glow while displaying a tool tip with ...

Utilizing CSS to Display a Variety of Colors within a Text String

Is it possible to style different words in a sentence with various colors using only CSS, without using the span element? For instance, how can I make the word "Red" appear in red, "Blue" in blue, and "Green" in green within an h1 tag? ...

Deactivate the second subradio button when the first option is selected and vice versa

Need some assistance, hoping for your help. I have 2 choices with subcategories. 1 - Option A ---- variant 1 ---- variant 2 ---- variant 3 2 - Option B ---- variant 4 ---- variant 5 ---- variant 6 Check out my code here Users must choose betwe ...

What is causing the content on my webpage to not fill the entire width of the page?

I've encountered an issue with the content on one of my pages not expanding to the full width of the page. Despite placing everything inside a container and setting the max-width of the container to 1500px, the content still doesn't extend all th ...

Guide on replacing a link tag with another using CSS

On one of my website pages, I am utilizing two different CSS stylesheets: <link type="text/css" href="base_form.css" rel="stylesheet" /> <link type="text/css" href="extended_form.css" rel="stylesheet" /> The extended_form.css stylesheet needs ...

How come the div element is not rendering the CSS styles?

What could be the reason for .header not displaying the background color and height settings? https://jsfiddle.net/f3puaeq6/1/ .header{ background-color: black; height: 300px; } ...

Switching on Closed Captions for HTML5 video while deactivating the standard video controls

I am facing two issues. Whenever I include the track tag in my video element, the default controller of the video pops up, which is causing conflicts with my custom controls. Secondly, I am unable to figure out how to turn closed captions on and off. Thi ...

In what way can I obtain CSS comments utilizing jQuery?

I am trying to figure out how I can access CSS comments that are included in an external stylesheet. In order to demonstrate, I have loaded a sample CSS using the following code: <link rel="stylesheet" type="text/css" media="all" href="test.css" /> ...

What is the process for adding a naked domain (without www) on GoDaddy that is deployed through Heroku?

I have successfully deployed a domain through Heroku, and it is functioning properly with the www prefix. However, when attempting to access the domain without the www, it fails to render correctly. I have tried adding both versions of the domain (with www ...

Issues with Adaptive Headers

* { box-sizing: border-box; font-family: sans-serif; margin: 0; padding: 0; } html, body { font-size: 14px; } header { width: 100vw; height: 50px; background-color: #222; margin: 0 auto; padding: 0; display: flex; justify-content: ...

Tips for adding a text input field within a dropdown menu

Could someone provide guidance on how to place an input text box within a dropdown without using bootstrap? I came across this image showing what I am looking for: https://i.stack.imgur.com/f7Vl9.png I prefer to achieve this using only HTML, CSS, and Jav ...

CSS hover effect causes text to unexpectedly slide out before it is meant to

I've set up a collection of glyphicons that reveal expanding text when hovered over. The problem I'm encountering is that if the text happens to be lengthy, it flashes over the container of the glyphicon before the CSS transition finishes. You ...