html - 如何使尺寸在所有屏幕上看起来都一样

标签 html css alignment

所以,我在两个站点上工作,并且填充在不同的屏幕上似乎发生了巨大变化,我想知道这是否可能是由于我使用的单位造成的?还是具体的CSS标签?不过,我希望有人能帮我解决这个问题

不断变化的两段代码:

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>

  • 在此基础上,顶部内边距在不同屏幕上变得非常大(有时会变小)。

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>

  • 由于某种原因,此网站导航与左侧的 Logo 没有正确对齐。此外,在 1920 x 1080 的屏幕上,按钮变得非常宽。

非常感谢对此的任何帮助。谢谢。

最佳答案

这些元素的大小在不同屏幕上变化的原因是因为您使用 % 而不是 px。 % 根据浏览器的大小缩放大小。

你应该使用 CSS Media queries

关于html - 如何使尺寸在所有屏幕上看起来都一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39689014/

相关文章:

html - 如何水平对齐一系列 HTML 链接?

html - 需要帮助使用 CSS/HTML 对齐 3 个图像

html - 如何对齐容器边框的文本

html - 子div不填充父

javascript - 图像输入按钮时提交的 HTML javascript 表单

javascript - 文本框内的分隔符

css - 在容器中居中放置 2 个 div(向左、向右浮动)

html - 行分隔符,但带有 float text-left

html - 将样式更改为 html 表中的标题

css - Google Fonts - 可变字体在 Windows 浏览器中不起作用