CSS cards gets zig zagged on hover and also text is flowing outside the box(overflow)

送分小仙女□ 提交于 2020-05-17 07:05:26

问题


i have a page which consists of css cards everything is working fine but the only problem is text which i need to display on css cards is over flowing (but i want it to be displayed with in the card). and one more thing to be fixed is hover effect, when i hover over an element remaining css cards are arranged in zig zag manner. check the following code.

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


回答1:


This problem is produced because you gave fixed height to the card when hover.

Remove height: 300px; and your hover problem will be gone.

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


来源:https://stackoverflow.com/questions/61476510/css-cards-gets-zig-zagged-on-hover-and-also-text-is-flowing-outside-the-boxover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!