Expanding a centered div beyond 100% width will cause the div to only enlarge towards the right side

I am currently in the process of revamping the login page for my website. I am facing a challenge where I am unable to adjust a div element to extend beyond 100% without it overflowing to the right side instead of the left. Despite trying various methods, I have not been successful in achieving the desired result. I would greatly appreciate it if someone could provide guidance on the CSS property that will help me achieve this.

Check out the CodePen and the code snippet below:

$(function() {
  "use strict"

  var name;
  var loggedin = $(".loggedin").hide();
  var t = 500;

  function store() {
    name = $("input#username").val();
  }

  function init() {
    $("input[type='submit']").on("click", function() {
      store();
      $(".login_inner, .login_inner__avatar").animate({
        'opacity': '0'
      }, t);
      setTimeout(function() {
        $(".login_inner__check").css({
          'opacity': '1',
          'animation': 'spinner 4s 0s linear',
          'transition': 'all ease 3s'
        });
      });
      setTimeout(function() {
        $(".login_inner__check--complete").find('i').animate({
          'opacity': '1'
        }, 500);
      }, 4200);
      setTimeout(function() {
        $(".login").fadeOut(500, function() {
          $(this).remove();
        });
      }, 5000);
      setTimeout(function() {
        loggedin.fadeIn(t, function() {
          $(this).show();
          $(this).find('h2').html("Welcome " + name);
        });
      }, 5500);
      setTimeout(function() {
        $(".loggedin h2").animate({
          'opacity': '1'
        }, t);
      }, 6000);
    });
  };
  init();
});
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Nunito', sans-serif;
}

html, body {
  background: #EDF2F4;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login {
  background: #2B2D42;
  border-radius: 4px;
  width: 300px;
  height: auto;
}
.login_inner {
  display: flex;
  justify-content: flex-end;
  flex-direction: column;
}
.login_inner__avatar {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217538/default-avatar-ponsy-deer.png);
  background-size: cover;
  border: 3px solid #EDF2F4;
  width: 4em;
  height: 4em;
  margin: 0 auto;
  -webkit-transform: translateY(-35px);
          transform: translateY(-35px);
  border-radius: 100%;
}
.login_inner__check {
  border: 1px dashed #FFF;
  border-radius: 100%;
  width: 4em;
  height: 4em;
  position: absolute;
  margin: -185px 120px;
  opacity: 0;
  text-align: center;
}
.login_inner__check--complete i {
  line-height: 4em;
  color: #FFF;
  opacity: 0;
}
.login_inner input {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  background: none;
  border-top: none;
  border-right: none;
  border-left: none;
  border-bottom: 1px solid #33354e;
  width: 100%;
  padding: 1.1em;
  color: #FFF;
  outline: none;
  font-size: 0.9em;
  text-align: left;
}
.login_inner input:last-of-type {
  border-bottom: none;
}
.login_inner input[type="submit"] {
  width: 110%;
  background: #4ECDC4;
  cursor: pointer;
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
  text-align: center;
  margin: 3em auto 0 auto;
}

.loggedin {
  background: #2B2D42;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
}
.loggedin h2 {
  opacity: 0;
  color: #FFF;
  text-align: center;
  font-size: 1.7em;
}

::-webkit-input-placeholder {
  color: #FFF;
}

:-moz-placeholder {
  color: #FFF;
}

::-moz-placeholder {
  color: #FFF;
}

:-ms-input-placeholder {
  color: #FFF;
}

::-ms-input-placeholder {
  color: #FFF;
}

.hide {
  opacity: 0;
}

.show {
  opacity: 1;
}

@-webkit-keyframes spinner {
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

@keyframes spinner {
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='login'>
  <div class='login_inner'>
    <div class='login_inner__avatar'></div>
    <input id='username' placeholder='Give yourself a username' type='text'>
    <input id='email' placeholder='What is your email?' type='email'>
    <input id='password' placeholder='Choose a password' type='password'>
    <input type='submit' value='Sign up'>
  </div>
  <div class='login_inner__check'>
    <div class='login_inner__check--complete'>
      <i class='fa fa-check'></i>
    </div>
  </div>
</div>
<div class='loggedin'>
  <h2></h2>
</div>

The CodePen above showcases the login page, particularly on line 74 of the CSS. I am attempting to expand the button in both directions to create a wrap-around effect. However, I am only able to adjust it to the right side. I believe there should be a straightforward solution to this issue.

  &[type="submit"] {
    width: 110%;
    background: $c-btn-color;;
    cursor: pointer;
    border-bottom-left-radius: $radius - 2;
    border-bottom-right-radius: $radius - 2;
    text-align: center;
    margin: 3em auto 0 auto;
 }

Despite experimenting with various positioning and block size techniques, I haven't been able to find a solution. Any advice on this matter would be highly appreciated!

Thank you!

Answer №1

Your margins on the button are set to auto for left and right - consider removing them and adding align-self: center to center the button - check out the updated code excerpt below:

&[type="submit"] {
    width: 110%;
    background: $c-btn-color;;
    cursor: pointer;
    border-bottom-left-radius: $radius - 2;
    border-bottom-right-radius: $radius - 2;
    text-align: center;
    margin-top: 3em; /* <-- only top margin */
    align-self: center; /* added */
}

For the latest codepen version and code snippet, visit updated codepen and check the following:

$(function() {
  "use strict"

  var name;
  var loggedin = $(".loggedin").hide();
  var t = 500;

  function store() {
    name = $("input#username").val();
  }

  function init() {
    $("input[type='submit']").on("click", function() {
      store();
      $(".login_inner, .login_inner__avatar").animate({
        'opacity': '0'
      }, t);
      setTimeout(function() {
        $(".login_inner__check").css({
          'opacity': '1',
          'animation': 'spinner 4s 0s linear',
          'transition': 'all ease 3s'
        });
      });
      setTimeout(function() {
        $(".login_inner__check--complete").find('i').animate({
          'opacity': '1'
        }, 500);
      }, 4200);
      setTimeout(function() {
        $(".login").fadeOut(500, function() {
          $(this).remove();
        });
      }, 5000);
      setTimeout(function() {
        loggedin.fadeIn(t, function() {
          $(this).show();
          $(this).find('h2').html("Welcome " + name);
        });
      }, 5500);
      setTimeout(function() {
        $(".loggedin h2").animate({
          'opacity': '1'
        }, t);
      }, 6000);
    });
  };
  init();
});
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Nunito', sans-serif;
}

html, body {
  background: #EDF2F4;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login {
  background: #2B2D42;
  border-radius: 4px;
  width: 300px;
  height: auto;
}
.login_inner {
  display: flex;
  justify-content: flex-end;
  flex-direction: column;
}
.login_inner__avatar {
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217538/default-avatar-ponsy-deer.png);
  background-size: cover;
  border: 3px solid #EDF2F4;
  width: 4em;
  height: 4em;
  margin: 0 auto;
  -webkit-transform: translateY(-35px);
          transform: translateY(-35px);
  border-radius: 100%;
}
.login_inner__check {
  border: 1px dashed #FFF;
  border-radius: 100%;
  width: 4em;
  height: 4em;
  position: absolute;
  margin: -185px 120px;
  opacity: 0;
  text-align: center;
}
.login_inner__check--complete i {
  line-height: 4em;
  color: #FFF;
  opacity: 0;
}
.login_inner input {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  background: none;
  border-top: none;
  border-right: none;
  border-left: none;
  border-bottom: 1px solid #33354e;
  width: 100%;
  padding: 1.1em;
  color: #FFF;
  outline: none;
  font-size: 0.9em;
  text-align: left;
}
.login_inner input:last-of-type {
  border-bottom: none;
}
.login_inner input[type="submit"] {
  width: 110%;
  background: #4ECDC4;
  cursor: pointer;
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
  text-align: center;
  margin-top: 3em;
  /* <-- only margin top */
  align-self: center;
  /* added */
}

.loggedin {
  background: #2B2D42;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
}
.loggedin h2 {
  opacity: 0;
  color: #FFF;
  text-align: center;
  font-size: 1.7em;
}

::-webkit-input-placeholder {
  color: #FFF;
}

:-moz-placeholder {
  color: #FFF;
}

::-moz-placeholder {
  color: #FFF;
}

:-ms-input-placeholder {
  color: #FFF;
}

::-ms-input-placeholder {
  color: #FFF;
}

.hide {
  opacity: 0;
}

.show {
  opacity: 1;
}

@-webkit-keyframes spinner {
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

@keyframes spinner {
  to {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='login'>
  <div class='login_inner'>
    <div class='login_inner__avatar'></div>
    <input id='username' placeholder='Give yourself a username' type='text'>
    <input id='email' placeholder='What is your email?' type='email'>
    <input id='password' placeholder='Choose a password' type='password'>
    <input type='submit' value='Sign up'>
  </div>
  <div class='login_inner__check'>
    <div class='login_inner__check--complete'>
      <i class='fa fa-check'></i>
    </div>
  </div>
</div>
<div class='loggedin'>
  <h2></h2>
</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

Utilize Jquery Mobile ThemeRoller's design on your MVC4 mobile app for a cohesive and professional look

After creating an MVC4 Mobile application in Visual Studio 2013, I am struggling to apply jquery mobile themeroller themes to it. I attempted to replace the existing theme css with my custom theme, but it does not seem to be working at all. See the code ...

Creating a 3-column div with varying sizes of text in another div at the center position

I am attempting to create a 3-column layout using only DIVs, but I am facing some challenges. If I were to use tables in the traditional HTML 4 way, I could achieve this: <div style="width:100%"> <table width="50%" align="center"> ...

Modify the JS/JQuery variable by utilizing the data entered into an HTML input field

I have implemented a javascript/ajax request on my advanced search page. <script> // window.setInterval(function() // { $(function () { var SearchTerm = '<?php echo $_POST['Search']; ...

Ways to extract all hyperlinks from a website using puppeteer

Is there a way to utilize puppeteer and a for loop to extract all links present in the source code of a website, including javascript file links? I am looking for a solution that goes beyond extracting links within html tags. This is what I have in mind: a ...

Using Bootstrap 4, you can create nested rows that will automatically expand to fill their parent container, which in turn has been set

In my current setup, I have a div with the class "d-flex flex-column" that contains a navbar and a container. Within this container, there is another div with the class "d-flex flex-column" which then contains two rows. I am using flex-grow to make the con ...

What is the best way to use CSS to center two blocks with space in between them?

My goal is to achieve a specific design: I want two text blocks with some space in between them aligned around the midline of the page (refer to the image). I have experimented with the float property, as well as used margin and padding to create the gap ...

Create an input field with a dynamic and exclusive identifier using the DataTables plugin

I am having trouble creating unique IDs for each input field based on the number of rows Here is the code snippet: $(document).ready(function() { var oTable = $('#jsontable').dataTable(); //Initialize the datatable $.ajax({ url ...

Is there a way to make my red div switch its background color from red to green when I press the swap button?

How can I make the red div change its background color to toggle between red and green when I click on the swap button in the following code? $(document).ready(onReady); var numberOfClicks = 0; function onReady() { console.log('inside on ready ...

Tips for aligning a form in the center of a webpage

I have a code snippet using material-ui that I want to center on the page, but it's not working. Can someone please help me fix this issue? Thank you in advance. import React from 'react'; import { makeStyles } from '@material-ui/core ...

Reveal or conceal the footer section as you reach the end of the webpage

My webpage layout consists of a fixed nav-bar at the top, a drop down sidebar, a <div> element with an id of content, some content inside the <div>, and a bottom <div> with a fixed position. I am trying to hide the bottom <div> whe ...

Image source not functioning properly

I am attempting to dynamically load an image and HTML using Angular but it doesn't seem to be working. Here is what I have tried: <img ng-src="img/{{product.Category}}/{{product.id}}.jpg"> and also this: <img src="img/{{product.Category}}/ ...

Show User-Uploaded Image on Redirected Webpage with Flask and html

My goal is to develop a webpage where users can submit an image, and upon submission, they are redirected to a new page displaying the rendered image. I have referenced the code from How to pass uploaded image to template.html in Flask for guidance, but un ...

Modifying the color of the highlighted selection in a dropdown select box

Is it possible to change the blue highlight on this dropdown to gray? Check out this demo of a select box I am aiming to alter the highlight color to gray, can someone help me achieve this? select { border: 0; color: #EEE; background: transparen ...

What could be causing the FontAwesome social icons in <ul> to malfunction?

I'm a beginner and I've been following various tutorials to achieve my goal. The main objective is to create animated social icons in the footer. However, I have encountered an issue where the social icons from FontAwesome are not working. When ...

Bind ng-model with button click in AngularJS

I am encountering a frustrating issue with data binding utilizing ng-model and button. The functionality of my website is as follows: The HTML site showcases a list of projects (imported from an external .json file). Each row contains an Edit button tha ...

Numerous DIVs with floating elements and border styling

Trying to align two divs with one floating to the left and with a width of 80%, while the other is floated to the left with 20% width, is causing some issues. I want to add a border on the right side of the first div and apply a box-shadow of 5px since eac ...

The button in Bootstrap 4 that triggers the modal stays in a highlighted or clicked state even after the modal has been

I am currently utilizing the button below to trigger the opening of a modal window However, upon closing the modal, it seems to maintain a highlighted or clicked appearance with a shadow effect. Initially, I assumed I could address this issue by implement ...

Space within a series of photographs

Looking for some assistance: I am trying to maintain a consistent margin of 10px between posts and between photos in a photoset. However, when a post is a photoset, the margins of the bottom photo and the overall post add up to 20px. I want to retain the ...

Issue with div:after transition not functioning in Safari

The transition effect on div:after does not function properly in Safari. Below is the code for reference: HTML: .bbtn { width: 151px; height: 48px; background: #ef2e41; margin: auto; margin-top: 32px; -webkit-transition: all 0.3s ease-in-ou ...

How to efficiently remove duplicate items from multiple select dropdowns in Angular using ng-repeat?

Need help with dynamically assigning objects to select boxes in AngularJS. I have a scenario where I add multiple select boxes to a form, but each box should only display items that haven't been selected in other boxes. How can I achieve this functio ...