gpt4 book ai didi

php - Flexbox CSS 对齐属性在某些情况下是惰性的?

转载 作者:行者123 更新时间:2023-11-28 00:55:42 25 4
gpt4 key购买 nike

我正在做一个元素,其中包含一个搜索框,该搜索框使用来 self 的数据库的正确查询来回显格式整齐的图像字符串。然而,在使用 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 墙的数小时努力都没有结果。

截图如下: enter image description here

有什么建议吗?

谢谢,

最佳答案

我将你的内联 css 移到了外部,并添加了一个类 .searchitems 到 flexitems。
如果你愿意,你可以把它移回去

.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;
,它正在离开你的屏幕我在 .searchitems 中添加了一个 margin-top:10px; 并在 中添加了一个负值 margin-top:-10px; .searchresults,因此边距仅添加到包装的 .seachitems

关于php - Flexbox CSS 对齐属性在某些情况下是惰性的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52949615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com