html - 在不同屏幕上查看网站时,某些元素不合适?

标签 html css position

在我的屏幕上一切看起来都不错,但是当我在楼下的电脑上看时,它就完全错位了。我用position absolute定义了position,然后留下一定数量的像素。我怎样才能使它保持水平居中并始终垂直地靠在导航栏上。

我的屏幕:

enter image description here

屏幕楼下:

enter image description here

.nav-main {
  width: 100%;
  background-color: #222;
  height: 70px;
  color: #fff;
  opacity: .65;
}
.nav-main .logo {
  float: left;
  height: 40px;
  padding: 15px 30px;
  font-size: 1.4em;
  line-height: 40px;
}
.nav-main > ul {
  margin: 0;
  padding: 0;
  float: left;
  list-style-type: none;
}
.nav-main > ul > li {
  float: left;
}
.nav-item {
  display: inline-block;
  padding: 15px 20px;
  height: 40px;
  line-height: 40px;
  color: #fff;
  text-decoration: none;
}
.music {
  background-color: white;
  background: rgba(255, 255, 255, 0.6);
  width: 800px;
  min-height: 900px;
  position: absolute;
  left: 524.5px;
  right: 524.5px;
}
.song-1 {
  position: absolute;
  left: 30px;
  float: left;
}
.song-2 {
  float: right;
  position: absolute;
  right: 30px;
}
.music h1 {
  text-align: center;
}
.music h3 {
  text-align: center;
}
<nav class="nav-main">
  <div class="logo">LogicLucas</div>
  <ul>
    <li>
      <a href="about.html" class="nav-item">About</a>
    </li>
    <li>
      <a href="content.html" class="nav-item">Content</a>
    </li>
    <li>
      <a href="music.html" class="nav-item">Music</a>
    </li>
    <li>
      <a href="https://www.youtube.com/channel/UCn63ebEmiYFxhyRVgdCOYtA" class="nav-item">My channel</a>
    </li>
  </ul>
</nav>
<div class="music">
  <h1>Music I used</h1>
  <h3>On this page you can find all the music I used in my skill compilations</h3>
  <div class="song-1">
    <iframe width="350" height="350" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/117698423&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
  </div>
  <div class="song-2">
    <iframe width="350" height="350" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/164076894&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
  </div>
</div>

最佳答案

位置.music相对并替换 leftright属性 margin: 0 auto .

.music {
  background-color: white;
  background: rgba(255, 255, 255, 0.6);
  width: 800px;
  min-height: 900px;
  position: relative;
  margin: 0 auto;
}
.song-1 {
  position: absolute;
  left: 30px;
  float: left;
}
.song-2 {
  float: right;
  position: absolute;
  right: 30px;
}
.music h1 {
  text-align: center;
}
.music h3 {
  text-align: center;
}
<div class="music">
  <h1>Music I used</h1>
  <h3>On this page you can find all the music I used in my skill compilations</h3>
  <div class="song-1">
    <iframe width="350" height="350" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/117698423&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
  </div>
  <div class="song-2">
    <iframe width="350" height="350" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/164076894&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
  </div>
</div>

关于html - 在不同屏幕上查看网站时,某些元素不合适?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27887330/

相关文章:

html - 表溢出父div

弹出对话框中的 JQuery Mobile 滑动页面无法正常工作

CSS position absolute - 下一个定位元素是body?

jquery - 如何创建像这些示例中那样滚动的网站内容?

php - 为 mailto 链接转义字符串的正确方法是什么

javascript - 使用 CSS 选择器在特定属性下查找不包含特定属性的 div

html - NSAttributedString 的最后一行未在 UILabel 中呈现

jquery - .css 文件中的随机背景图像 url

html - 我怎样才能使 :hover area of effect inside the element with the property?

html - 无法移动带边距的文本