1

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

umop apisdn
  • 653
  • 9
  • 20
  • I think you need to play with media queries –  Jun 04 '17 at 16:29
  • I was bothered by answers like this one here: https://stackoverflow.com/questions/4684304/how-can-i-resize-an-image-dynamically-with-css-as-the-browser-width-height-chang – umop apisdn Jun 04 '17 at 16:46

2 Answers2

1

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.

Ryan Tsui
  • 918
  • 5
  • 14
  • thanks for your suggestion, but i wish that there was an answer that could manipulate flex-box too...additionally, my code works for when the browser window scales horizontally but not when it scales vertically – umop apisdn Jun 07 '17 at 02:56
  • Still accepting your answer for the simplicity it gives though! I guess sometimes it is better not to complicate matters...thanks! – umop apisdn Jun 07 '17 at 03:06
  • 1
    This will also work when you scale your browser window vertically. The login-wrapper will always be big enough to wrap all your form elements. However, there will be a scrollbar when the login-wrapper is taller than the viewpoint. You might want to apply additional styling to customize your form in such short viewports. – Ryan Tsui Jun 07 '17 at 03:13
0

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;
}


}
johnashu
  • 2,167
  • 4
  • 19
  • 44