0

So, I am working on two sites, and the padding seems to change tremendously on different screens, I was wondering if this was potentially due to the units I am using? Or the specific CSS tag? However, I am hoping someone can figure it out for me

Two bits of code that keep changing:

codepen

.divider {
  background-color: #3498db;
  padding-top: 5%;
  padding-bottom: 5%;
  font-family: Open Sans;
  font-weight: 300;
  text-align: center;
}
.divider h1 {
  margin-bottom: 10px;
  margin-top: 0%;
  padding-top: 20%;
  font-weight: 500;
  color: white;
}
.divider p {
  color: white;
  margin-bottom: 5px;
  font-family: Open Sans;
  text-align: center;
}
.divider button {
  padding: 10px;
  height: 15%;
  cursor: auto;
  width: 17%;
  margin-top: 30px;
  border-radius: 50px;
  text-align: center;
  color: white;
  border: white 1px solid;
  background-color: #3498db;
}
.divider button:hover {
  background-color: white;
  color: black;
  transition: all 0.3s ease 0s;
}
<div class="divider">
  <h1>See Something You Like?</h1>
  <p>Feel free to contact us at any time and we’ll have someone reply to you 6 as soon as possible.
    <br>industry's standard dummy text ever since the 1500s
    <br>
    <br>Whenever you’re ready, email us with the details you want on your website, and we will
    <br>respond with a rough price.</p>
  <a href="mailto:hello@baseframe.co">
    <button>Email</button>
  </a>
</div>
  • on this, the top padding gets super big (or sometimes it gets smaller) on different screens.

codepen

* {
  margin: 0 auto;
  padding: 0;
}
html {
  height: 100%;
}
body {
  font-family: 'Open Sans';
  font-weight: 400;
  height: 100%;
  background-color: #ddd;
}
.nav {
  background: rgba(0, 0, 0, 0);
  position: absolute;
  width: 100%;
}
.nav ul {
  text-align: right;
  vertical-align: middle;
  margin-right: 15px;
  margin-top: 15px;
  font-size: 1.1em;
}
.nav li {
  padding-top: 5px;
  list-style: none;
  display: inline-block;
  padding: 15px;
}
.nav a {
  margin-top: 17px;
  bottom: 0;
  display: inline-block;
  color: white;
  text-decoration: none;
}
.nav a:hover {
  color: #3498db;
  transition: ease 0.5s all 0s;
}
.nav hr {
  opacity: 0.2;
  width: 95%;
  text-align: center;
}
.nav-logo {
  vertical-align: middle;
  top: 0;
  float: left;
  width: 5%;
  display: inline-block;
}
.nav-logo img {
  width: 250%;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
/*-------------------Home-Page-------------------*/

.home-page {
  background-image: url("http://baseframe.co/getanimus/img/cover1.jpg");
  background-size: cover;
  background-position: top;
  background-attachment: fixed;
  padding-bottom: 17%;
  text-align: center;
}
.home-page h1 {
  color: white;
  padding-top: 15%;
  font-size: 5em;
  text-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
.home-page input {
  cursor: auto;
}
.home-page p {
  font-weight: 300;
  color: white;
  margin-bottom: 15px;
}
button#infl {
  background-color: #3498db;
  color: white;
  font-size: 1em;
  width: 15%;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
  font-family: montserrat;
  padding: 15px;
  margin: 5px;
  border-top-left-radius: 2em;
  border-top-right-radius: 2em;
  border-bottom-left-radius: 2em;
  border-bottom-right-radius: 2em;
  border: none;
  cursor: auto;
}
button#brands {
  background-color: white;
  color: #7f8c8d;
  font-size: 1em;
  width: 15%;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
  font-family: montserrat;
  padding: 15px;
  margin: 5px;
  border-top-left-radius: 2em;
  border-top-right-radius: 2em;
  border-bottom-left-radius: 2em;
  border-bottom-right-radius: 2em;
  border: none;
  cursor: auto;
}
button#brands:hover {
  opacity: 0.8;
  transition: all 0.3s ease 0s;
}
button#infl:hover {
  opacity: 0.8;
  transition: all 0.3s ease 0s;
}
/*-------------------About-------------------*/

.about {
  background-color: white;
  padding-bottom: 10%;
}
.about h1 {
  text-align: left;
  margin-left: 20%;
  margin-top: 5%;
}
.about hr {
  background-color: #3498db;
  height: 5px;
  border: none;
  margin-top: 2%;
  margin-left: 20%;
  width: 5%;
  text-align: left;
  float: left
}
.about p {
  margin-left: 20%;
  margin-right: 20%;
  line-height: 30px;
  margin-top: 5%;
  text-align: left;
}
<div class="nav">
  <ul>
    <li class="nav-logo">
      <img src="http://baseframe.co/getanimus/img/logo_white.png">
    </li>
    <li><a href="#">Home</a></li>
    <li><a href="#">Influencers</a></li>
    <li><a href="#">Brands</a></li>
    <li><a href="#">Contact</a></li>
    <hr>
</div>

<div class="home-page">
  <h1>Animus Digital</h1>
  <p>Premium Talent Management Agency</p>
  <button id="infl">Influencers</button>
  <button id="brands">Brands</button>
</div>
  • this website navigation doesn't align properly with the logo on the left, for some reason. In addition, on a 1920 x 1080 screen, the buttons get pretty wide.

Really appreciate any help on this. Thanks.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Devexted
  • 11
  • 2
  • 7

2 Answers2

0

The reason why the sizes of those elements changes on different screens is because you use % instead of px. % scales the size with the browser's size.

You should use CSS Media queries

TripleDeal
  • 726
  • 4
  • 14
0

For first case since you are using % in padding, which leads to unexpected behavior in different situations.

For "n%" margin (and padding) to be the same for margin-top/margin-right/margin-bottom/margin-left, all four have to be relative to the same base. If top/bottom used a different base than left/right', then "n%" margin (and padding) wouldn't mean the same thing on all four sides.

(Also note having the top/bottom margin relative to the width enables a weird CSS hack that allows you to specify a box with an unchanging aspect ratio ...even if the box is rescaled.) % with margin/padding

Community
  • 1
  • 1
Cyclotron3x3
  • 2,188
  • 23
  • 40