umop apisdn
umop apisdn

Reputation: 683

CSS Resizing failure when browser window is scaled vertically

I am trying to create a simple login page, and after learning about CSS3 flexbox some time ago I redid the page using this new concept. So now, my page looks like this:

enter image description here

which is what I wanted...until I tried to resize the browser. Then, I got this (when I simply decreased the height of the browser window without decreasing the width):

enter image description here

and this (when I decreased both the height and the width of the browser window to a minimum):

enter image description here

This confused me since I read on other stackoverflow answers that I do not have to have media queries yet to create a responsive web design (which I do intend to do, later on), but just CSS by specifying the max-width in terms of percentages.

Here's my code:

HTML:

<div class="center">
    <!-- Logo -->
    <img id="logo" src="assets/logowshadow.png" alt="cueclick logo">

    <!-- Login element -->
    <form class="login" action="/action_page.js" method="post">
        <p>Enter <i>your</i> secret key</p>
        <div id="password">
            <img id ="eye" src="assets/eye2.png" alt="eye">
            <input type="password" name="secret-key" placeholder="ilovecueclick" autofocus autocomplete="off"/>
        </div>
    </form>
</div>

CSS:

/* -- Background image -- */
body {
    background-image: url(assets/wood.png);
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

/* -- Center element -- */
.center {
    max-width: 60%;
    max-height: 80%;
    width: 30%;
    height: 40%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 15%;
    box-shadow: 2px 2px 4px 3px #505050;
    position: absolute;
    z-index: 1;
}

/* -- Logo style -- */
#logo {
    position: relative;
    z-index: 2;
    max-width: 100%;
    height: auto;
}

/* -- Form styles -- */
form.login {
    max-width: 100%;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 2;
}

#password {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-bottom: 5%;
}

/* -- Show password -- */
#eye {
    height: auto;
    max-width: 15%;
    margin-right: 3%;
}

/* -- Login element -- */
form.login p {
    font-family: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
    font-size: 2vw;
    max-width: 100%;
    height: auto;
    line-height: 2%;
}

form.login input[type=password] {
    max-width: 100%;
    width: 100%;
    height: auto;
}

To explain what this code is doing further: - body has a full-size background image that scales with the browser window - 'center' is essentially the translucent white rectangle above the background - the logo and the form log-in elements overlap the white rectangle

I have also created three flex containers for their flex items (to deal with the troublesome issue of centering): 1) body is the flex container, and the flex item is the center element 2) center is the flex container, and the logo and the form input section (ie. the paragraph + eye + input field) are the flex items 3) the 'password' div is the flex container (in-line), and the eye and login field are the flex items

I am really unsure where the issue lies, since there seems to be some scaling achieved with the current code...

The full HTML can be found here: https://pastebin.com/6tS6SXi3, and the full CSS can be found here: https://pastebin.com/6M11HnJE

Thanks in advance!

EDIT:

After experimenting further, it turns out that I simply had to let the height of the center class be auto...

Accepted the answer for its simplicity even though it does not use flex-box like I would have wanted it to

Upvotes: 1

Views: 111

Answers (2)

johnashu
johnashu

Reputation: 2211

Start from Mobile up..

Something like this (obliviously adjust the 100% to what you desire)

Work from mobile to desktop and I thinki you will find you situation easier to deal with that way..

This resizes fine for me..

@media (max-width:768px){
    .center {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    }

/* -- Logo style -- */
#logo {
    max-width: 100%;
    height: auto;
}

/* -- Form styles -- */
form.login {
    max-width: 100%;

}

#password {
max-width:100%
}

/* -- Show password -- */
#eye {
    max-width: 100%;
}

/* -- Login element -- */
form.login p {
    max-width: 100%;
    height: auto;
}

form.login input[type=password] {
    max-width: 100%;
    width: 100%;
    height: auto;
}


}

Upvotes: 0

Ryan Tsui
Ryan Tsui

Reputation: 948

Construct your form wrapper with HTML and CSS instead of using an image, which is very hard to control when screen size changes.

Sample: https://codepen.io/anon/pen/NgPGoQ

.login {
  width: 300px;
}

@media screen and (max-width: 768px) {
  .login {
    width: 80%;
  }
}

Set a default width for your wrapper and add media queries for the screen sizes that you would like a custom width.

Upvotes: 1

Related Questions