简体   繁体   English

CSS 网格未在 Y 轴上对齐

[英]CSS grid not aligning in Y-axis

It's a small problem but I don't get it.这是一个小问题,但我不明白。 I am just trying to align the text in y-axis, but it only goes a little distance down when I put align-self : end or center.我只是想在 y 轴上对齐文本,但是当我放置 align-self : end 或 center 时,它只会向下移动一点距离。 Container is the main grid, which contains the col div (columns) which has the con div (content) which contains the text inside the box div Container 是主网格,其中包含col div(列),其中包含con div(内容),其中包含div 内的文本

CSS CSS

.container{

  display: grid;
  grid-template-columns: repeat(4,22.45em);
  grid-template-rows: 48rem;
  grid-template-areas:
  "colone coltwo colthr colfour";
  /*text-align: center;*/

}
.con{
  /*
  padding-left: 0.5rem auto;
  padding-right: 0.5rem auto;
  padding-top: 0.5rem auto;
  padding-bottom: 0.5rem auto;*/
  display: grid;
  grid-area: con;

  justify-content: center;
  align-items: center;
  padding-left: 0.5rem;
  padding-right: 0.5rem;

  position: relative;
}
.col{
  border-right: 0.005rem solid white;

  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 16rem;
  grid-template-areas: "con";
  color: grey;
  z-index: 1;
}
.box{
  position: absolute;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  justify-self: start;
  align-self: end;
}

here is the codepen link : https://codepen.io/aronnora/project/editor/DkyrVM这是 codepen 链接: https ://codepen.io/aronnora/project/editor/DkyrVM

You would probably need to put the content inside its own container and then give it some properties of its own您可能需要将内容放在自己的容器中,然后为其提供一些自己的属性

.center-Container {
  display: flex;
  justify-content: center;
  align-items: center;
}

or a simpler way to just add a padding-top: 40%;或者更简单的方法来添加一个padding-top: 40%; to your existing content到您现有的内容

Welcome to StackOverflow.欢迎使用 StackOverflow。

So I went through your CSS.所以我浏览了你的 CSS。 I inspected the elements and found out that the child element with class .con have the default height and is also not inheriting the parent's height because you haven't set height to parent which is not necessary since you are using the grid-template-rows: 48em .我检查了元素,发现类.con的子元素具有默认高度,并且也没有继承父元素的高度,因为您没有将高度设置为父元素,这是不必要的,因为您使用的是grid-template-rows: 48em

So I would suggest you to set height of .con for eg.所以我建议你设置.con高度,例如。

.con {
  height: 48em;
}

I hope this solves your query.我希望这能解决您的疑问。

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

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