Make a screen responsive to monitor resolution

Asked

Viewed 434 times

0

Good morning!

I have a login screen, I’m doing with bootstrap 4.

How I would adjust the layout of the page so that the background image is not missing or exploded.

As you can see in the image below, on monitors of 1440 x 1032 it is missing a bottom of the background image

Monitores 1440 x 1032

<link rel="stylesheet" href="theme.css" type="text/css">
<div class="py-5" style="background-image: url('../Content/img/cover-stripes.svg'); background-position:left center; background-size: cover;">
<div class="container">
    <div class="row">
        <div class="p-5 col-lg-6">

            @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                <h4>Efetuar login.</h4>
                <hr />
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            @Html.CheckBoxFor(m => m.RememberMe)
                            @Html.LabelFor(m => m.RememberMe)
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Entrar" class="btn btn-default" />
                    </div>
                </div>

            }
        </div>
    </div>
</div>

SASS

$enable-rounded:            true !default;
$enable-shadows:            true;
$enable-transitions:        true;
$enable-hover-media-query:  false;
$enable-grid-classes:       true;
$enable-print-styles:       true;

// Variables
//
// Colors

$theme-colors: (
  primary: #12bbad,
  secondary: #4f70ce,
  light: #f3f3f3,
  dark: #151515,
  info: #ccc,
  success: #28a745,
  warning: #ffc107,
  danger: #dc3545
);

$body-bg: white;
$body-color: #333;


$body-color-inverse: invert($body-color) !default;
$link-color: #12bbad;

// Fonts
$font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
$headings-font-family: $font-family-base;
$display-font-family: $font-family-base;
$font-weight-normal: 200;
$headings-font-weight: 200;
$lead-font-size:   1.30rem;

$spacer: 1.5rem;

@import 'bootstrap-4.1.3';


html,body {
   height:100%;
}

.cover {
    min-height:100%;
  display:flex;
  align-items:center
}


.bg-gradient {
  overflow: hidden;
  color: color-yiq(map-get($theme-colors, 'primary'));
  background: linear-gradient(-30deg, theme-color("secondary") 0%, theme-color("primary") 50%, theme-color("primary") 100%);
}

.filter-dark {
  overflow: hidden;
  position: relative;
  color: color-yiq(map-get($theme-colors, 'dark'));
    &:before {
    position: absolute;
    top:0px;
    left:0px;
    width:100%;
    height: 100%;
    content: ' ';
    background: rgba(map-get($theme-colors, 'dark'), 0.75);
  }
}

.filter-light {
  overflow: hidden;
  position: relative;
  color: color-yiq(map-get($theme-colors, 'light'));
    &:before {
    position: fixed;
    top:0px;
    left:0px;
    width:100%;
    height: 100%;
    content: ' ';
    background: rgba(map-get($theme-colors, 'light'),0.75);
  }
}

.filter-color {
  overflow: hidden;
  position: relative;
  color: color-yiq(map-get($theme-colors, 'primary'));
    &:before {
    position: absolute;
    top:0px;
    left:0px;
    width:100%;
    height: 100%;
    content: ' ';
    background: rgba(map-get($theme-colors, 'primary'), 0.75);
  }
}

.filter-gradient {
  overflow: hidden;
  position: relative;
  color: color-yiq(map-get($theme-colors, 'primary'));
    &:before {
    position: absolute;
    top:0px;
    left:0px;
    width:100%;
    height: 100%;
    content: ' ';
    background: linear-gradient(-30deg, transparentize(theme-color("secondary"), 0.1) 0%, transparentize(theme-color("primary"), 0.1) 50%, transparentize(theme-color("primary"), 0.05) 100%);
  }
}

.filter-fade-in {
  overflow: hidden;
  position: relative;
  &:before {
    position: absolute;
    top:0px;
    left:0px;
    width:100%;
    height: 100%;
    content: ' ';
    background: linear-gradient($body-bg, transparentize($body-bg, 0.2),transparentize($body-bg, 0.9),transparentize($body-bg, 1));
    }
}

2 answers

1

If your problem is just like the background of a login page you can use the direct background on body, and uses the properties background-size and background-position to adjust the image, in the case of the example I did I aligned the image pasted in the bottom vertically and horizontally centered background-position: bottom center and for the background will occupy the correct size use background-size: cover

OBS: Here in the snippet it doesn’t get very good pq it doesn’t have enough height and has to make the treatment responsive, but display under "Whole page" that you will see better how it is getting. I tried to use a similar image for you to have an idea of how it will look.

html, body {
  height: 100%;
}
  body {
    background-image: url(https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX27495652.jpg);
    background-size: cover;
    background-position: bottom center;
    background-repeat: no-repeat;
  }
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />


<div class="container">
  <div class="row">
    <div class="col-md-6 p-5">
      <form>
          <div class="form-group">
            <label for="exampleInputEmail1">Email address</label>
            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
          </div>
          <div class="form-check">
            <input type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label" for="exampleCheck1">Check me out</label>
          </div>
          <button type="submit" class="btn btn-primary">Submit</button>
      </form>
    </div>
  </div>
</div>

  • Opa! , vlw once again. Taking advantage, if I wanted to put an image on top of the form, would I have any way to leave it fixed in the center? I tried it with code below, just messing with the margim-left, but in this case, of course it will break when you change the resolution, would you have any hints? <div class="p-5 col-lg-6"> <img src="~/Content/img/br_negative.png" style="height:100px" /> </div>

  • @Jhensen face in the background-size vc puts the image size like 500px 300px, and in the background-position vc puts center, so a background image will be centered in the middle of the screen. Or you want the image to be really over the form leaving it covered under the image?

  • The background is solved. Only I decided to put a logo on the login form. Above the "Log in", then I wanted to center this right above this form. I already inserted the image and such, but I just could not align to the center of the form.

  • @Jhensen has now become easier to understand. I saw that you posted a new question, that would be correct even not to mess this etc. I’ll see if I answer you there

  • @Jhensen answered you there in the other question

0


One of the viable and very simple solutions, instead of adding the background in a style, you could create a class as in the example below:

In the example below instead of using the "background-image" I used the "background" and added the no-repeat and aligned the image in the center, to work correctly applied the "position: Absolute;"

.py-5 {
    background: url('https://i.imgur.com/lUGkKdy.png') no-repeat center center;
    -webkit-background-size: cover; /* Safari and Chrome */
    -moz-background-size: cover;  /* Firefox */
    -o-background-size: cover; /* Opera */
    background-size: cover;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
}
<div class="py-5">
<div class="container">
    <div class="row">
        <div class="p-5 col-lg-6">

            @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                <h4>Efetuar login.</h4>
                <hr />
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            @Html.CheckBoxFor(m => m.RememberMe)
                            @Html.LabelFor(m => m.RememberMe)
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Entrar" class="btn btn-default" />
                    </div>
                </div>

            }
        </div>
    </div>
</div>

  • Oops! , Thanks for the help buddy! Taking advantage, if I wanted to put an image on top of the form, would I have any way to leave it fixed in the center? I tried it with code below, just messing with the margim-left, but in this case, of course it will break when you change the resolution, would you have any hints? <div class="p-5 col-lg-6"> <img src="~/Content/img/br_negative.png" style="height:100px" /> </div>

  • in case you want to add a logo above the form?

  • this, above H4. I have already inserted it, but only not centered. Oh my doubt is if you have a correct way to center this image. I know it has some forms, but what would be the ideal? that my doubt

  • There are numerous ways to leave the way you want, but there is no way I can help you without more information about the code, I recommend you open another question and provide more information on the page and leaves the code a little cleaner for better understanding, with the top code until you can help, but at the time you apply in the model can conflict with other classes.

  • Blz, I made a new post to make it clearer. https://answall.com/questions/344270/alinr-logo-no-centro-do-form

Browser other questions tagged

You are not signed in. Login or sign up in order to post.