Flexbox CSS对齐属性是否属于惰性?

Flexbox CSS对齐属性是否属于惰性?

问题描述:

I was working on a project which contained a search box which echoed a neatly formatted string of images with the correct queries from my database. Somewhere in the maze of using Flexbox CSS, however, I managed to end up with: A it escaping my screen and B the s for each item not having spaces above and below each other :(

Here's my code for this part:

<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>

And here's the CSS as requested:

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

Just to clarify, this does work and my database echoes my test values correctly but unfortunately hours of efforts trying to hack through a wall of complex CSS have been fruitless.

Here's a screenshot: enter image description here

Any suggestions?

Thank you,

i moved your inline css to external and addes a class .searchitems to the flexitems.
you can move it back in if you want

.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>

is this ok ?

it is escaping your screen because of the width:100vw;
I added a margin-top:10px; to the .searchitems and added a negative margin-top:-10px; to the .searchresults, so the margin is only added to the wrapped .seachitems

</div>