为什么我的网页太宽了?

时间:2017-11-24 18:04:41

标签: html css responsive-design

免责声明 :我对编码非常陌生,这是我在本网站上的第一个问题,所以请指出我的礼仪缺乏。此外,关于我的编码的非主题相关指针是 welcome

我正在构建一个投资组合页面并试图让我的页面响应(在图像,文本,填充等上使用 em )。

由于某种原因,页面显示太广(需要向右滚动到中心内容)。有人能指出我正确的方向吗?

我的代码如下:

<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
  <nav>
    <!-- Start of Navigation -->
    <div class="container-fluid">
      <ul>
        <li id="name">Nathan King</li>
        <li><a href="#contact">Contact</a></li>
        <li><a href="#portfolio">Portfolio</a></li>
        <li><a href="#about">About</a></li>
      </ul>
    </div>
  </nav>
  <!-- End of Navigation/Start of Content -->
  <div class="content">
  <div class="about">
    <!-- Start of About -->
    <a id="about"></a>
    <h2>Enter text about my education and skills<h2/><img src="https://preview.ibb.co/i1JZv6/me.jpg" class=".img-responsive">
  </div><!-- End of About/Start of Portfolio -->
  <div class="portfolio" id="portfolio"> 
    <h1>Portfolio</h1>
    <div class="row">
      <div class="photo span4"></div>
      <div class="photo span4"></div>
    </div>
    <div class="row">
      <div class="photo"></div>
      <div class="photo"></div>
    </div>
  </div>
  <!-- End of Portfolio/Start of Contact -->
  <div class="contact">
    <a id="contact"></a>
    <h2>Contact me:</h2>
    <div id="soc-btn">
      <a href="https://www.facebook.com/#" class="fa fa-facebook" target="_blank"></a>
      <a href="https://twitter.com/#" target="_blank" class="fa fa-twitter"></a>
    </div>
  </div>
</body>

CSS

body {
  margin: 0 auto;
  padding: 0;
  background-color: #ccccff;
  width 100%;
}
nav {
  margin: 0 auto;
  padding: 0 auto;
  width: 100%;
}
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #9099a2;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  width: 100%;
}
li {
  display: inline;
  float: right;
}

nav a {
  text-decoration: none;
  font-family: arial;
  display: block;
  padding: 1em 0.5em 1em 0.5em;
  color: white;
  width: 5em;
  text-align: center;
}
nav a:hover {
  opacity: 0.7;
}
nav a.active {
  background-color: #63799d;
  font-weight: bold;
}

#name {
  float: left;
  font-family: arial;
  padding: 1em 0.5em 1em 1em;
  color: white;
}
.content {
  margin: 0 auto;
  padding: 0 auto;
  width: 100%;
}

.about {
  padding: 4em 2em 2em 2em;
  margin: 0 auto;
  background-color: #6d7993;
  width: 100%;
}

.about h2 {
  text-align: center;
  color: #d5d5d5;
}
.about img {
  height: 9em;
  width: 9em;
  border-radius: 50%;
  margin-top: 1em;
}

h1,
h2,
p {
  font-family: calibri;
}

.portfolio {
  padding: 4em 2em 4em 2em;
  margin: 0 auto;
  background-color: #d5d5d5;
  text-align: center;
  height: 100%;
  width: 100%;
}
.portfolio h1 {
  color: Black;
}

.photo {
  width: 10em;
  height: 5em;
  background-color: #6d7993;
  padding: 4em;
  margin: 4em;
  display: inline-block;
  border-radius: 1em 4em 1em 4em / 2em 1em 2em 1em;
  -moz-border-radius: 1em 4em 1em 4em / 2em 1em 2em 1em;
  -webkit-border-radius: 1em 4em 1em 4em / 2em 1em 2em 1em;
}

.contact {
  padding: 4em 2em 4em 2em;
  background-color: #96858f;
  color: #d5d5d5;
  height: 100%;
  width: 100%;
  text-align: center;
}

.soc-btn {
  margin: 0 auto;
}

.fa {
  padding: 20px;
  font-size: 30px;
  width: 30px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
  border-radius: 50%;
}

.fa:hover {
  opacity: 0.7;
}

.fa-facebook {
  background: #3b5998;
  color: white;
}

.fa-twitter {
  background: #55acee;
  color: white;
}

1 个答案:

答案 0 :(得分:2)

你需要一个:

* {
  box-sizing: border-box
}

这对于响应式设计至关重要,因为它告诉网页在元素的总宽度和高度中包含填充和边框。如果你添加它,你的页面显示正常。

这篇文章在线here,非常好地解释了这一点。

在此处查看您的网页:https://jsfiddle.net/tfr8f8az/

*定位所有元素。