html - 无法在 CSS 文件中获取 @media 查询设置以在适用平台上执行

标签 html css responsive-design

我在我网站的 style.css 文件中编写了我网站桌面版的 CSS 代码。然后,在 css 文件的末尾,我写了

body, html {    /*the outer layer of the site and global style attributes*/
    font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
    margin: 0px;
    height: 100%;
    width: 100%;
    font-size: 100%; /*16px*/
    background-color: #383c5f;
    /*background-image: linear-gradient(#191e4d, white);*/
    display: flex;
    background-repeat: no-repeat;
    background-attachment: fixed;

    }
/*    
* { 
    border: 1px solid red; 
} */

#website {
    width: 100%;   
}

#logo {
    height: 20px;
}


/* NAV BAR */
.nav-bar {
    width: 100%;
    position: fixed;
    display: flex;
    background-color: #232754;
    flex-direction: horizontal;
    justify-content: center;
    z-index: 3;
}

a {
    text-decoration: none;
}

.nav-bar-item {
    margin-right: 20px;
    margin-left: 20px;
    font-family: Lucida Grande, sans-serif;
    color: white;
    font-size: /*1.40vw*/ 1.25em;
    padding-top: 7px;
    padding-bottom: 5px;  
    margin-top: 1.75vh;
}

img {
    height: 100%;
    left: 50%
}


/* Slideshow */
* {
    box-sizing: border-box
}

/* Slideshow container */
.slideshow-container {
    max-width: 100%;
    position: relative;
    margin: auto;
    height: 85%;
    overflow: hidden;
    display: flex;
    align-items: center;
    top: -1.5%;
}

/* Hide the images by default */
.mySlides {
  display: none;
}

/* Next & previous buttons */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 30%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: white;
  font-weight: bold;
  font-size: 1.125em;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
  background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
  color: #f2f2f2;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/4 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 2.5%;
}

/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: #717171;
}

/* Fading animation */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4} 
  to {opacity: 1}
}

/*Content*/

.content {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.title {
    position: absolute;
    left: 16%;
    font-size: /*3em*/ 6vh;
    color: white;
    font-family: Futura, sans-serif;
    text-align: center;
    text-shadow: 8px 8px 10px #000000;
}

/*HOMEPAGE*/

.container {
    width: 80%;
    height: 100%;
    display: flex;
    flex-direction: horizontal;
    align-items: center;
    justify-content: center;
}
.container.home {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: horizontal;
    align-items: center;
    justify-content: center;
}

#name {
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-size: /*8.75em*/ 9.75vw;
    color: white;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -105%);
    text-align: center;
    text-shadow: 8px 8px 10px #000000;
    display: none;
}

#quote {
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    font-size: /*2.5em*/ 2.75vw;
    color:/* #191e4d;*/ white;
    position: absolute;
    top: 70%;
    left: 50%;
    transform: translate(-50%, 0%);
    -webkit-text-stroke: 1px #5d4f4f;
    text-align: center;
    text-shadow: 8px 8px 10px #000000;
    display: none;
}


/*ABOUT*/

.title.about{
    top: 118%;
}

.about-item {
    margin: 30px;
    width: 350px;
    height: 350px;
    display: flex;
    flex-direction: horizontal;
    justify-content: center;
    align-items: center;
}


#kristy-picture{
    position: relative;
    display: flex;
    justify-content: center;
    width: 80% /*20vw*/;
    height: 80% /*20vw*/;
    overflow: hidden;
    border-radius: 100%;
}

#resume-line {
    position: absolute;
    font-size: /*1.5em*/ 3.25vh;
    color: /*#191e4d;*/ white;
    top: 180%;
    font-family: Futura, sans-serif;
    text-align: center;

}

#rlink:link {
    color: white;
}

#rlink:active {
    color: rgb(228, 235, 250);
}
#rlink:visited {
    color: rgb(186, 206, 250);
}

#about-description {
    color: white;
    font-family: Futura, sans-serif;
    font-size: 1.125em;
}

/* PROJECTS */

.title.projects{
    top: 218%;
}

#projects-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    width: inherit;
    height: 65%;
    position: absolute;
    top: 235%;   
    align-items: center;
}

.project {
    cursor: pointer;
    height: 50%;
    width: 35%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    overflow: hidden;
    margin: 5px;
    background: #333454;
    align-items: center;
    /* box-shadow: 4px 4px 4px #000000a8; */
    border-color: white;
}

#byow-img:hover {
    animation: enlarge_photo ease-in 0.5s;
    animation-fill-mode: both;
    animation-iteration-count: 1;
}

#bearmaps-img:hover {
    animation: enlarge_photo ease-in 0.5s;
    animation-fill-mode: both;
    animation-iteration-count: 1;
}


#maps-img:hover {
   /* box-shadow: 8px 8px 8px #000000a8;*/
    animation: enlarge_photo ease-in 0.5s;
    animation-fill-mode: both;
    animation-iteration-count: 1;
}

@keyframes enlarge_photo {
    from {
        width: 85%;
        height: 75%
    }


    to {
        width: 95%;
        height: 85%;
    }
}


.proj-image{
    width: 85%;
    height: 7M5%;
    text-align: center;
    overflow: hidden;
}

.proj-label {
    color: #f2f2f2;
    font-family: Futura, sans-serif;

}

/* EXPERIENCE */
.title.experience{
    top: 318%;
}

#experience-container {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    /* flex-wrap: wrap; */
    width: inherit;
    height: 65%;
    position: absolute;
    top: 330%;
    align-items: center;
}

.expr-item {
    height: 50%;
    width: 100%;
    display: flex;
    flex-direction: horizontal;
    justify-content: center;
    /*overflow: scroll;*/
    margin: 5px;
    align-items: center;
    border-width: 2px;
    background-color: #35395d;
    border-color: #1f2140;
}

#skills {
    /* height: 70%; */
    /* width: 35%; */
    /* border-radius: 30px; */
    border-width: 2px;
    background-color: #35395d;
    border-color: #1f2140;
    color: white;
    font-family: Futura, sans-serif;
    display: flex;
}
/*
#exp-flex {
    height: 65%;
    width: 60%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}*/

.tex sub, .latex sub, .latex sup {
    text-transform: uppercase;
  }

  .tex sub, .latex sub {
    vertical-align: -0.5ex;
    margin-left: -0.1667em;
    margin-right: -0.125em;
  }

  .tex, .latex, .tex sub, .latex sub {
    font-size: 1em;
  }

  .latex sup {
    font-size: 0.85em;
    vertical-align: 0.15em;
    margin-left: -0.36em;
    margin-right: -0.15em;
  }

.textbox {
    width: 75%;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 0.875em;
    color: white;
    font-family: Futura, sans-serif;
}

.exp-image {
    width: 10%;
    height: 75%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* CONTACT ME */

.title.contact{
    top: 418%;
}

#contact-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    width: inherit;
    height: 65%;
    position: absolute;
    top: 430%;
    align-items: center;
}

#contact-line {
    width: 100%;
    text-align: center;
    font-size: 1.5em;
    color: white;
    font-family: Futura, sans-serif;
}

.contact-box-container {
    width: 80%;
    height: 60%;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
}

.contact-box {
    width: 40%;
    height: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    background-color: /*rgb(112, 129, 184)*/ #333454;
    border-color: #1f2140;
    border-width: 2px;
    color: white;
    font-family: Futura, sans-serif;
    text-align: center;

}


/* Popup Box */
#overlay {
    background: rgba(0, 0, 0, 0.7);
    position: absolute;
    height: 500%;
    width: 100%;
    z-index: 2;
    top: 0px;
    left: 0px;
}

#lightbox {
    display: none;
}

#specific-project-container {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 3;
    transform: translate(-50%, -50%);
    background-color: #1e2435;
    height: 82%;
    width: 70%;
    border-color: #1e1e54;
    overflow: hidden;
    border-width: 3px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    overflow: scroll;
}

.picture {
    margin-top: 10px;
    width: 45%;
    height: 50%;
    overflow: hidden;
    text-align: center;

}
.proj-desc {
    margin-bottom: 10px;
    width: 80%;
    /*overflow: scroll; */
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: Futura, sans-serif;

}
/* BOTTOM BAR */

.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    width: 100%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: horizontal;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 40px;


}

.bottom-button {
    width: 25px;
    height: 25px;
    margin-right: 10px;
    margin-left: 10px;
    position: relative;
    display: inline-block; 
    opacity: 0.6;
    z-index: 1;

}

.bottom-button:hover {
    animation: opaque ease-in 0.3s;
    animation-fill-mode: both;
    animation-iteration-count: 1;
   /* opacity: 1;*/
}

@keyframes opaque {
    from { opacity: 0.6; }
    to { opacity: 1}
}

#copyright {
    font-size: 0.75em;
    position: fixed;
    color: /*#191e4d;*/ white;
    margin-bottom: 48px;
    margin-top: 20px;
    z-index: 1;


}

@media only screen and (max-width: 800px) {
    #kristy-picture {
        width: 100%;
        height: 100%;
    }

    #about-description {
        color: white;
        font-family: Futura, sans-serif;
        font-size: 1.5em;
    }

    .project {
        height: 30%;
    }

    .exp-image {
        width: 20%;
        height: 30%;
    }

    .contact-box-container {
        width: 100%;
        height: 40%;
    }

}

@media only screen and (max-height: 520px) {
    .textbox {
        font-size: 0.5em;
    }
}

覆盖任何现有的上述元素的移动显示设置。不过,我不确定为什么当我查看我的网站时这些设置没有显示在我的 iPhone 上。我不应该把@media 放在文件末尾吗?我使用了这个 YouTube 视频 https://www.youtube.com/watch?v=2KL-z9A56SQ了解从桌面到向下的响应式设计。

最佳答案

我刚刚查看了您的网站,您的网页中似乎缺少元标记。 <meta> viewport 元素告诉浏览器页面的尺寸和缩放比例。在您的 <head> 中包含以下标签标记,一切都会按预期工作。

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

可以关注this link了解有关元标记及其在网页上的重要性的更多信息。希望对您有所帮助。

关于html - 无法在 CSS 文件中获取 @media 查询设置以在适用平台上执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56919902/

相关文章:

jquery - Bootstrap 3 - 表单提交到 "_blank"

html - 尝试修复 css 和 html 以协同工作

html - IE 的 CSS 调试工具

javascript - 来自 XML 文件问题的分页 jQuery 结果集

javascript - 用不同的方式创建响应式网站

css - Bootstrap 中的响应式文本框用于超小尺寸(col-xs)不起作用

javascript - 旋转一个 div 但使其内容不会颠倒

html - CSS text-decoration-不设置,但允许一个或多个属性

javascript - 如何使用用 Javascript 编写的现有方法验证我的表单?

html - 防止在特定断点后重置样式