flexbox css对齐属性是否间接无效?

wooyq4lh  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(339)

我当时正在做一个项目,其中包含一个搜索框,该搜索框用数据库中正确的查询来回响一个格式整齐的图像字符串。然而,在使用flexbox css的迷宫中,我成功地结束了:a它逃离了我的屏幕,b每个项目的s没有上下空格:(
这是我的代码:

<div id= "searchresults" style="width: 100vw; padding-bottom: 3vh; padding-top: 3vh; min-height: 10vh; height: auto; background-color:  #e7e7e7 ; display: flex; flex-wrap: wrap; align-content: space-between; justify-content: space-between;">
<?php
//Makes connection
include 'dxbase.php';
$conn = new mysqli($servername, $username, $password, $dbname);

if(isset($_POST["search"])){
$tempvardf = '%'.$_POST['search'].'%'; #############
//Defines SQL command to bring up data about the products matching the set search
$sql = "SELECT id, name, price, location, path FROM products WHERE name LIKE ?;"; #'%$_POST[search]%'
//Create a prepared statement
$stmt = mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
    echo "SQL STATEMENT FAILED... OOF";
} else {
    //Bind paramaters to placeholder
    mysqli_stmt_bind_param($stmt, "s", $tempvardf);
    //Run paramaters inside database
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);

    while ($row = mysqli_fetch_assoc($result)) {
        echo  "<div style='background-color: blue; padding: 1vw; width: 30vw; display: flex; flex-direction: column; align-content: space-between;'>";

        if(isset($row['path'])){
        echo "<img style='width: 28vw; height: 28vw; ' src=". $row['path'].">". "<br>";

        } else {
            echo "can't access image path";
        }
        echo $row['name']."<br>";
        echo "<s><i>".$row['price']."</i></s><br>"; #CHANGE THIS ONE TO ORIGINAL NONDISCOUNTED PRICE
        echo $row['price']."<br>";
        echo "</div>";
    }
    #echo "And that's it!";
}

} else {

}

?>
</div>

以下是所要求的css:

body {
    font-family: "Lato", sans-serif;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #111;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;

}

.sidebar {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #818181;
    display: block;
    transition: 0.3s;
    white-space: nowrap;

}

.sidebar:hover {
    color: #f1f1f1;
}

.closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidebar {font-size: 18px;}
}

.spacedfont {
    letter-spacing:3px;
}

.headera {
  overflow: hidden;
  background-color: #111;
  padding: 10px 10px;
  height: 15vh;
}

* {box-sizing: border-box}

body {margin:0; padding: 0;}
.mySlides {display: none}
img {vertical-align: middle;}

/* Slideshow container */
.slideshow-container {
  position: relative;
  margin: none;
}

/* Next & previous buttons */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 16px;
  margin-top: -22px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  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(0,0,0,0.8);
}

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

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

/* 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}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .prev, .next,.text {font-size: 11px}
}

只是澄清一下,这确实有效,而且我的数据库正确地响应了我的测试值,但不幸的是,数小时的努力试图破解一堵复杂的css墙却毫无结果。
以下是截图:

有什么建议吗?
谢谢您,

z2acfund

z2acfund1#

我把你的内联css移到了外部并添加了一个类 .searchitems 去弹性体。
如果你想的话可以搬回去

.searchitems{
  background-color: blue; 
  padding: 1vw; 
  width: 30vw; 

  display: flex; 
  flex-direction: column; 
  align-content: space-between;

  margin-top: 10px;

}
.searchresults{
  margin-top: -10px;
  min-height: 10vh; 

  background-color:  #e7e7e7 ; 

  display: flex; 
  flex-wrap: wrap; 
  justify-content: space-between;
}
<div class= "searchresults" >
  <div class="searchitems"></div>
  <div class="searchitems"></div>
  <div class="searchitems"></div>
  <div class="searchitems"></div> 
</div>

这样可以吗?
它正在逃离你的屏幕,因为 width:100vw; 我加了一个 margin-top:10px;.searchitems 加了一个负片 margin-top:-10px;.searchresults ,因此边距仅添加到 .seachitems

相关问题