首页 > 解决方案 > CSS 使用媒体查询改变位置

问题描述

嗨,可以请人帮助我,我正在打破我的大脑,试图将 div 的位置从绝对更改为static(default)我需要当页面缩小到800px高于div(absolute)另一个时,div(relative)将他的位置更改为堆栈下方,div(relative)但问题是我无法更改某些代码,因为我展示了一张幻灯片,而这张幻灯片保留了一张aspect ratio 16:9图片,这就是为什么我使用 atop-padding 52.5来始终保持这个纵横比,而图片保持他的原始外观我只需要上面有文字的潜水图片堆叠在图片结束的右下方或图片的 div 结束的地方

*{
  margin:0;
  padding:0;
}
.navi{
  background:yellow;
  width:100%;
  height:100px;
  margin-bottom:20px;
}
.jumbo{
  background:grey;
  width:100%;
  height:500px;
  margin-top:20px;
}


.slideshow{
  background:green;
  width:100%;


}
.slide-image-wrap{
  width:100%;


  box-sizing: border-box;


}
.mySlides {

  width: 100%;
  overflow: hidden;


  }

img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;


}
#tata .slide-image-wrap .mySlides{

  position: relative;
  height:0;
  padding-top: 56.25%;

}

#tata img{

  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}


.slide-text-wrap{
  height: 100px;
  width:500px;
  background:blue;
  position: absolute;

  bottom:20%;
  right: 6%;
  color:orange;
  font-size: 2em;
}

.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  color: white;
  font-weight: bolder;
  font-size: 2em;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;

}

/* 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(255,0,0,0.8);
}


/* The dots/bullets/indicators */
.dot {
  cursor: pointer;
  height: 10px;
  width: 20px;
  margin: 0 10px;
  background-color: #bbb;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: right:   ;
}
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}




@media only screen and (orientation: portrait) {




}

@media only screen and (max-width: 800px){
  .slide-text-wrap{
  background-color: yellow;
  top: 0;
  right: 0;
  bottom:0%;
  left: 0;
  margin: auto auto 0 auto;
  width: 450px;
}


}

标签: htmlcssposition

解决方案


对于响应式媒体查询(当屏幕最大小于 800px 时有效

@media (max-width: 800px){
     .yourClassName{
       //style goes here
     }
}

访问以引用 css flex 框https://www.youtube.com/watch?v=0e02dl66PYo


推荐阅读