javascript - 宽度/高度 html 属性在非 img html 元素中是否重要?
问题描述
像styled-components和styled-system这样的React 库非常流行,我注意到经常使用以下策略:
import {
space,
width,
color,
top,
position,
bottom,
opacity
} from 'styled-system';
import styled from 'styled-components';
export const Relative = styled.div`
position: relative;
${position}
${space}
${width}
${height}
`;
const MyComponent = () => <Relative width={1}>some stuff...</Relative>
position: relative
这是一种在组件上使用的声明性方式。还使用了其他 CSS 设置,如宽度和高度(来自styled-system
)。
但是我注意到这种用法将导致div
具有width="1"
价值:
<div width="1">some stuff...</div>
然而,在样式系统width={1}
中,width: 100%
这会导致width="1"
实际的 html。我想知道是否width="1"
可以忽略它,因为从技术上讲,这个宽度值没有任何意义。这可能是img
元素的问题,因为浏览器实际上可能依赖于宽度/高度 html 属性,但对于非 img 标签,这有什么影响吗?
解决方案
推荐阅读
- java - 我的代码中有一个卡片布局错误,表明我在单击鼠标时遇到问题
- c# - 如何在 asp.net web api 项目中实现 IIS 身份验证?
- gitlab - 从 Gitlab CI API 中查找工作标签
- firebase - Firebase:结合查询和子事件监听器
- php - 看不到 PHP 代码的语法错误
- css - 自定义帖子类型按日期和时间排序 - Wordpress
- python-3.x - python 3.6的if语句和else
- java - 在数据库中保存 BCryptPasswordEncoder 时出错
- c# - 创建自定义 Button 控件的最节省内存的方法是什么?
- vba - 在每个单元格 Excel 中使用 VBA 而不是使用公式(索引和匹配)