Is there a way to position two buttons in the same inline, one shifted to the left and the other to the right?

I can't seem to figure out how to position two buttons within this div. My goal is to have the tweet button on the left and the "Next Quote" button on the right. I've attempted to use position absolute to move the Next-Quote button to the right, but it only moves halfway. I've also tried float right and pull-right without success. I'm stuck and could really use some guidance...

<div className="container col-md-6 col-sm-offset-3">
  <div id="quote-box">
    <h4 id="text" className="text-md-center"> {this.props.quote.quote}</h4>
    <p id="author" className="text-md-right">- {this.props.quote.author}</p>
  <div className="buttons btn-toolbar">
    <a 
      href="https://twitter.com/share?ref_src=twsrc%5Etfw" 
      className="twitter-btn twitter-share-button"
      data-size="large"
      data-show-count="false"
     >Tweet
     </a>
     <button
       id="new-quote"
       className="btn btn-primary btn-xs pull-right"
       onClick={this.onClick.bind(this)}
     >Next Quote
     </button>
  </div>
 </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
#quote-box {
  padding: 20px;
  border-radius: 10px;
  background-color: red;
}

.btn-toolbar {
  display: flex;
  justify-content: space-between;
}

#new-quote {
  font-size: 13.5px;
  padding: 3px;
}

Answer №1

Here’s the solution that worked for me:

Here is the HTML code snippet:

<div class="left-btn">
    <button class="btn"></button>
</div>
<div class="right-btn">
    <button class="btn"></button>
</div>

This is the corresponding CSS code:

.left-btn { float: left; }
.right-btn { float: right; }

Answer №2

Give this method a try. It may seem uncomplicated, but it definitely gets the job done

<ul class="main-navigation">
    <li class=""><a href="home.html" class="company-logo"><img src="assets/logo.svg" alt="Company Logo"></a></li>

    <div class="menu-items">
        <li><a href="index.php" class="nav-link" data-wow-duration="1s" data-wow-delay="0.2s">Homepage</a></li>
    </div>
</ul>

.main-navigation {
    display: flex;
}

.main-navigation li:first-child {
    margin-right: auto;
    z-index: 3;

}

Answer №3

To begin, encase each button within its own div:

<div className="buttons-container">
    <div className="left-group">
        <button className="twitter-button">Tweet</button>
    </div>
    <div className="right-group">
        <button className="primary-button">Next Quote</button>
    </div>
</div>

Next, apply some CSS rules to manage the elements inside those divs:

.buttons-container {
    display: flex;
    justify-content: space-between;
}

.left-group {
    display: flex;
    flex: 1;
    justify-content: flex-start;
}

.right-group {
    display: flex;
    flex: 1;
    justify-content: flex-end;
}

Answer №4

Here's an alternative approach you can experiment with:

<div class="actions">
      <button className="facebook-btn">Share</button>

      <button className="btn-secondary">Next Post</button>
</div>

To customize the layout, simply use the marginLeft property on the desired button element:

.actions {
        display: flex;
}

.btn-secondary {
        marginLeft: auto;
        backgroundColor: blue;
}

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 the text alignment off?

I've been immersed in creating a website, but I encountered an issue for which I can't seem to find the solution. Check out my text alignment here (test) - it's not aligned all the way to the left of the content Here is the HTML code: < ...

Floating left and right positions for a fixed CSS div

My navbar is currently set to float right and 330px left with absolute positioning. Everything is working fine in this setup, but I want it to be fixed. The problem arises when trying to convert it to a fixed position. I've tried various methods but n ...

The error message "global.HermesInternal - Property 'HermesInternal' is not found in the type 'Global & typeof globalThis'" appeared

I ran the auto-generated code below: $ react-native init RepeatAloud App.tsx /** * Sample React Native App * https://github.com/facebook/react-native * * @format * @flow strict-local * ...

implementing jquery typewriter plug-in for a responsive bootstrap image

I am using Bootstrap and my image response dynamically, but I am having trouble adding text to it. I would like to use a jQuery typewriter plugin for the text on the image, which should resize according to screen size. Here is my HTML code and I have used ...

Does reducing the number of HTML, PHP, or CSS files truly have a significant impact on improving a webpage's performance, or is it just a minor factor?

Discovering a new HTML minifier on Ajaxian got me thinking - is minimizing HTML, PHP, or CSS files truly a significant improvement for webpages? Would shrinking files that are 100 lines long on average make a noticeable impact? ...

Use CSS to align an element next to a centered element by applying the float property

My webpage is featuring a table right in the middle of it http://example.com/table Can someone help me position the button near the table on the left? I made this detailed diagram to help you visualize: | | | $$center | | ...

Achieving vertical alignment of content within a card using Bootstrap

Can someone help me create a card similar to this design? Example Card I'm having trouble aligning the items at the bottom like in this example: My Card Here is my code snippet: <div class="container"> <div class="row row ...

Two-column layout with consistent height vertically, but varying heights on individual rows

By using JavaScript, I am able to ensure that two columns have equal height. The left column contains user input which can vary in length, causing some columns to have more content than others. My current issue is that there are multiple rows instead of ju ...

jQuery divs display and conceal

Looking for help with this code structure: Here's the HTML: <div class="container"> <button class="a">Button</button> <div class="b" hidden="hidden">Content</div> </div> <div class="container"> & ...

The behavior of React's SetState in an event handler varies when using mocked data versus data fetched from an API

Currently, I am replicating the same scenario with identical code in two different situations. With mocked data With data fetched from an API 1) The case with Mocked Data => https://codesandbox.io/s/select-demo-0e90s is functioning as expected The m ...

Tips for creating a mobile-friendly contact section on your website

I have encountered an issue with my Contact Us page. Although it works perfectly on desktop, the mobile view is not responsive. Is there anyone who can assist me in resolving this error? Here is the Contact Us page that needs to function properly on mobil ...

The shading of the box isn't displaying the correct color in Microsoft Edge and IE 11

I have a unique pattern consisting mainly of white and grey hues. To add a touch of color, I am using the box shadow property in CSS to apply a blue filter effect. This technique successfully displays the desired result in Firefox and Chrome browsers. Howe ...

Sending information to the server displaying as invalid

As a beginner in React JS and Flux, I am struggling to pass my form data from React to my server. While the code runs without errors, the data appears as undefined. Can anyone assist me with this issue? Here is the code that I am using: Below is my Store. ...

One way to assign the name of the select input to match the MenuItem

I have a Select Input with option list containing values. I need to store these values in my state so that I can later dispatch them to my Redux state. While I have successfully saved the values in the state, the name of the selected option is not being di ...

Issue with Datepicker in Angular Bootstrap: format identifier not being utilized

Check out this Plunk for reference. This is how my controller is set up: app.controller("myController", [ "$scope", function($scope){ $scope.DateFormat = "DD/MM/YYYY"; $scope.From = '15/01/2015'; // DD/MM/YYYY ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

Achieving a layout of three columns and two rows (1 x 2 x 2) using flexbox

I am looking to achieve a specific layout using Flexbox. While I am comfortable with CSS, I want to challenge myself by learning how to implement this design using Flexbox for more concise and maintainable code. https://i.stack.imgur.com/QDVfT.png .ban ...

Animating pseudo-elements using Jquery

I'm having trouble animating the :after pseudo-element of my ul. Below is the CSS code I have: #slider .mypagination ul::after { content: ""; width:25%; bottom: 0; left:0; position: absolute; border-top:1px solid #7accc8; ...

Ways to incorporate radio buttons, checkboxes, and select fields into a multi-step form using JavaScript

In the snippet below, I have created a multi-step form where users can provide details. The issue is that currently only text input fields are being accepted. The array of questions specifies the type of input required for each question: Question no.1 req ...

Is the subdirectory set as "/blogs" using firebase?

Can a NextJs app be added as a subdirectory to an existing ReactJs app on firebase hosting? I have the main app already deployed on firebase with its own domain, and I want to include a NextJs app in the path "/blogs" for SEO reasons. Has anyone successful ...