简体   繁体   English

使用 CSS 水平而不是垂直显示颜色列表

[英]To display the color list horizontally instead vertically using CSS

I have a lit of colors that are currently displayed vertically, however i need something to spread out the color list width wise as and when they are added to the list.我有一些当前垂直显示的颜色,但是当它们添加到列表中时,我需要一些东西来扩展颜色列表的宽度。 below are the screenshot:下面是截图:

Vertical List垂直列表

在此处输入图片说明

that I need to make it look like:我需要让它看起来像:

在此处输入图片说明

In short its good to have 3-4 colors per row.简而言之,每行有 3-4 种颜色是件好事。 How can achieve this in css?如何在 css 中实现这一点?

The code is react: and below is the css.代码是 react: 下面是 css。

  render() {
    return (
        <div styleName={main}>
          <DropDownButton>
              {this.mapItems(colors)}
          </DropDownButton>
        </div>
    );
  }
 createListItem(color) {
        return (
            <a href="#" styleName={colorAll}>
              <span style={{background:"#"+color}} styleName={spanStyle}>

              </span>
            </a>
        )
      }

      mapItems(colors) {
        return colors.map(this.createListItem.bind(this));
      }

css: css:

.main {
  height: 100%;
  float: left;
  width: 600px;
}
.spanStyle {
  display: block;
  height: 20px;
  line-height: 20px;
  width: 20px;
  &:hover {
    background-color: transparent;
  }
}

.colorAll {
  padding: 2px;
}

From what I can see, just change the value for height in .main :据我.main ,只需更改.main height值:

.main {
  height: 50%;
  float: left;
  width: 600px;
}

or try pixel values for height:或尝试高度的像素值:

.main {
  height: 70px;
  float: left;
  width: 600px;
}

You can add to parent container this properies:您可以将此属性添加到父容器:

display: flex;
flex-direction:row:
flex-wrap:wrap:

And add to child elements if you want 3 element per row : flex-basis: 33% or if you want 4 elements per row flex-basis:25% .如果您想要每行 3 个元素,则添加到子元素: flex-basis: 33%或者如果您想要每row flex-basis:25% 4 个元素row flex-basis:25% Read here for more information.阅读此处了解更多信息。

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

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