A Pen by JowayYoung on CodePen.
Created
November 3, 2019 12:14
-
-
Save mqxu/d66b246ba78f8d16a7cf5fea76138b44 to your computer and use it in GitHub Desktop.
【iCSS:行为】使用max-height切换自动高度
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="bruce flex-ct-x"> | |
<ul class="auto-height"> | |
<li> | |
<h3>列表1</h3> | |
<p>内容1<br>内容2<br>内容3<br>内容4</p> | |
</li> | |
<li> | |
<h3>列表2</h3> | |
<p>内容1<br>内容2<br>内容3<br>内容4</p> | |
</li> | |
<li> | |
<h3>列表3</h3> | |
<p>内容1<br>内容2<br>内容3<br>内容4</p> | |
</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.auto-height { | |
width: 300px; | |
li { | |
margin-top: 5px; | |
cursor: pointer; | |
&:first-child { | |
margin-top: 0; | |
} | |
&:hover p { | |
border-bottom-width: 1px; | |
max-height: 600px; | |
} | |
} | |
h3 { | |
padding: 0 20px; | |
height: 40px; | |
background-color: #f66; | |
cursor: pointer; | |
line-height: 40px; | |
font-size: 16px; | |
color: #fff; | |
} | |
p { | |
overflow: hidden; | |
padding: 0 20px; | |
border: 1px solid #f66; | |
border-top: none; | |
border-bottom-width: 0; | |
max-height: 0; | |
line-height: 30px; | |
transition: all 500ms; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://yangzw.vip/static/css/reset.css" rel="stylesheet" /> | |
<link href="https://yangzw.vip/static/css/main.css" rel="stylesheet" /> | |
<link href="https://yangzw.vip/static/css/theme.scss" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment