<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>網(wǎng)格布局 + 截斷文本</title>
<style>
.box {
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(3, 1fr);
grid-template-areas:
'sidebar header header'
'sidebar content content'
'sidebar footer footer';
color: aqua;
}
.box>div {
background: #333;
padding: 10px;
}
.header {
grid-area: header;
}
.sidebar {
grid-area: sidebar;
}
.content {
grid-area: content;
}
.footer {
grid-area: footer;
}
.truncate p {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: 200px;
background: #333;
color: aqua;
}
</style>
</head>
<body>
<!-- 網(wǎng)格布局 -->
<div class="box">
<div class="header">header</div>
<div class="sidebar">
display: grid 啟用網(wǎng)格。
grid-gap: 10px 定義元素之間的間距。
grid-template-columns: repeat(3, 1fr) 定義3列大小相同。
grid-template-areas 定義網(wǎng)格區(qū)域的名稱。
grid-area: sidebar 使元素使用名稱為的區(qū)域sidebar 。
</div>
<div class="content">
content
<br>
哈哈哈哈哈哈哈哈哈哈哈
</div>
<div class="footer">footer</div>
</div>
<!-- 截斷文本 -->
<div class="truncate">
<p>溜溜idf你電腦年可能可能能否公雞肉你說你好吸煙返回回到那幾十年是覺得后進生</p>
<!-- overflow: hidden 防止文本溢出其尺寸(對于塊,100 %寬度和自動高度)。
white-space: nowrap 防止文本高度超過一行。
text-overflow: ellipsis 使其在文本超出其維度時以省略號結尾。
width: 200px; 確保元素具有維度,以知道何時獲取省略號 -->
</div>
</body>
</html>
css布局--網(wǎng)格布局 + 截斷文本
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內(nèi)容
- 之前寫flex布局基礎知識整理提到了網(wǎng)格布局,也大概說了下它與flex布局的區(qū)別。 flex只是一維布局(沿橫向或...
- 原文地址:Getting to know CSS Grid Layout 原文作者:Chris Wright 譯者...
- 以下是Oliver Williams的客座帖子。 Oliver一直在使用CSS網(wǎng)格布局,并收獲良多。 在這篇文章中...
- (注1:如果有問題歡迎留言探討,一起學習!轉(zhuǎn)載請注明出處,喜歡可以點個贊哦?。ㄗ?:更多內(nèi)容請查看我的目錄。) ...