What is the best way to align a logo in a log-in screen?

I am having an issue with centering the logo on my login form. The "signin" text is centered perfectly, but the logo always stays at the top left corner. I don't understand why the logo is not centered. If anyone has a solution to propose, I would greatly appreciate it.

Additionally, I would like to know how to make the logo responsive. Any tips or techniques would be very helpful.

Thank you in advance for your response.

.parent {
    position: absolute;
    top: 10%;
    left: 15%;
}

.wrapper {
    position: relative;
    width: 70vw;
    height: 80vh;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.wrapper::before {
    content: "";
    position: absolute;
    top: 0;
    left: -50%;
    width: 100%;
    height: 100%;
    background: linear-gradient(-45deg, #79df4a, #8673A1);
    z-index: 6;
    transform: translateX(100%);
    transition: 1s ease-in-out;
}

.logo img {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 75px;
}

.signin {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 5;
}

form {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 40%;
    min-width: 238px;
    padding: 0 10px;
}

form.sign-in-form {
    opacity: 1;
    transition: 0.5s ease-in-out;
    transition-delay: 1s;
}

.title {
    font-size: 35px;
    color: #8673A1;
    margin-bottom: 10px;
}

.panels-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;
}

.panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    width: 35%;
    min-width: 238px;
    padding: 0 10px;
    text-align: center;
    z-index: 6;
}

.left-panel {
    pointer-events: none;
}

.content {
    color: #fff;
    transition: 1.1s ease-in-out;
    transition-delay: 0.5s;
}

.left-panel .content {
    transform: translateX(-200%);
}

.right-panel .content {
    transform: translateX(0);
}

.signin_item_block {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 40%;
    min-width: 238px;
    padding: 0 10px;
}

.signin_item_block.sign-in-block-form {
    opacity: 0;
    transition: 0.5s ease-in-out;
    transition-delay: 1s;
}


/*Responsive*/

@media (max-width:779px) {
    .wrapper {
        width: 100vw;
        height: 100vh;
        background-color: red;
    }
}

@media (max-width:635px) {
    .wrapper::before {
        display: none;
    }
    form {
        width: 80%;
    }
    .signin_item_block.sign-in-block-form {
        display: none;
    }
    .wrapper.sign-up-mode2 form.sign-in-block-form {
        display: flex;
        opacity: 1;
    }
    .wrapper.sign-up-mode2 form.sign-in-form {
        display: none;
    }
    .panels-wrapper {
        display: none;
    }
}

@media (max-width:320px) {
    form {
        width: 90%;
    }
}
<!doctype html>
<html lang="fr">
   <head>
      <meta charset="utf-8">
      <title>Titre de la page</title>
      <link rel="stylesheet" href="style.css">
      <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
   </head>
   <body>
      <div class="parent">
         <div class="wrapper">
            <div class="logo">
               <img src="https://zupimages.net/up/23/02/0itb.png" alt="image">
            </div>
            <div class="signin">
               <form (ngSubmit)="logon()" class="sign-in-form">
                  <!-- Signin -->
                  <h3 class="title">Signin</h3>
               </form>
               <div class="signin_item_block sign-in-block-form"></div>
            </div>
            <div class="panels-wrapper">
               <div class="panel left-panel"></div>
               <div class="panel right-panel">
                  <div class="content">
                     ...
                  </div>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>

Answer №1

Resolved: https://stackblitz.com/edit/js-ndbzyq?file=style.css

https://i.sstatic.net/6Mv8t.png

Initially, the code was disorganized with unnecessary CSS like position: absolute.

The key modifications made were:

  • Moving the logo div inside the signin div.
  • Changing the flex-direction of the signin div to column.
  • Utilizing display flex for the logo class to center justify-content.
<div class="signin">
  <div class="logo">
    <img src="https://zupimages.net/up/23/02/0itb.png" alt="image" />
  </div>

  <div>
    <form (ngSubmit)="logon()" class="sign-in-form">
      <h3 class="title">Signin</h3>
    </form>
  </div>
  <div class="signin_item_block sign-in-block-form"></div>
</div>
.logo {
  justify-content: center;
  display: flex;
  width: 50%;
  min-width: 238px;
}

.signin {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  z-index: 5;
  flex-direction: column;
}

To improve, it is recommended to redesign the entire HTML structure using Flex or Grid instead of relying on position absolute.

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

Combining Content on a GitHub Page

Within the <head> section of my index.html, I have successfully utilized these links on localhost: <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"> <link href=&apos ...

Achieve center alignment for two column divs without altering the HTML code using only CSS

Recently, I stumbled upon a basic HTML code that I am unable to modify due to restrictions: <div id="container"> <div id="a"> Title col </div> <div id="b"> Left col </div> <div id="c"> ...

Utilize CSS with dynamically created elements

I am currently figuring out how to use my .each() function with a $(document).ready and a click event. Here's what I have so far: $(document).ready(function(){ $(".help-inline").each(function() { $(this).css('display', 'none&apos ...

Use JavaScript to load and set a background image for a div

When it comes to loading different images onto an "img" tag by printing their URLs using JavaScript and then letting CSS manipulate the content in the tag, I have a code snippet that does just that. $(window).load(function() { var randomImages = [&apo ...

Tips on customizing the appearance of mat-card-title within a mat-card

Is there a way to truncate the title of a mat card when it overflows? I tried using the following CSS: overflow:hidden text-overflow:ellipsis white-space: nowrap However, the style is being overridden by the default mat-card style. I attempted to use mat ...

Show image details on hover?

I have six images displayed full width using a flex grid. I would like the image information (along with a visit button) to appear on hover, and the brightness of the image should decrease. I am struggling to position the information in the center of the i ...

Managing the vertical dimensions of a div

I've created a unique set of visually appealing cards that house meaningful messages within an infinite scrolling feed. The intended functionality is for the complete message to be displayed upon clicking a "more" button, as the messages are typically ...

Replicating DIV element with input field

Once again, I find myself stuck in my attempt to duplicate a DIV and its form elements using jQuery. Button: <div class="addNew" id="addSkill">Add Skill <i class="icon-plus"></i></div> This is the Div and contents that I want to ...

Ways to achieve text transparency with CSS without converting it to an image

Is there a way to have my navigation bar indicate the selected page by changing the text color and adding a black background, while making only the text inside the current page nav transparent? For example, you can see the effect here: sammarchant.co.uk/n ...

Displaying a div based on the response after it is received using an if/else statement

In my form, each question is on a separate page (div), with the ability to show and hide pages. If a user receives a response from the API with a status of "accepted", they are redirected to a URL. I'm currently trying to display a div if their status ...

Enhance the code for updating the content within a div element

I recently discovered that utilizing jQuery allows for updating the content within a div. My goal now is to enhance this script so the content remains consistent, even while loading or not. Take a look at my current code: function changeContent () { va ...

What is the best way to vertically center a column of images on mobile devices in a responsive manner?

Currently, I am developing an application that showcases the 9 newest photos with a specific tag. To ensure consistency in image sizes, I have set each photo to be 240px wide and 200px tall. My query now is how can I vertically center these images so they ...

What is the best way to apply a png overlay to each img tag when hovered over?

Here is the code snippet I am working with: <div class="latest-post"> <a href="http://localhost/blaze/2011/documentaries/test-big-thumb" rel="bookmark"> <span> <img width="140" height="100" src="http:// ...

Revamping Existing Styles: Making a Statement with `:after`

In my asp.net mvc application, I am facing an issue where the * symbol, representing a required field, and the ? symbol, representing help, are not both being displayed. The ? symbol seems to be overriding the * symbol, resulting in only one symbol being s ...

Text that is superimposed onto an image

Struggling to implement a hovering text over an image? I attempted to follow a tutorial, but couldn't adapt it to my project. While I managed to create a fixed overlay, I aim for a responsive solution that adjusts with resolution changes. My goal is t ...

Is there a significant time-saving benefit to utilizing nested rules in CSS, particularly when using HAML or LESS?

Here is how I am currently coding my CSS: Regular CSS: #content { color: white; background: black; } #content a { color: yellow; } #content p { margin: 0; } #content (etc...) #contnet (etc...) #content (etc...) (I always include the parent eve ...

Enhanced Custom Code Highlighting for Aptana Studio 3 with support for .less files

Looking to enhance syntax highlighting for .less files in Aptana Studio 3 but struggling to find a solution. XText only works with Eclipse, and the forums offer limited guidance. Has anyone successfully implemented custom syntax highlighting for .less fi ...

Tips for creating an input field that automatically expands and has a specific width

I am facing an issue with the alignment of my search field. Here is the code snippet: #menu_search{ position: absolute; width: 100%; max-width: 1280px; display: inline; float: right; right: 0px; z-index: 99; } I would like th ...

The background color should only cover a specific percentage of the element

Here is the current structure I have: <li class="myclass" ng-class="myAngularClass"> <div> div1 <div> div2 </div> </div> </li> The li element has dynamic dimensions and width. The class "myAngularClass" i ...

Updating the background color using typescript

Before transitioning to angular development, I had experience working with vanilla Javascript. I encountered a challenge when trying to modify the css properties of specific elements using Typescript. Unfortunately, the traditional approach used in Javascr ...