如何修复CSS以做出响应式布局?

瑞典人:

希望您能帮我CSS吗?我设计了带有左侧导航的页面,该页面在全屏上看起来不错,但是,当我将其调整为移动尺寸时,我的主要内容停留在一列中,并且没有填满整个视口-在左侧留有相当大的空间...有人知道我的CSS有什么问题吗?我相信媒体查询会有所帮助。这是一个链接:https : //codepen.io/sweexee/pen/abvqyOY让我知道您是否可以看到它和CSS:

/* Typography imported from Google Fonts */

header {
  font-family: "Taviraj", serif;
  color: #257ecc;
}

p,
a {
  font-family: Taviraj, serif;
}

/*Generic styles*/

html {
  scroll-behavior: smooth;
}

html,
body {
  min-width: 290px;
  background-color: #ffffff;
  line-height: 1.5;
}

body {
  margin: 8px;
  display: block;
}

a {
  background-color: #257ecc;
  text-decoration: none;
  color: white;
  text-align: center;
  display: inline-block;
  transition: all 0.3s;
}

a:hover {
  opacity: 0.8;
  color: #cc4d47;
}

p {
  font-weight: 300;
  font-size: 1.2rem;
}

blockquote {
  border-left: 10px solid #257ecc;
  margin: 1.5em 10px;
  padding: 0.5em 10px;
}

blockquote:before {
  color: #257ecc;
  content: open-quote;
  font-size: 4em;
  line-height: 0.1em;
  margin-right: 0.25em;
  vertical-align: -0.4em;
}

blockquote p {
  display: inline;
  font-weight: 400;
  font-style: italic;
  font-size: 1.5rem;
  color: #cc4d47;
}

ul {
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  padding-inline-start: 40px;
}

li {
  display: list-item;
}

/* Navigation styles*/
nav {
  display: block;
}

#navbar {
  position: fixed;
  min-width: 290px;
  top: 0px;
  left: 0px;
  width: 300px;
  height: 100%;
  background-color: #257ecc;
  border-right: solid;
  border-color: #828e99;
}

@media only screen and (max-width: 815px) {
  #navbar {
    max-height: 275px;
    border: none;
    border-bottom: 2px solid;
    position: absolute;
    width: 100%;
    z-index: 1;
    top: 0;
    padding: 0;
    margin: 0;
  }
}
nav > header {
  color: #ffffff;
  margin: 10px;
  text-align: center;
  font-size: 1.9rem;
  font-weight: 600;
  display: block;
}

#navbar ul {
  padding: 0;
  height: 80%;
  overflow-y: auto;
  overflow-x: hidden;
}

@media only screen and (max-width: 815px) {
  #navbar ul {
    border: 1px solid;
    height: 207px;
  }
}

#navbar ul > li {
  color: #ffffff;
  border-top: 1px solid;
  border-color: #cc4d47;
  list-style: none;
  position: relative;
  width: 100%;
}

#navbar a {
  display: block;
  padding: 12px 30px;
  text-decoration: none;
  cursor: pointer;
  font-size: 1.1rem;
  font-family: "Roboto", sans-serif;
  font-weight: 300;
}

/*Main ccontent styles*/

main {
  display: block;
}

#main-doc {
  position: absolute;
  margin-left: 310px;
  padding: 20px;
  margin-bottom: 110px;
}

@media only screen and (max-width: 400px) {
  #main-doc {
    margin-left: -10px;
  }
}

@media only screen and (max-width: 815px) {
  #main-doc {
    position: relative;
    margin-top: 270px;
  }
}

/* Section styling*/

section {
  display: block;
}

#main-doc header {
  display: block;
  font-size: 1.6rem;
  font-weight: 600;
  text-align: left;
  margin: 0px;
  padding-top: 10px;
}

section article {
  color: #3d4247;
  margin: 15px;
}
article {
  display: block;
}

section article > p {
  display: block;
}

section article > img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-left: auto;
  margin-right: auto;
  margin-top: 20px;
}

section article > ul {
  list-style: none;
}

section article > ul li::before {
  content: "\2022";
  color: #257ecc;
  font-weight: bold;
  display: inline-block;
  width: 1em;
  margin-left: -1em;
}

section article > ul > li {
  font-family: "Taviraj", sans-serif;
  font-size: 1.2rem;
  font-weight: 300;
  color: #3d4247;
}

section article > ul > li > a {
  color: #257ecc;
  background-color: #ffffff;
}
拉克什塔·马都山:

左增加空白:0; #main-doc@media only屏幕中,并且(最大宽度:815px)宽度的媒体查询如下

左边缘反射:310px;#main-doc即使在内容的移动宽度处也向右移动。

@media only screen and (max-width: 815px)
#main-doc {
    position: relative;
    margin-left: 0;    /* *** add this *** */
    margin-top: 270px;
}

在此处输入图片说明 添加后,您的网站的移动宽度将如下所示

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章