Building a nice looking login page with custom CSS

Categories PHP, PHP Code Generator, PHP Form Generator, Tutorials

PHPRunner 7.0 and ASPRunnerPro 8.0 add a new new 'Custom CSS' feature - an easy way to modify the appearance of your pages adding bells and whistles Style Editor doesn't support. Lets see how we can build a custom login page similar to this one:


Lets start with some basic stuff.

Here is how you can set image as a background of the login page:

  1. body.function-login {
  2. height:100%;
  3. background:transparent url("http://mywebsite.com/images/some_image.jpg") no-repeat center center fixed;
  4. background-size:cover;
  5. }

What is body.function-login by the way?

body.function-login means this background will be only applied to the login page. If you want to apply this background to all List pages use the following:

  1. body.function-list {
  2. height:100%;
  3. background:transparent url("http://mywebsite.com/images/some_image.jpg") no-repeat center center fixed;
  4. background-size:cover;
  5. }

To figure out class names of individual pages you will need either Firefox browser with Firebug or Chrome. Here is the screenshot of body tag inspected in Chrome Developer Tools.

What if I want to apply this background image to all page in my application?

It's not difficult at all. Simply use body tag in Custom CSS:

  1. body.function-list {
  2. height:100%;
  3. background:transparent url("http://mywebsite.com/images/some_image.jpg") no-repeat center center fixed;
  4. background-size:cover;
  5. }

Okay, I'm getting it. What if I have a single List page that needs to have her own background?

This can be done as well. Custom CSS belongs to the current selected Style. If you assign a custom Style to one of List pages you can use Custom CSS that will be assigned to that single List page only.

We proceed to the Style Editor, make sure this List page is selected, choose "Apply to the current page" in Styles section and choose a different style for this page. Now we can proceed to Custom CSS and set different image as a background for this page.

  1. body.function-list {
  2. height:100%;
  3. background:transparent url("http://mywebsite.com/images/some_other_image.jpg") no-repeat center center fixed;
  4. background-size:cover;
  5. }

Got it. What about that semi-transparent login form?

Here is the code that does the job.

  1. .function-login .rnr-c > * {
  2. background: rgba(17,17,17,0.85) !important;
  3. }

What about Add page? I need the same look and feel there.

It will be slightly different. The same idea though.

  1. .function-add .rnr-c > * {
  2. background: rgba(17,17,17,0.85) !important;
  3. }

I have applied this code to the login page. This is what I got.

Not bad! This can be enough for most projects however with some extra work we can make it look exactly like a screenshot of the beginning of this article. Lets get started.

1.  Proceed to Security screen, turn on Facebook login and Password reminder.

2. Proceed to Style Editor, select Login page on the left, choose 'Apply to the current page' option from  'Project layouts'. Choose login1 layout.

3. You may notice that login page form is a bit wider than what we are after. Click 'Customize layout' and remove width=500 snippet.

4. Lets spend some time in Visual Editor now. We need to move Facebook button to the top and also move username/password labels so they appear on the top of input boxes.

Before moving form labels I recommend to turn on Show Borders mode.

Drag username input box to the left column and position it under Username label. You will need to use Enter button to insert a line break between the label and the field itself. Do the same with password field. Now delete the right column, we don't need it anymore.

Moving Facebook button should be easy. Just click on it and drag it to the top of the form.

5. Now lets change some labels. Click on 'Submit' button, switch to HTML mode and change 'Submit' to 'LOG IN'.

6. Switch back to Visual Mode. Select 'Remember password' link and switch to HTML mode again. We need to modify this link adding CSS forgot class. This class will be later defined in Custom CSS section. Here is how Remember password link is supposed to look in HTML code.

  1. <A class="forgot" href="remind.php">
  2. Forgot your password?
  3. </A>

7. Since built-in Facebook button doesn't support the style we looking we need to replace it with own own button. For this purpose click on Facebook button, switch to HTML code and replace button's HTML code with the following:

  1. <a href="#" onclick="window.login();return false;">
  2. Log in with Facebook
  3. </a>

It will not look nice until we apply our custom CSS. Do not worry, we'll get to it in a few seconds.

8. Now here is the CSS code and glues it all together. I'm posting it as a single code snippet so you can copy and paste it to your project. Note that this code requires one more image file (facebook.png), that appears on Facebook button. You can download it from the Web, upload somewhere to your website and modify image URL in CSS code accordingly. We use icon size 29x29px in this example.

  1. /* makes login form semi-transparent */
  2. .function-login .rnr-c > *
  3. {
  4. background: rgba(17,17,17,0.85) !important;
  5. }
  6.  
  7.  
  8. /* login page background */
  9. body.function-login {
  10. height:100%;
  11. background:transparent url("http://yourwebsite.com/images/homepage.jpg") no-repeat center center fixed;
  12. background-size:cover;
  13. }
  14.  
  15. /* styling of 'remember password' link */
  16.  
  17. a.forgot {
  18. color: #70d4dd;
  19. text-decoration: none;
  20. font-family: 'Open Sans', sans-serif;
  21. font-size: 12px;
  22. font-style: normal;
  23. font-weight: normal;
  24. font-variant: normal;
  25. }
  26.  
  27.  
  28. /* sets height of the login form header */
  29. .rnr-b-loginheader {
  30. height: 100px;
  31. }
  32.  
  33. /* Facebook button styling */
  34.  
  35. .facebook {
  36. -webkit-box-shadow: rgb(152, 202, 245) 0px 2px 0px -1px inset, rgba(64, 64, 64, 0.298039) 0px 2px 2px 0px;
  37. background-attachment: scroll;
  38. background-clip: border-box;
  39. background-color: rgb(0, 131, 213);
  40. background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0.05, rgb(80, 164, 216)), to(rgb(0, 131, 213)));
  41. background-origin: padding-box;
  42. background-size: auto;
  43. border-bottom-color: rgb(8, 135, 213);
  44. border-bottom-left-radius: 3px;
  45. border-bottom-right-radius: 3px;
  46. border-bottom-style: solid;
  47. border-bottom-width: 1px;
  48. border-image-outset: 0px;
  49. border-image-repeat: stretch;
  50. border-image-slice: 100%;
  51. border-image-source: none;
  52. border-image-width: 1;
  53. border-left-color: rgb(8, 135, 213);
  54. border-left-style: solid;
  55. border-left-width: 1px;
  56. border-right-color: rgb(8, 135, 213);
  57. border-right-style: solid;
  58. border-right-width: 1px;
  59. border-top-color: rgb(8, 135, 213);
  60. border-top-left-radius: 3px;
  61. border-top-right-radius: 3px;
  62. border-top-style: solid;
  63. border-top-width: 1px;
  64. box-shadow: rgb(152, 202, 245) 0px 2px 0px -1px inset, rgba(64, 64, 64, 0.298039) 0px 2px 2px 0px;
  65. color: rgb(255, 255, 255);
  66. cursor: auto;
  67. display: block;
  68. font-family: 'Open Sans', sans-serif;
  69. font-size: 16px;
  70. font-style: normal;
  71. font-variant: normal;
  72. font-weight: bold;
  73. height: 49px;
  74. line-height: 49px;
  75. list-style-image: none;
  76. list-style-position: outside;
  77. list-style-type: none;
  78. margin-bottom: 0px;
  79. margin-left: auto;
  80. margin-right: auto;
  81. margin-top: 30px;
  82. outline-color: rgb(255, 255, 255);
  83. outline-style: none;
  84. outline-width: 0px;
  85. padding-bottom: 0px;
  86. padding-left: 32px;
  87. padding-right: 2px;
  88. padding-top: 0px;
  89. text-align: left;
  90. text-decoration: none;
  91. text-shadow: rgb(0, 0, 0) 0px -1px 1px;
  92. text-transform: uppercase;
  93. vertical-align: baseline;
  94. width: 252px;
  95. background: -moz-linear-gradient(center top , #50A4D8 5%, #0083D5 100%) repeat scroll 0 0 transparent;
  96. }
  97.  
  98.  
  99. a.facebook-icon:before {
  100. background: url(http://yourwebsite.com/images/facebook.png) no-repeat;
  101. content: '';
  102. display: inline-block;
  103. width: 29px;
  104. height: 29px;
  105. position: relative;
  106. left: -15px;
  107. top: 9px;
  108. }
  109.  
  110. /* make input boxes on the login page slightly large */
  111.  
  112. .function-login input[type=text], .function-login input[type=password] {
  113. background-color: #ffffff;
  114. border: 1px solid #c3c2c2;
  115. -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
  116. -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
  117. box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
  118. width: 290px !important;
  119. display: inline-block;
  120. height: 26px;
  121. padding: 0px 6px;
  122. margin: 5px 0 0 0;
  123. font-size: 12px;
  124. line-height: 14px;
  125. color: #555555;
  126. -webkit-border-radius: 4px;
  127. -moz-border-radius: 4px;
  128. border-radius: 4px;
  129. }
  130.  
  131. .function-login .rnr-page {
  132. margin: 50px auto 0 auto;
  133. padding: 0 0 20px 0;
  134. display: block;
  135. }
  136.  
  137. /* width of the login form */
  138.  
  139. .function-login .rnr-c-fields {
  140. width: 350px;
  141. }
  142.  
  143.  

9. One last piece is the "LOG IN" button styling. In this example I have done this using Style Editor. Remember that this is the "Main button" style. Use 'Lato' font, 16px font size, bold if you want to create something similar.

If you done everything right here is how your login page is going to look in Visual Editor.

"Message" area is where "Invalid login" message will appear.

What else would you like to know?

12 thoughts on “Building a nice looking login page with custom CSS

  1. This is a great tutorial!

    What i also would like to see in a tutorial like this is how to change all af the buttons (like Add, Inline Add, Print) to image like buttons. Safe that as a custom style and re-use that style in other projects.

    It would just be simulair to the new menuoptions in PHPRunner 7.

    Thanks for this tutorial Sergey.

  2. Great tutorial and function! This like adding on cosmetic to a beautiful lady.
    In fact, this is exactly what we are looking for. This is especially good before festivals or holidays.

  3. This is really helpful to see both how to change a style and use custom CSS. I applied this to a new app, minus the Facebook login, and it worked well. My image isn’t exactly the way I would like it. Is there a good standard size for an image to use as a background? Thanks for creating this tutorial!

  4. Sandy,

    there is a standard for this sort of thing as end user device screen are different. There are some CSS options you can try though, try removing background-size:cover; for instance.

  5. I tried the tutorial, but my result not same with screenshot above. the black rectacle frame seem overlaping make it not transparant in mine.

  6. When I enter the code it’s not working. the first ligne .fonction…..

    how I can do?

    message: Parse error: syntax error, unexpected ‘*’, expecting function (T_FUNCTION) in C:\wamp\www\RegCanHai\classes\loginpage.php on line 17
    Call Stack
    # Time Memory Function Location

Leave a Reply

Your email address will not be published. Required fields are marked *