公共css文件初始化

本文介绍了一种兼容多种浏览器的CSS初始化样式方法,通过统一元素的默认样式来确保跨浏览器的一致性表现。该样式表包括了常用HTML元素的默认样式重置,如边距、填充等,并对字体大小、颜色进行了规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

body,
html{
  height: 100%;
}
body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
code,
form,
fieldset,
legend,
input,
button,
textarea,
p,
blockquote,
th,
td {
  margin:0;
  padding:0;
  box-sizing: border-box;
}

body, button, input, select, textarea {
  font: 14px Arial,PingFangSC,"Lucida Grande",Verdana,"Microsoft YaHei",hei;
  color: #333;
  line-height: 1.5;
  border: 0;
  outline: 0;
}
h1, h2, h3, h4, h5, h6 {
  font-weight:normal;
  font-size:100%;
}
address, caption, cite, code, dfn, em, strong, th, var {
  font-style:normal;
  font-weight:normal;
}
a { color:#555;
  text-decoration:none;
  font-size: 0.42857142857142855rem;
  font-size: 24/56rem;
}
a:hover {
  text-decoration:none;
}
img { border:none; }
ol,ul,li {
  list-style:none;
  padding: 0;
}
input, textarea, select, button {
  font:0.42857142857142855rem Verdana,Helvetica,Arial,sans-serif;
}
table {
  border-collapse:collapse;
}
.clearfix:after {
  content: ".";
  display: block;
  height:0;
  clear:both;
  visibility: hidden;
}
.clearfix {
  *zoom:1;
}

/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
::-webkit-scrollbar
{
  width: 0px;
  height: 0px;
  background-color: #F5F5F5;
}
/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track
{
  -webkit-box-shadow: inset 0 0 1px rgba(0,0,0,0);
  border-radius: 10px;
  background-color: #F5F5F5;
}

/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb
{
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
  background-color: #555;
}

input[type="button"], input[type="submit"], input[type="search"], input[type="reset"] {
  -webkit-appearance: none;
}
textarea { -webkit-appearance: none;}
.margin{
  margin: 0 auto;
}
.left{
  float: left;
}
.right{
  float: right;
}
.hide{
  display: none;
}
.show{
  display: block;
}
.ellipsis{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

兼容多浏览器的 初始化 css 样式

### 封装和初始化公共组件的最佳实践 #### 使用 Composition API 提升代码复用性 为了提升 Vue 3 中组件的复用性和维护性,推荐采用 Composition API 来组织逻辑。Composition API 让开发者能更灵活地组合功能模块,从而创建高度可重用的业务逻辑片段[^2]。 ```javascript import { defineComponent, ref } from 'vue'; export function useCounter() { const count = ref(0); function increment() { count.value++; } return { count, increment }; } ``` 此函数 `useCounter` 可被多个不同界面共享,实现计数器的功能而无需重复编写相同逻辑。 #### 创建全局注册机制简化组件引入 对于项目中频繁使用的通用型 UI 组件(按钮、输入框等),可以通过插件形式一次性完成批量注册工作,减少单页面应用内各处手动声明的工作量[^1]。 ```typescript // plugins/element.ts import ElementPlus from 'element-plus'; import 'element-plus/dist/index.css'; import * as components from './components'; // 假设所有自定义组件都位于该路径下 const install = (app: App) => { app.use(ElementPlus); Object.keys(components).forEach((key) => { const component = components[key]; app.component(component.name || key, component); }); }; export default { install }; ``` 随后只需在入口文件 main.js 或者 main.ts 中调用一次即可: ```javascript import { createApp } from 'vue'; import App from './App.vue'; import MyPlugin from './plugins/element'; createApp(App).use(MyPlugin).mount('#app'); ``` #### 配置 TypeScript 支持增强类型安全性 当使用 TypeScript 开发时,确保为每一个组件提供完整的接口定义,这不仅有助于编辑器智能提示,也能有效防止潜在类型的错误发生。 ```typescript <script lang="ts"> import { defineComponent, PropType } from 'vue'; import { IOptions } from '@/types/options'; interface IData { message: string; } export default defineComponent({ props: { options: { type: Object as PropType<IOptions>, required: true, }, }, data(): IData { return { message: '', }; }, }); </script> ``` 通过上述方式,在构建大型应用程序过程中,可以显著提高开发效率并降低出错几率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值