如何使页面展开以适应屏幕?

时间:2016-11-17 22:31:54

标签: html css

注意页面如何居中。如何使其扩展以适应屏幕,包括列?对不起,我是编码的新手。我包含了大部分代码,因为我不知道在哪里可以找到它。希望你们中的一个可以提供帮助。我假设它必须在正文或主页上?Notice how everything is in the middle.

/* Base styles */
*, input[type=search] {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  background-color: $color_2;
}

body {
  color: $color_4;
  font-family: $font_1;
  font-size: 13px;
  font-weight: lighter;
  line-height: 1.5;
  margin: 0;
  margin-left: 0px;
  padding-bottom: 100px;
}

img {
  max-width: 100%;
  vertical-align: middle;
}

img[width], img[height] {
  max-width: none;
}

figure > img {
  display: block;
}

a {
  color: $color_5;
  font-family: $font_2;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

ul, ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

table {
  border-collapse: collapse;
  text-align: left;
  width: 100%;
}
[dir="rtl"] table {
  text-align: right;
}

td, th {
  border-color: #eeeeee;
  border-style: solid;
  padding: 18px;
}

th {
  border-width: 1px 0;
  color: #bebebe;
  font-size: 11px;
  font-weight: normal;
  white-space: nowrap;
}

td {
  border-width: 0 0 1px 0;
}

h1, h2, h3, h4, h5, h6 {
  color: black;
  font-weight: 400;
}

h1 {
  font-size: 20px;
}

input, label {
  display: inline-block;
  vertical-align: middle;
}

label {
  font-size: 12px;
}

input[type="checkbox"] + label {
  margin-left: 5px;
}

input, textarea {
  border: 1px solid #dddddd;
  border-radius: 2px;
  padding: 10px;
}

textarea {
  height: 100px;
  padding: 7px 10px;
  resize: vertical;
}

textarea, input[type=text] {
  width: 100%;
}

input, textarea, select {
  color: #555;
}

input::-ms-clear {
  display: none;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

::-webkit-input-placeholder {
  color: #cccccc;
}

:-ms-input-placeholder {
  color: #cccccc;
}

::-moz-placeholder {
  color: #cccccc;
}

/* Buttons */
button, [role=button], [type=button], [type=submit] {
  border-radius: 4px;
  border: 1px solid #dddddd;
  color: $color_5;
  cursor: pointer;
  display: inline-block;
  padding: 5px 10px;
  position: relative;
  vertical-align: middle;
  white-space: nowrap;
}

a[role=button]:hover {
  text-decoration: none;
}

input[type=submit] {
  background: #444;
  border-color: transparent;
  color: #FFF;
  padding: 10px 30px;
}

input[type=submit][disabled] {
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";
  /* IE 8 */
  opacity: 0.4;
}

button img, [role=button] img {
  border-radius: 4px;
  margin: 0 5px 0 0;
  height: 20px;
  position: relative;
  top: -1px;
  vertical-align: middle;
}
[dir="rtl"] button img, [dir="rtl"] [role=button] img {
  margin: 0 0 0 5px;
}

/* Forms */
.form {
  max-width: 505px;
}

.form-field + .form-field {
  margin-top: 25px;
}

.form-field label {
  display: block;
  font-weight: bold;
  margin-bottom: 5px;
}

.form-field input[type=checkbox] + label {
  margin: 0 0 0 10px;
}

.form-field.required > label:after {
  content: "*";
  color: red;
  margin-left: 2px;
}

.form-field p {
  color: #bebebe;
  font-size: 11px;
}

.form-field input[type=number], .form-field input.datepicker {
  width: 150px;
}

.form form + form, .searchbox {
  margin-top: 25px;
}

.searchbox-suggestions {
  background-color: #fff;
  border: 1px solid #eeeeee;
  border-radius: 4px;
  padding: 10px 20px;
}

.searchbox-suggestions li {
  padding: 5px 0;
}

[data-loading="true"] input,
[data-loading="true"] textarea {
  background: transparent url(/hc/assets/loader.gif) 99% 50% no-repeat;
  background-size: 16px 16px;
}

.form footer {
  border-top: 1px solid #eeeeee;
  margin-top: 40px;
  padding-top: 30px;
  text-align: right;
}

.form footer a {
  color: #cccccc;
  cursor: pointer;
  margin-right: 15px;
}

/* Navigation menus */
.nav li, .nav-bordered li, .nav-spaced li {
  display: inline-block;
  font-weight: bold;
}

.nav li a, .nav-bordered li a, .nav-spaced li a {
  font-weight: normal;
}

.nav-bordered li + li {
  border-color: #eeeeee;
  border-style: solid;
  border-width: 0 0 0 1px;
  margin: 0 0 0 30px;
  padding: 0 0 0 30px;
}

[dir="rtl"] .nav-bordered li + li {
  border-width: 0 1px 0 0;
  margin: 0 30px 0 0;
  padding: 0 30px 0 0;
}

.nav-spaced li + li {
  margin: 0 0 0 40px;
}

[dir=rtl] .nav-spaced li + li {
  margin: 0 40px 0 0;
}

/* Search box */
.search-box, .sub-nav .search {
  position: relative;
}

.search-box:before, .sub-nav .search:before {
  content: "\1F50D";
  font-family: "entypo";
  font-size: 1.25em;
  line-height: 0;
  position: absolute;
  text-align: center;
  top: 50%;
  width: 2.5em;
  z-index: 1;
}

.search-box input, .sub-nav .search input {
  line-height: 1.2em;
  font-weight: lighter;
  padding: .75em 2.7em;
  width: 100%;
  -webkit-appearance: none;
}

.search-box input[type="submit"], .sub-nav .search input[type="submit"] {
  display: none;
}

/* Breadcrumbs */
.breadcrumbs li {
  color: #bebebe;
  display: inline-block;
  font-size: 12px;
}
.breadcrumbs li + li:before {
  content: ">";
  margin: 0 4px;
}
.breadcrumbs li a {
  color: $color_4;
}

/* Labels */
.label, .request-status {
  border-radius: 20px;
  display: inline-block;
  font-size: 10px;
  padding: 3px 10px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Metadata */
.meta, .meta-group {
  color: #cccccc;
  display: inline-block;
  font-size: 11px;
}

.meta-group * + *:before {
  content: "\2022";
  font-size: 8px;
  margin: 0 10px;
}

/* Helper classes */
.clearfix:before, .clearfix:after {
  content: " ";
  display: table;
}

.clearfix:after {
  clear: both;
}

/* Social share links */
.share {
  white-space: nowrap;
}

.share li, .share a {
  display: inline-block;
}

.share a {
  height: 30px;
  line-height: 30px;
  overflow: hidden;
  vertical-align: middle;
  width: 30px;
}

.share a:before {
  background: #CCC;
  border-radius: 50%;
  color: #FFF;
  display: inline-block;
  font-family: "entypo";
  text-align: center;
  width: 100%;
}

.share a:hover {
  text-decoration: none;
}

.share-twitter:before {
  content: "\F309";
}

.share-facebook:before {
  content: "\F30C";
}

.share-linkedin:before {
  content: "\F318";
}

.share-googleplus:before {
  content: "\F30F";
}

/* Pagination */
.pagination {
  margin: 20px 0;
  text-align: center;
}

.pagination * {
  display: inline-block;
}

.pagination li {
  border: 1px solid #eeeeee;
  float: left;
  margin-left: -1px;
}
[dir="rtl"] .pagination li {
  float: right;
}

.pagination a, .pagination span {
  color: inherit;
  font-size: 12px;
  padding: 5px 12px;
}

.pagination-current {
  background-color: #f9f9f9;
  color: #bebebe;
}

.pagination-first {
  border-radius: 3px 0 0 3px;
}
[dir="rtl"] .pagination-first {
  border-radius: 0 3px 3px 0;
}

.pagination-last {
  border-radius: 0 3px 3px 0;
}
[dir="rtl"] .pagination-last {
  border-radius: 3px 0 0 3px;
}

/* Markdown styles */
.markdown {
  word-wrap: break-word;
  line-height: 1.7;
}
.markdown img {
  max-width: 70%;
}
.markdown hr {
  background-color: #eeeeee;
  border: 0;
  height: 1px;
}
.markdown ul, .markdown ol {
  list-style-position: inside;
  padding: 0 15px;
}
.markdown ul {
  list-style-type: disc;
}
.markdown ol {
  list-style-type: decimal;
}
.markdown pre {
  background: #f9f9f9;
  border: 1px solid #eeeeee;
  border-radius: 3px;
  padding: 10px 15px;
  overflow: auto;
  white-space: pre;
}
.markdown blockquote {
  border-left: 1px solid #eeeeee;
  color: #bebebe;
  font-style: italic;
  padding: 0 15px;
}

/* Frame */
main, .header-inner, .footer-inner {
  margin: 0 auto;
  padding: 20 20px;
  width: 500px;
}

/* Columns */
.main-column, .side-column {
  display: inline-block;
  vertical-align: top;
}

.main-column {
  width: 620px;
}

.side-column {
  width: 270px;
  margin-left: 45px;
}
[dir=rtl] .side-column {
  margin-left: 0;
  margin-right: 45px;
}

/* Header */
.header {
  background: $color_1;
  border-bottom: 1px solid #eeeeee;
}

.header-inner {
  display: table;
  height: 100px;
}

.logo, .user-nav {
  display: table-cell;
  vertical-align: middle;
}
.logoHD, .user-navHD {
  display: table-cell;
    position: left;
  left: 80px;
  vertical-align: middle;
}

.logo img {
  max-height: 60px;
}

.logoHD img {
  max-height: 60px;

}

.user-nav {
  text-align: right;
}

.user-navHD {
  left: center;
}
.user-nav > * {
  display: inline-block;
  margin: 0 0 0 25px;
}
.user-navHD > * {
  display: inline-block;
  margin: 0 0 0 25px;
}
[dir=rtl] .user-nav {
  text-align: left;
}
[dir=rtl] .user-nav > * {
  margin: 0 25px 0 0;
}

/* Home page */
.hero-unit {
  display: block;
  font-size: 22px;
  padding: 80px 60px;
}

body.community-enabled .knowledge-base, body.community-enabled .community {
  display: inline-block;
  vertical-align: top;
}
body.community-enabled .knowledge-base {
  width: 620px;
}

.knowledge-base, .community {
  display: inline-block;
  vertical-align: top;
}

.knowledge-base {
  width: 100%;
}

4 个答案:

答案 0 :(得分:3)

您必须使用百分比或使用媒体查询等内容来设置内容的特定宽度。百分比的一个例子是:

main, .header-inner, .footer-inner {
  margin: 0 auto;
  width: 90%;
}

答案 1 :(得分:3)

更改

.side-column {
  width: 270px;
  margin-left: 45px;
}

.main-column {
  width: 620px;
 }

.side-column {
  width: 0px;
  margin-left: 0px;
}

.main-column {
  width: 100%;
 }

答案 2 :(得分:3)

您的主要设置为500px宽度。您需要删除该宽度样式。然后main将占据它的父容器的整个宽度。

这背后的原理是块级元素默认占用它的父容器的整个宽度。由于main是块级元素,因此您不必设置100%;它自动默认为100%。

顺便说一下,你的主要填充样式是畸形的。你有填充:20 20px;你需要使用单位,而不仅仅是数字。所以要么写填充:20px 20px;甚至更好的只是填充:20px;

答案 3 :(得分:1)

您似乎在CSS中使用固定大小。例如,下面的行:

.main-column {
  width: 620px;
}

.side-column {
  width: 270px;
  margin-left: 45px;
}

正在分配固定的width值。 (修正后,我的意思是使用pxmmin等单位。相反,使用相对大小(,通常为百分比)是合适的。对于较大的包含元素,我倾向于使用vw(视口宽度)和vh(视口高度)的单位。在适当的情况下在CSS中做同样的事也应该有帮如果您选择稍后使用CSS媒体查询,这也可以更轻松地优化其他设备大小。