Guide on how to position a single anchor at the center of a div alongside other elements

I am having trouble centering an anchor on my webpage. I have tried using text-align: center;, but it always puts the link on a new line due to the required div element. Other methods like margins and spans have not worked for me either.

span.right {
    float: right;
}
<form action="login.py" method="post">
  <div class="container">
    <label for="username">
      <b>Username</b>
    </label>
    <input type="text" placeholder="Enter Username" name="uname" required>
    <label for="pword">
      <b>Password</b>
    </label>
    <input type="password" placeholder="Enter password" name="pword" required>
    <button type="submit">Login</button>
    <label>
      <input type="checkbox" checked="checked" name="remember"> Remember me
    </label>
    <a class="link-secondary" href="#">Sign up?</a>
    <span class="right"><a class="link-secondary" href="#">Forgot password?</a></span>
  </div>
</form>

This is what the html looks like, and I want to position the span containing "sign up?" accordingly.

Thank you.

Answer №1

For achieving this layout, Bootstrap's flex utilities can be used effectively by adding the following classes to a new wrapping div: d-flex justify-content-between

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7959898838483859687b7c2d9c6d9c4">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<form action="login.py" method="post">
  <div class="container">
    <label for="username">
      <b>Username</b>
    </label>

    <input type="text" placeholder="Enter Username" name="uname" required>

    <label for="pword">
      <b>Password</b>
    </label>

    <input type="password" placeholder="Enter password" name="pword" required>

    <button type="submit">Login</button>

    <div class="d-flex justify-content-between">
      <label>
        <input type="checkbox" checked="checked" name="remember"> Remember me
      </label>

      <a class="link-secondary" href="#">Sign up?</a>
      
      <a class="link-secondary" href="#">Forgot password?</a>
    </div>
  </div>
</form>

Answer №2

Alternatively, you can achieve the same layout without relying on Bootstrap by simply using display: flex; with the justify-content attribute set to space-between:

.flex-container {
  display: flex;
  justify-content: space-between;
}
<form action="login.py" method="post">
      <div class="container">
        <label for="username">
          <b>Username</b>
        </label>
        <input type="text" placeholder="Enter Username" name="uname" required />
        <label for="pword">
          <b>Password</b>
        </label>
        <input
          type="password"
          placeholder="Enter password"
          name="pword"
          required
        />
        <button type="submit">Login</button><br />
        <div class="flex-container">
          <label>
            <input type="checkbox" checked="checked" name="remember" /> Remember
            me
          </label>
          <a class="link-secondary" href="#">Sign up?</a>
          <a class="link-secondary" href="#">Forgot password?</a>
        </div>
      </div>
    </form>

Answer №3

<form action="login_page.py" method="post">
    <div class="container">
        <label for="username_input"gt;<b>Enter Your Username</b></label>
        <input type="text" placeholder="Type your username here" name="uname_input" required>
        <label for="password_input"gt;<b>Enter Your Password</b></label>
        <input type="password" placeholder="Type your password here" name="pword_input" required>
        <button type="submit">Login Now</button>
        
<div class="flexA">
        <div><label><input type="checkbox" checked="checked" name="remember_me"&rtl; Remember me? </label><a class="link-secondary" href="#">Sign up Here!</a></div>
        <a class="link-secondary" href="#">Forgot Your Password?</a>
</div>
    </div>
</form>
and apply the following css styles to flexA : 
.flexA {
display: flex;
justify-content: space-between;
align-items: center;
}

Answer №4

By incorporating flex into the design, your layout will be flexible and customizable to meet your specific needs.

<form action="login.py" method="post">
        <div class="container">
<div class="row">
            <label for="username"><b>Username</b></label>
            <input type="text" placeholder="Enter Username" name="uname" required>
            <label for="pword"><b>Password</b></label>
            <input type="password" placeholder="Enter password" name="pword" required>
            <button type="submit">Login</button>
<div class="remember-bottom d-flex column justify-content-between">
            <label><input type="checkbox" checked="checked" name="remember"> Remember me? </label>
            <a class="link-secondary" href="#">Sign up?</a>
            <span class="right"gt;<a class="link-secondary" href="#">Forgot password?</a></span>
</div>
        </div>
</div>
    </form>

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

Colorful radial spinner bar

I am interested in replicating the effect seen in this video: My goal is to create a spinner with text in the center that changes color, and when the color bar reaches 100%, trigger a specific event. I believe using a plugin would make this task simpler, ...

Customize the arrow color in a TextField Select component from material-ui

Having some trouble changing the color of my arrow icon within the Material-ui TextField Select. Here's what I've tried: icon: { fill: "white !important", }, Despite applying these props, the color remains unchanged. I've experimen ...

Clicking on a different texture/image allows for the texture to change in Three.js

I am working on creating a 360 image view using Threejs. I have a total of 4 images, with one linked to Threejs and the other 3 displayed as thumbnails at the bottom of the page. When a thumbnail is clicked, the 360 image view should change accordingly. Y ...

Choosing various li classes within a navigation bar

Struggling to pick the right JQuery elements for my portfolio site. The aim is to show/hide the .inner (Task) items by clicking on the .outer (Category) items, complete with rotating .arrows when the menu expands. Check out a similar question, along with ...

Display issues with React styled components preventing proper rendering on the screen

Having issues with my style components displaying in a web application I'm developing using React and Ruby on Rails. Everything was working fine until I added a third style component, now even after removing it, nothing shows up on the screen after ru ...

Dynamic visuals created with Jquery and Ajax

While I'm not an experienced developer, I have managed to work with some small Jquery scripts. Lately, I've been struggling for the past month trying to figure out how to implement a specific functionality that I would like to incorporate. Does a ...

What is the best way to incorporate an opaque overlay onto an image along with text overlay on top of the image?

I'm struggling to overlay an opaque layer above an image with responsive text on top of it. I want the opaque layer to be positioned above the image but below the text, and not appear when hovering over the image. You can view my test page here: I a ...

Using both italic and regular text in an HTML (or ASP.NET) textbox can add emphasis and enhance readability for

Is there a way to achieve this using JavaScript? For instance, if the initial text is 'Axxxxxx', I want it to be displayed in a textbox with normal style for the first letter and italic style for the rest like 'A*xxxxxx*' If the initia ...

How do you specifically apply an Inset Border Shadow to just two sides using CSS?

Is it possible to apply the inner shadow specifically to the bottom and right sides? I've come across some hacks, but they seem to be more focused on regular border shadows. It's easier to add a drop shadow than to remove an inner shadow. -moz-b ...

How to Adjust the Padding of Tree Row in GWT?

Have you ever seen a GWT tree before? It sort of resembles the following structure: <div class="gwt-Tree"> <div style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; margin-left: 0px; padding-left: ...

Looping through multi-dimensional JSON objects with jQuery

Hello there, I'm currently facing some challenges in getting the screen below to work properly: Project progress screen I have generated the following JSON data from PHP and MYSQL. My goal is to display the project alongside user images and names whe ...

Creating a dynamic 2D image using HTML5 animation

As a beginner HTML5 developer, I have been exploring ways to create an animated image using multiple jpg files stored in a specific folder on my website. My goal is to design an animation of a rabbit running across the page when a user clicks on a button. ...

Retrieving the background image URL from inline CSS using jQuery

I'm looking for a link similar to url(img/bg/06.jpg), but when using jQuery, I get a longer link like url("file:///D:/WORKING%20FILE/One%20Landing%20Page/version/img/bg/06.jpg") https://i.stack.imgur.com/8WKgv.png Below is the code snippet in questi ...

JavaScript script that parses innerHTML

Does the behavior of element.innerHTML = '<script>alert()</script>'; differ across browsers? Can I consistently expect innerHTML to not parse scripts? ...

Creating a responsive layout with two nested div elements inside a parent div, all styled

I'm currently facing an issue with using padding in my CSS to make the two divs inside a parent div responsive at 50% each. However, when combined, they exceed 100%. I suspect this is due to the padding, but I'm unsure how to resolve it. .column ...

Leveraging jquery to retrieve the value of a selected element

Why is this code not functioning properly? Here is the HTML snippet: <img src='picture.jpg'> <select name='blah[0]' onchange='changePicture();'> <option value='default.jpg'>Default</option> ...

Script for converting Fixed Positioned Elements to Static

I am frequently finding that elements on web pages are causing disruptions due to their fixed positioning. I am exploring ways to disable the position: fixed CSS rules on any website I visit. To address this issue, I have developed a userscript specifical ...

Tips on how to apply CSS styles to a specific "div" card only?

I'm working on a project that involves using multiple templates, but I've run into issues with conflicting CSS links from different templates. I want to ensure that the CSS link from one template only affects a specific HTML card without impactin ...

PHP script to populate a table with images based on certain conditions

I have a table in HTML that displays results from a SQL database on the right hand side. The code snippet for populating each cell is as shown below: <tr> <td>House</td> <td><?php echo $row_buyerdetails['tod_hous ...

Adjust the classes of the static navigation bar based on the background of the section it is positioned over

In the process of developing a website using Bootstrap 4, I encountered a challenge with sections featuring both light and dark backgrounds along with a fixed navbar. The navbar, which is set to dark using the css class bg-dark, becomes indistinguishable ...