CSS 网格 - 子项不居中且 ul 在变换时不扩展全角:旋转?
CSS Grid - Children do not center and ul does not extend full-width on transform: rotate?
我从 CSS 开始,但我有疑问,我不明白为什么该部分。 aside2,根据放在里面的文本而不是正文网格中指定的文本来获取宽度,我想要做的是拥有链接。 aside2 rotated 但在 grid-template-columns 中分配了宽度,而不是我根据是否添加更多文本来选择它,并理解为什么我不会,看看是否有人可以帮助我
*填写文字因为它说我的post主要是代码,填写文字因为它说我的post主要是代码
*{
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
color: white;
}
body{
background-color: rgb(17, 17, 17);
display: grid;
grid-template-columns: 140px 1fr;
grid-template-rows: 80px 1fr;
height: 100vh;
}
aside{
grid-column: 1/2;
grid-row: 1/3;
width: 100%;
display: grid;
}
.aside1{
background: rgb(116,191,244);
background: linear-gradient(0deg, rgba(116,191,244,1) 0%, rgba(255,162,222,1) 100%);
box-shadow: 30px 0px 192px 100px rgba(0,43,255,0.15);
}
.aside2{
box-sizing: border-box;
display:flex;
justify-content: center;
align-items: center;
}
.aside2 ul{
display: flex;
transform: rotate(-90deg);
}
.aside2 ul li{
}
.aside2 ul li a{
color: white;
}
header{
grid-column: 2/3;
grid-row: 1/2;
}
main{
grid-column: 2/3;
grid-row: 2/3;
}
h1{
font-size: 50px;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<aside>
<section class="aside1">
<span>Hola</span>
</section>
<section class="aside2">
<ul>
<li><a href="">Instagram</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Facebook</a></li>
</ul>
</section>
</aside>
<header>
<nav>
<a href="">G6</a>
<ul>
<li><a href="">Buy NFT</a></li>
<li><a href="">Whitepaper</a></li>
<li><a href="">Feeding</a></li>
<li><a href="">FAQ</a></li>
<li><a href="">Connect Wallet</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Discover rare digital art and collect NFTs</h1>
<div>
<img src="" alt="a">
<img src="" alt="b">
<img src="" alt="c">
</div>
<img src="" alt="FOTO NFT">
</section>
<div>
<img src="" alt="Una">
<img src="" alt="Dos">
</div>
</main>
</body>
</html>
get-go 之后有几件事。您不需要在网格 children 上使用 flex-box 和 align/justify-center 来使它们居中。
只需在您的 parent 上添加 place-items: center;
并使用主网格作为替代。
之后,只需在您的网格 children 上指定 height
和 width: 100%;
即可填充剩余的 space.
继续 aside2
宽度 max-content。您会注意到,现在每个 parent (aside1 & aside2
) 都有定义的宽度和高度,您可以在 ul
上定义宽度和高度,这将占据整个 space 垂直和水平(如果指定)。您的 aside2
class 应如下所示:
.aside2 > ul {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
flex-direction: column;
}
注意到我删除了 transform: rotate
。您应该会看到类似这样的内容:View Image.
然后像这样在 li
上设置你的 transform
:
.aside2>ul>li {
transform: rotate(-90deg);
}
看到它在这里工作:
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
color: white;
}
body {
background-color: rgb(17, 17, 17);
display: grid;
grid-template-columns: 140px 1fr;
grid-template-rows: 80px 1fr;
height: 100vh;
}
aside {
grid-column: 1/2;
grid-row: 1/3;
width: 100%;
display: grid;
place-items: center;
}
.aside1 {
background: rgb(116, 191, 244);
background: linear-gradient(0deg, rgba(116, 191, 244, 1) 0%, rgba(255, 162, 222, 1) 100%);
box-shadow: 30px 0px 192px 100px rgba(0, 43, 255, 0.15);
width: 100%;
height: 100%;
}
.aside2 {
box-sizing: border-box;
width: 100%;
height: 100%;
}
.aside2 > ul {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
flex-direction: column;
}
.aside2>ul>li {
transform: rotate(-90deg);
}
.aside2 ul li a {
color: white;
}
header {
grid-column: 2/3;
grid-row: 1/2;
}
main {
grid-column: 2/3;
grid-row: 2/3;
}
h1 {
font-size: 50px;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<aside>
<section class="aside1">
<span>Hola</span>
</section>
<section class="aside2">
<ul>
<li><a href="">Instagram</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Facebook</a></li>
</ul>
</section>
</aside>
<header>
<nav>
<a href="">G6</a>
<ul>
<li><a href="">Buy NFT</a></li>
<li><a href="">Whitepaper</a></li>
<li><a href="">Feeding</a></li>
<li><a href="">FAQ</a></li>
<li><a href="">Connect Wallet</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Discover rare digital art and collect NFTs</h1>
<div>
<img src="" alt="a">
<img src="" alt="b">
<img src="" alt="c">
</div>
<img src="" alt="FOTO NFT">
</section>
<div>
<img src="" alt="Una">
<img src="" alt="Dos">
</div>
</main>
</body>
</html>
我从 CSS 开始,但我有疑问,我不明白为什么该部分。 aside2,根据放在里面的文本而不是正文网格中指定的文本来获取宽度,我想要做的是拥有链接。 aside2 rotated 但在 grid-template-columns 中分配了宽度,而不是我根据是否添加更多文本来选择它,并理解为什么我不会,看看是否有人可以帮助我
*填写文字因为它说我的post主要是代码,填写文字因为它说我的post主要是代码
*{
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
color: white;
}
body{
background-color: rgb(17, 17, 17);
display: grid;
grid-template-columns: 140px 1fr;
grid-template-rows: 80px 1fr;
height: 100vh;
}
aside{
grid-column: 1/2;
grid-row: 1/3;
width: 100%;
display: grid;
}
.aside1{
background: rgb(116,191,244);
background: linear-gradient(0deg, rgba(116,191,244,1) 0%, rgba(255,162,222,1) 100%);
box-shadow: 30px 0px 192px 100px rgba(0,43,255,0.15);
}
.aside2{
box-sizing: border-box;
display:flex;
justify-content: center;
align-items: center;
}
.aside2 ul{
display: flex;
transform: rotate(-90deg);
}
.aside2 ul li{
}
.aside2 ul li a{
color: white;
}
header{
grid-column: 2/3;
grid-row: 1/2;
}
main{
grid-column: 2/3;
grid-row: 2/3;
}
h1{
font-size: 50px;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<aside>
<section class="aside1">
<span>Hola</span>
</section>
<section class="aside2">
<ul>
<li><a href="">Instagram</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Facebook</a></li>
</ul>
</section>
</aside>
<header>
<nav>
<a href="">G6</a>
<ul>
<li><a href="">Buy NFT</a></li>
<li><a href="">Whitepaper</a></li>
<li><a href="">Feeding</a></li>
<li><a href="">FAQ</a></li>
<li><a href="">Connect Wallet</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Discover rare digital art and collect NFTs</h1>
<div>
<img src="" alt="a">
<img src="" alt="b">
<img src="" alt="c">
</div>
<img src="" alt="FOTO NFT">
</section>
<div>
<img src="" alt="Una">
<img src="" alt="Dos">
</div>
</main>
</body>
</html>
get-go 之后有几件事。您不需要在网格 children 上使用 flex-box 和 align/justify-center 来使它们居中。
只需在您的 parent 上添加 place-items: center;
并使用主网格作为替代。
之后,只需在您的网格 children 上指定 height
和 width: 100%;
即可填充剩余的 space.
继续 aside2
宽度 max-content。您会注意到,现在每个 parent (aside1 & aside2
) 都有定义的宽度和高度,您可以在 ul
上定义宽度和高度,这将占据整个 space 垂直和水平(如果指定)。您的 aside2
class 应如下所示:
.aside2 > ul {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
flex-direction: column;
}
注意到我删除了 transform: rotate
。您应该会看到类似这样的内容:View Image.
然后像这样在 li
上设置你的 transform
:
.aside2>ul>li {
transform: rotate(-90deg);
}
看到它在这里工作:
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
color: white;
}
body {
background-color: rgb(17, 17, 17);
display: grid;
grid-template-columns: 140px 1fr;
grid-template-rows: 80px 1fr;
height: 100vh;
}
aside {
grid-column: 1/2;
grid-row: 1/3;
width: 100%;
display: grid;
place-items: center;
}
.aside1 {
background: rgb(116, 191, 244);
background: linear-gradient(0deg, rgba(116, 191, 244, 1) 0%, rgba(255, 162, 222, 1) 100%);
box-shadow: 30px 0px 192px 100px rgba(0, 43, 255, 0.15);
width: 100%;
height: 100%;
}
.aside2 {
box-sizing: border-box;
width: 100%;
height: 100%;
}
.aside2 > ul {
width: 100%;
height: 100%;
display: flex;
justify-content: space-around;
flex-direction: column;
}
.aside2>ul>li {
transform: rotate(-90deg);
}
.aside2 ul li a {
color: white;
}
header {
grid-column: 2/3;
grid-row: 1/2;
}
main {
grid-column: 2/3;
grid-row: 2/3;
}
h1 {
font-size: 50px;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<aside>
<section class="aside1">
<span>Hola</span>
</section>
<section class="aside2">
<ul>
<li><a href="">Instagram</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Facebook</a></li>
</ul>
</section>
</aside>
<header>
<nav>
<a href="">G6</a>
<ul>
<li><a href="">Buy NFT</a></li>
<li><a href="">Whitepaper</a></li>
<li><a href="">Feeding</a></li>
<li><a href="">FAQ</a></li>
<li><a href="">Connect Wallet</a></li>
</ul>
</nav>
</header>
<main>
<section>
<h1>Discover rare digital art and collect NFTs</h1>
<div>
<img src="" alt="a">
<img src="" alt="b">
<img src="" alt="c">
</div>
<img src="" alt="FOTO NFT">
</section>
<div>
<img src="" alt="Una">
<img src="" alt="Dos">
</div>
</main>
</body>
</html>