中文 |
翻译 |Web 后端开发 (web_qdkf)。
使用图像叠加图标来给您的网站交互细节或一组功能留下深刻印象。本文的内容将分为两部分,第一部分创建结构并将链接附加到图标。在第二部分中html 图像,我们将使用 CSS 进行设计。
创建结构:在本节中html 图像,我们将创建一个基本结构,并将 Font-awesome CDN 链接附加到那些将在悬停时用作图标的图标。
“字体如此之好”中图标的CDN链接:
<link rel =” stylesheet” href =““ https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css”>
网页代码:
Image Overlay Icon using HTML and CSS
<link rel="stylesheet" href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
GeeksforGeeks
Image Overlay Icon using HTML and CSS
"https://media.geeksforgeeks.org/wp-content/uploads/20200326201748/download312.png"
alt="Geeksforgeeks">
设计结构:在内部内容中,我们创建了将用作图像叠加图标的基本网站的结构。在本节中,我们将设计图像叠加图标的结构。
CSS代码:
body {
text-align: center;
}
h1 {
color: green;
}
/* Image styling */
img {
padding: 5px;
height: 225px;
width: 225px;
border: 2px solid gray;
box-shadow: 2px 4px #888888;
}
/* Overlay styling */
.overlay {
position: absolute;
top: 23.5%;
left: 32.8%;
transition: .3s ease;
background-color: gray;
width: 225px;
height: 225px;
opacity: 0;
}
/* Overlay hover */
.container:hover .overlay {
opacity: 1;
}
/* Icon styling */
.icon {
color: white;
font-size: 92px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
最终
解决方案:这是将上述两部分组合在一起后的最终代码。它将显示图像叠加图标。
Image Overlay Icon using HTML and CSS
<link rel="stylesheet" href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
body {
text-align: center;
}
h1 {
color: green;
}
/* Image styling */
img {
padding: 5px;
height: 225px;
width: 225px;
border: 2px solid gray;
box-shadow: 2px 4px #888888;
}
/* Overlay styling */
.overlay {
position: absolute;
top: 23.5%;
left: 32.8%;
transition: .3s ease;
background-color: gray;
width: 225px;
height: 225px;
opacity: 0;
}
/* Overlay hover */
.container:hover .overlay {
opacity: 1;
}
/* Icon styling */
.icon {
color: white;
font-size: 92px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
GeeksforGeeks
Image Overlay Icon using HTML and CSS
"https://media.geeksforgeeks.org/wp-content/uploads/20200326201748/download312.png"
alt="Geeksforgeeks">
最终输出效率:
以下部分向新创建的具有 p-notification 类的 div 设备添加或设置范围通知属性:
this.notification = $('', {
'class': 'p-notification'
});
下一个要降低或设置 content 属性上限的部分是新创建的 div 元素添加html,它预设了几个属性:class、style 和 text:
this.content = $('', {
'class': $elem.attr("hasFooter") === "true" ? 'p-content with-p-footer' : 'well',
'style': $elem.attr("paddless") === "true" ? 'padding:0;' : '',
'text': 'Loading'
});
它本身对 DOM 没有影响添加html,因为您已经创建了元素但没有将它们插入到文档中。 您可以使用 jQuery 提供的多种方法插入它们,例如追加:
$('#somediv').append(this.content);//adds the div that was created to an element with id somediv
发表评论