为什么媒体查询无法正常工作

问题描述

我正在尝试使用媒体查询来使div响应,但是由于我编写了@media以将flex更改为最大宽度为800px时的50%,所以它并没有改变这种方式,而是在720px以及max-width上工作480像素,更改为432像素。为什么有人有任何想法会发生这种情况?这是html和css代码

<header class="header">
        <h1>RESPONSIVE galLERY</h1>
        <p>Picker,pic of the day...</p>
    </header>
        <div class="row">
            <div class="col">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
            </div>
            <div class="col">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
                <img src="img1.png" alt="">
            </div>
            <div class="col">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
            </div>    
            <div class="col">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
                <img src="img2.png" alt="">
            </div>
        </div>

.css

*{
    Box-sizing: border-Box;
    font-family: 'Alata',sans-serif;
}
/* .header{
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background-color: #f2f2f2;
    font-family: 'Alata',sans-serif;
} */

.header{
    padding: 30px;
    text-align: center;
}

.row{
    display: flex;
    flex-wrap: wrap;
    /* padding: 0 4px; */
}


.col{
    flex:25%;
    /* max-width: 25%; */
    padding-right: 10px;
}

.col img{
    width:100%;
    margin-top: 10px;
    vertical-align: middle;
}

@media (max-width: 800px){
    .col{
        flex:50%;
        max-width:50%;
    }
}

@media (max-width: 480px){
    .col{
        flex:100%;
        max-width:100%;
    }
}

解决方法

您需要在@media查询中添加一些额外的代码,请尝试以下操作:

////these next four class and functions are for exporting  data directly to the Azure SQL database via the spark connectors. 
// the next two functions are for retry purpose. if exporting a table faile,it will retry
def tryNotebookRun (path: String,timeout: Int,parameters: Map[String,String] = Map.empty[String,String]): Try[Any] = {
  Try(
    if (parameters.nonEmpty){
      dbutils.notebook.run(path,timeout,parameters)
    }
    else{
      dbutils.notebook.run(path,timeout)
    }
  )
}

def runWithRetry(path: String,String],maxRetries: Int = 3) = {
  var numRetries = 0
  
  // I want to add a wait period here
  while (numRetries < maxRetries){
    
    tryNotebookRun(path,parameters) match {
      case Success(_) => numRetries = maxRetries
      case Failure(_) => numRetries = numRetries + 1      
    }    
  }
}

case class NotebookData(path: String,String])

def parallelNotebooks(notebooks: Seq[NotebookData]): Future[Seq[Any]] = {

  val numNotebooksInParallel = 5
  // This code limits the number of parallel notebooks.
  implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(numNotebooksInParallel))
  val ctx = dbutils.notebook.getContext()
  
  Future.sequence(
    notebooks.map { notebook => 
      Future {
        dbutils.notebook.setContext(ctx)
        runWithRetry(notebook.path,notebook.timeout,notebook.parameters)
      }
      .recover {
        case NonFatal(e) => s"ERROR: ${e.getMessage}"
      }
    }
  )
}

////create a sequence of tables to be writed out in parallel

val notebooks = Seq(
  
  NotebookData("Export Tables To Database",Map("client"->client,"scope"->scope,"secret"->secret,"schema"->"test","dbTable"->"table1")),NotebookData("Export Tables To Database","dbTable"->"table2"))
)

val res = parallelNotebooks(notebooks)

Await.result(res,3000000 seconds) // this is a blocking call.
res.value

还要检查是否在HTML文件中设置了元视口:

@media screen and (max-width: 800px){
    .col{
        flex:50%;
        max-width:50%;
    }
}

@media screen and (max-width: 480px){
    .col{
        flex:100%;
        max-width:100%;
    }
}