我有一个由css卡组成的页面,一切工作正常,但是唯一的问题是我需要在css卡上显示的文本溢出(但是我希望它与卡一起显示)。当我将鼠标悬停在一个元素上时,还有一个需要解决的问题是悬停效果,其余的CSS卡以Z字形排列。检查以下代码。
<!DOCTYPE html>
<html>
<head>
<title>Easy</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.self{
margin-left:160px;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Float four columns side by side */
.column {
float: left;
width: 25%;
padding: 0 10px;
margin-bottom: 20px;
flex-basis: 25%;
}
/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
Responsive columns
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 1);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
transition: width 2s,height 4s;
transition-timing-function: ease-in-out;
}
.card:hover{
background-color: lightgreen;
transition-timing-function: ease-in-out;
width: 300px;
height: 300px;
}
</style>
</head>
<body style="background-color: #dae2e3;">
<div class="self">
<div class="column w3-button">
<div class="card">
<h1><?php echo"$value"; ?></h1>
<h3 style="overflow-x:page-break-inside:inherit;"><?php echo"$description";?></h3>
<h3><?php echo"$index";?></h3>
</div>
</div>
</div>
<?php }?>
产生此问题的原因是,悬停时您将卡的高度固定了。
删除height: 300px;
,您的悬停问题将消失。
.self { margin-left: 160px; } * { box-sizing: border-box; } body { font-family: Arial, Helvetica, sans-serif; } /* Float four columns side by side */ .column { float: left; width: 25%; padding: 0 10px; margin-bottom: 20px; flex-basis: 25%; } /* Remove extra left and right margins, due to padding */ .row { margin: 0 -5px; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } @media screen and (max-width: 600px) { .column { width: 100%; display: block; margin-bottom: 20px; } } /* Style the counter cards */ .card { box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 1); padding: 16px; text-align: center; background-color: #f1f1f1; transition: width 2s, height 4s; transition-timing-function: ease-in-out; } .card:hover { background-color: lightgreen; transition-timing-function: ease-in-out; width: 300px; /*height: 300px;*/ }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <body style="background-color: #dae2e3;"> <div class="self"> <div class="column w3-button"> <div class="card"> <h1>my card have an overflow problem</h1> <h3 style="overflow-x: page-break-inside:inherit;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque quisquam voluptate velit perferendis. Vel, cum dignissimos consequatur recusandae quisquam, quibusdam! Amet possimus sunt veritatis quos, nostrum minima deleniti, voluptatem repellat.</h3> <h3>1</h3> </div> </div> </div> </body>