简体   繁体   English

语义用户界面反应中的网格对齐问题

[英]grid alignment issue in semantic-ui-react

I am using semantic-ui-react to create a simple news-like layout with an image and text alongside but unable to fix the empty space issue. 我正在使用语义UI反应来创建一个简单的类似新闻的布局,同时在其中放置图像和文本,但无法解决空白问题。

Below is a screenshot along with details in computed panel. 以下是屏幕截图以及计算面板中的详细信息。 I am unable to figure out the cause of the empty white space(outside the padding area marked with green) in the first cell containing the image. 我无法找出包含图像的第一个单元格中空白区域(用绿色标记的填充区域之外)空白的原因。

在此处输入图片说明

This is how my JSX code looks like - 这就是我的JSX代码的样子-

import * as React from "react";
import { Grid, Image, Container, Header } from "semantic-ui-react";

export const SummaryList: React.SFC = () => {
  const items = Array.from(Array(10).keys());
  return (
    <div>
    {items.map((i) => 
    <Grid key={i} celled stackable>
      <Grid.Row centered columns={2}>
        <Grid.Column width={3}>
          <Image src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/FIFA_series_logo.svg/1280px-FIFA_series_logo.svg.png" />
        </Grid.Column>
        <Grid.Column width={10}>
          <Container >
            <Header as="h3">quick brown fox scored a goal</Header>
            <p>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
              commodo ligula eget dolor...
            </p>
          </Container>
        </Grid.Column>
      </Grid.Row>
    </Grid>
  )}
  </div>);
};

I recreated your code and I don't have any white space. 我重新创建了您的代码,但没有空格。

在此处输入图片说明

So this could be caused by your body styles, try setting the margin and padding to 0, or if you have a container component holding it, the styles on that container could be the issue as well. 因此,这可能是由您的身体样式引起的,请尝试将margin和padding设置为0,或者如果您拥有一个容纳它的容器组件,则该容器上的样式也可能是问题。

The cause of the extra space below was due to the long text in the second column while the cause of the extra space on left was due to the way semantic-ui arranges columns. 下方多余空间的原因是第二列中的文本太长,而左侧多余空间的原因是语义UI排列列​​的方式。

I did following things to fix the space on the left - 我做了以下事情来固定左侧的空间-

  • moved the Grid out of the loop Grid移出循环
  • once I understood that semantic-ui comes with 16 columns, I assigned 12 column space to the text container and 4 column space to image. 一旦我了解了semantic-ui带有16列,就将12列空间分配给文本容器,将4列空间分配给图像。
  • removed unnecessary Container within Grid.Column 删除了Grid.Column中不必要的Container

Following helped me get rid of the extra space on the left - 以下帮助我摆脱了左侧的多余空间-

import * as React from "react";
import { Grid, Image, Container, Header } from "semantic-ui-react";

export const SummaryList: React.SFC = () => {
  const items = Array.from(Array(10).keys());
  return (
    <div>
    <Grid key={i} celled stackable>
    {items.map((i) => 
      <Grid.Row centered columns={2}>
        <Grid.Column width={4}>
          <Image src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/FIFA_series_logo.svg/1280px-FIFA_series_logo.svg.png" />
        </Grid.Column>
        <Grid.Column width={12}>
            <Header as="h3">quick brown fox scored a goal</Header>
            <p>
              Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
              commodo ligula eget dolor...
            </p>
        </Grid.Column>
      </Grid.Row>
  )}
    </Grid>
  </div>);
};

I am still not sure how to make the text column dynamically adhere to certain size to ensure the image cell doesn't have to stretch too much. 我仍然不确定如何使文本列动态保持一定大小,以确保图像单元格不必拉伸得太多。 For now I adjusted the text size to align to not exceed image cell size. 现在,我将文本大小调整为不超过图像单元格大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM