在html中加icon,利用CSS3 @font-face属性在网页中添加小图标

正如标题所示,今天要掌握的知识利用@font-face + Icomoon 在网页中加入小图标。

知识要点:

在网站中加入小图标

打开http://icomoon.io/app/#/select选择你要下载的小图标,点击Generate Font 下载。

复制style.css样式到你的样式表里,注意修改路径

@font-face {

font-family: 'icomoon';

src: url('../fonts/icomoon.eot'); /* IE9 兼容模式 */

src:url('../fonts/icomoon.eot?vml2lj');

src:url('../fonts/icomoon.eot?#iefixvml2lj') format('embedded-opentype'),

url('../fonts/icomoon.woff?vml2lj') format('woff'),

url('../fonts/icomoon.ttf?vml2lj') format('truetype'),

url('../fonts/icomoon.svg?vml2lj#icomoon') format('svg');

font-weight: normal;

font-style: normal;

}

.icon{

font-family: "icomoon";

font-style: normal;

font-weight: normal;

font-size: 20px;

-webkit-font-smoothing: antialiased;

-moz-osx-font-smoothing: grayscale;

margin-right: 5px;

color:#0195ba;

}

复制fonts文件夹到你的主题里。

接下来我们就可以调用小图标在你网页中了。打开demo.html复制你想要在网页中显示的小图标代码,我的代码为e600,在网页中调用小图标,代码如下,注意在代码e600前加上

您可以使用以下 HTMLCSS 代码来创建一个带搜索图标的搜索框: HTML 代码: ```html <div class="search-box"> <form action="/search" method="get"> <input type="text" placeholder="Search..."> <button type="submit"><i class="fa fa-search"></i></button> </form> </div> ``` CSS 代码: ```css .search-box { display: flex; justify-content: center; align-items: center; margin: 20px; } input[type="text"] { padding: 10px; border: none; border-radius: 5px 0 0 5px; width: 200px; font-size: 16px; } button[type="submit"] { padding: 10px 15px; background-color: #4CAF50; border: none; border-radius: 0 5px 5px 0; color: white; font-size: 16px; cursor: pointer; } i.fa.fa-search { font-size: 16px; margin-right: 5px; } ``` 这里的 HTML 代码中包含一个名为 `search-box` 的 div 元素,用于设置搜索框的样式。在 div 元素内部,使用了 form 元素和 input 元素来创建搜索框,使用了 button 元素和 i 元素来创建搜索按钮和搜索图标。`placeholder` 属性提供了默认的提示文本,`name` 属性指定了提交的参数名称。 CSS 代码中使用了 `display: flex` 属性和 `justify-content: center` 和 `align-items: center` 属性来将搜索框水平居中。`border-radius` 属性用于设置输入框和按钮的圆角,`padding` 属性用于设置输入框和按钮的内边距,`width` 属性用于设置输入框的宽度。`background-color` 属性用于设置按钮的背景颜色,`color` 属性用于设置按钮的文字颜色,`cursor` 属性用于设置鼠标悬停时的光标类型。`fa` 和 `fa-search` 类名用于引用 Font Awesome 图标库中的搜索图标样式。 请注意,这里使用了 Font Awesome 图标库,您需要在页面中引入该库的 CSS 样式文件,例如: ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值