Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 display:table-cell; 实现冒号居中对齐 #10

Open
iotale opened this issue Oct 10, 2020 · 0 comments
Open

使用 display:table-cell; 实现冒号居中对齐 #10

iotale opened this issue Oct 10, 2020 · 0 comments
Labels

Comments

@iotale
Copy link
Owner

iotale commented Oct 10, 2020

类似于表单可以将表单项名称根据后面的冒号对其。效果如下:
image

重点是 CSS 样式,和 React 无关,只是方便渲染

结构

const mockData = [
  {name: '1号窗口', value: '001'},
  {name: '11号窗口', value: '003'},
  {name: '91号窗口', value: '——'},
  {name: '471号窗口', value: '178'},
  {name: '33号窗口', value: '999'},
  {name: '2号窗口', value: '061'},
];
// ...
function App() {
  // ...
  return (
    <div className="box">
       {
         mockData.map(item => (
             <div key={item.name} className="item">
               <div className="name">{item.name}:&nbsp;</div>
              <div className="value">{`${item.value}号客户`}</div>
            </div>
        ))
      }
    </div>
  );
}

样式

.item {
  display: table-row;
}
.name {
  display: table-cell;
  text-align: right;
}
.value {
  display: table-cell;
}

很基础的实现,但是效果很好,代码也很简单。
需要注意的是要 显式 的给类名为 item 的元素设置 display: table-row;。否 text-align: right; 不生效。

@iotale iotale added AST CSS and removed AST labels Oct 10, 2020
@iotale iotale changed the title 使用 display:table-cell; 实现冒号居中对齐 使用 display:table-cell; 实现冒号居中对齐 Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant