隐藏虽然是隐藏了 但是不够美观 我想将可见区域文字最后 替换成。。。 然后加上一个查看详情的功能,点击查看详情 可以通过弹窗查看所有信息
时间: 2024-03-13 16:46:23 浏览: 22
好的,您可以使用CSS的文本溢出截断属性,将超出部分替换成省略号,同时添加一个查看详情的按钮或链接。点击按钮或链接时,可以弹出一个模态框,在模态框中展示完整的项目描述内容。
以下是一个实现的示例代码:
HTML部分:
```html
<div class="item">
<div class="title">项目标题</div>
<div class="description">项目描述内容,可能会很长,需要截断隐藏。在末尾添加省略号。点击<a href="#" class="more">查看详情</a>可以查看完整内容。</div>
</div>
```
CSS部分:
```css
.item {
display: flex;
align-items: center;
}
.title {
flex: 0 0 auto;
width: 100px;
}
.description {
flex: 1 1 auto;
width: 200px;
height: 60px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.more {
text-decoration: none;
color: #007bff;
cursor: pointer;
}
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
}
.modal-content {
background-color: #fff;
padding: 20px;
max-width: 80%;
max-height: 80%;
overflow-y: auto;
}
```
JavaScript部分:
```javascript
var modal = document.createElement('div');
modal.classList.add('modal');
var modalContent = document.createElement('div');
modalContent.classList.add('modal-content');
modal.appendChild(modalContent);
var items = document.querySelectorAll('.item');
for (var i = 0; i < items.length; i++) {
var item = items[i];
var description = item.querySelector('.description');
var more = item.querySelector('.more');
var fullDescription = description.innerHTML;
more.addEventListener('click', function(event) {
event.preventDefault();
modalContent.innerHTML = fullDescription;
document.body.appendChild(modal);
});
}
```
上述代码中,我们使用了CSS的flexbox布局,将项目标题和项目描述内容放在一行中。对于项目描述内容,我们使用了文本溢出截断属性,将超出部分截断并添加省略号。同时,我们在末尾添加了一个“查看详情”的链接,点击这个链接会弹出一个模态框,展示完整的项目描述内容。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)