<ul> и <p>без упаковки в css макете сетки - PullRequest
0 голосов
/ 01 апреля 2020

Я пытаюсь понять структуру сетки CSS, и я до сих пор люблю все это! Тем не менее, я не могу заставить код сработать.

Когда боковая панель навигации заполняет всю ширину, я хочу, чтобы абзац справа разбивался под навигацией. Я знаю, как бы это сделать с помощью flexbox и медиа-запросов (flex-direction: row vs column), но я не совсем понимаю, как это сделать с сеткой CSS. Вы можете мне помочь?

.container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  grid-gap: 10px;
}


/* Navigation */

.legal-navi {
  grid-column: 1;
  list-style: none;
  padding: 0;
}

.legal-navi li {
  width: 100%;
  box-sizing: border-box;
  /* border */
  border: black solid;
  border-width: 1px 0 0 0;
}

.legal-navi li a {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 20px;
  display: block;
}

.legal-navi li:last-child {
  border-width: 1px 0 1px 0;
}


/* content */

.legal-content {
  grid-column: 2 / -1;
}
<div class="container">
  <ul class="legal-navi">
    <li>
      <a href="lorem">Lorem</a>
    </li>
    <li>
      <a href="ipsum">Ipsum</a>
    </li>
    <li>
      <a href="dolor">Dolor</a>
    </li>
    <li>
      <a href="ahmet">Ahmet</a>
    </li>
  </ul>
  <p class="legal-content">
    Cry louder at reflection eat half my food and ask for more so dont wait for the storm to pass, dance in the rain for tweeting a baseball poop on floor and watch human clean up lick the plastic bag but stand with legs in litter box, but poop outside. Stand
    with legs in litter box, but poop outside cats are fats i like to pets them they like to meow back, twitch tail in permanent irritation so immediately regret falling into bathtub yet nyan fluffness ahh cucumber!, but the door is opening! how exciting
    oh, it's you, meh purr while eating. When in doubt, wash eat owner's food so sit in a box for hours and skid on floor, crash into wall pretend not to be evil. Give attitude if human is on laptop sit on the keyboard so demand to have some of whatever
    the human is cooking, then sniff the offering and walk away, cat slap dog in face. Hide from vacuum cleaner purrr purr littel cat, little cat purr purr or eat the fat cats food. Eat an easter feather as if it were a bird then burp victoriously, but
    tender pee in human's bed until he cleans the litter box sleep in the bathroom sink sleep nap but furrier and even more furrier hairball cat gets stuck in tree firefighters try to get cat down firefighters get stuck in tree cat eats firefighters'
    slippers. Weigh eight pounds but take up a full-size bed poop on grasses but scream for no reason at 4 am, sleep nap plays league of legends sit on human they not getting up ever for my slave human didn't give me any food so i pooped on the floor.
    Meow. Meow for food, then when human fills food dish, take a few bites of food and continue meowing cat fur is the new black cat fur is the new black , cough hairball, eat toilet paper grab pompom in mouth and put in water dish for stare out cat door
    then go back inside i love cats i am one wake up scratch humans leg for food then purr then i have a and relax. Annoy kitten brother with poking. Curl up and sleep on the freshly laundered towels eat too much then proceed to regurgitate all over living
    room carpet while humans eat dinner, for sit on human sleep everywhere, but not in my bed i show my fluffy belly but it's a trap! if you pet it i will tear up your hand and sit on human they not getting up ever. Mewl for food at 4am x intently sniff
    hand cat milk copy park pee walk owner escape bored tired cage droppings sick vet vomit but show belly nyan fluffness ahh cucumber! so you call this cat food. Meowing chowing and wowing then cats take over the world for chase ball of string for being
    gorgeous with belly side up. Why use post when this sofa is here milk the cow or favor packaging over toy pet my belly, you know you want to; seize the hand and shred it!. Sniff sniff chew on cable stare at owner accusingly then wink for eat the rubberband,
    asdflkjaertvlkjasntvkjn (sits on keyboard) the door is opening! how exciting oh, it's you, meh. Eat prawns daintily with a claw then lick paws clean wash down prawns with a lap of carnation milk then retire to the warmest spot on the couch to claw
    at the fabric before taking a catnap. Poop in a handbag look delicious and drink the soapy mopping up water then puke giant foamy fur-balls hide head under blanket so no one can see hate dog, so human give me attention meow i can haz. Behind the couch
    climb leg, so sun bathe. Ask to be pet then attack owners hand sleep on dog bed, force dog to sleep on floor lies down , for rub butt on table. Mew chase ball of string so scratch at fleas, meow until belly rubs, hide behind curtain when vacuum cleaner
    is on scratch strangers and poo on owners food, yet intently stare at the same spot, yet plays league of legends mesmerizing birds for cat jumps and falls onto the couch purrs and wakes up in a new dimension filled with kitty litter meow meow yummy
    there is a bunch of cats hanging around eating catnip . Scratch at fleas, meow until belly rubs, hide behind curtain when vacuum cleaner is on scratch strangers and poo on owners food my left donut is missing, as is my right but give me some of your
    food give me some of your food give me some of your food meh, i don't want it i is not fat, i is fluffy, but i like big cats and i can not lie, but lick face hiss at owner, pee a lot, and meow repeatedly scratch at fence purrrrrr eat muffins and poutine
    until owner comes back. Lick sellotape find empty spot in cupboard and sleep all day destroy the blinds and stare at owner accusingly then wink ccccccccccccaaaaaaaaaaaaaaatttttttttttttttttssssssssssssssss but kitty pounce, trip, faceplant you didn't
    see that no you didn't definitely didn't lick, lick, lick, and preen away the embarrassment for mesmerizing birds. Shove bum in owner's face like camera lens Gate keepers of hell or i heard this rumor where the humans are our owners, pfft, what do
    they know?!.
  </p>
</div>

Ответы [ 2 ]

1 голос
/ 01 апреля 2020

Вы явно определили grid-column как 2, поэтому этого не произойдет. Кстати, такая задача не подходит для сетки CSS, если вы не хотите использовать медиа-запрос.

Вы можете сделать это с помощью flexbox и без медиа-запроса, как показано ниже:

.container {
  display: flex;
  flex-wrap: wrap;
}

.legal-navi {
  list-style: none;
  padding: 0;
  width: 250px;
  max-width: 100%;
  flex-grow: 1;
}

.legal-content {
  width: calc(100% - 250px);
  min-width: 250px;
  flex-grow: 1;
  padding-left: 10px;
}


/**/

.legal-navi li {
  width: 100%;
  border: black solid;
  border-width: 1px 0 0 0;
}

.legal-navi li a {
  width: 100%;
  height: 100%;
  padding: 20px;
  display: block;
}

.legal-navi li:last-child {
  border-width: 1px 0 1px 0;
}

* {
  box-sizing: border-box;
}
<div class="container">
  <ul class="legal-navi">
    <li>
      <a href="lorem">Lorem</a>
    </li>
    <li>
      <a href="ipsum">Ipsum</a>
    </li>
    <li>
      <a href="dolor">Dolor</a>
    </li>
    <li>
      <a href="ahmet">Ahmet</a>
    </li>
  </ul>
  <p class="legal-content">
    Cry louder at reflection eat half my food and ask for more so dont wait for the storm to pass, dance in the rain for tweeting a baseball poop on floor and watch human clean up lick the plastic bag but stand with legs in litter box, but poop outside. Stand
    with legs in litter box, but poop outside cats are fats i like to pets them they like to meow back, twitch tail in permanent irritation so immediately regret falling into bathtub yet nyan fluffness ahh cucumber!, but the door is opening! how exciting
    oh, it's you, meh purr while eating. When in doubt, wash eat owner's food so sit in a box for hours and skid on floor, crash into wall pretend not to be evil. Give attitude if human is on laptop sit on the keyboard so demand to have some of whatever
    the human is cooking, then sniff the offering and walk away, cat slap dog in face. Hide from vacuum cleaner purrr purr littel cat, little cat purr purr or eat the fat cats food. Eat an easter feather as if it were a bird then burp victoriously, but
    tender pee in human's bed until he cleans the litter box sleep in the bathroom sink sleep nap but furrier and even more furrier hairball cat gets stuck in tree firefighters try to get cat down firefighters get stuck in tree cat eats firefighters'
    slippers. Weigh eight pounds but take up a full-size bed poop on grasses but scream for no reason at 4 am, sleep nap plays league of legends sit on human they not getting up ever for my slave human didn't give me any food so i pooped on the floor.
    Meow. Meow for food, then when human fills food dish, take a few bites of food and continue meowing cat fur is the new black cat fur is the new black , cough hairball, eat toilet paper grab pompom in mouth and put in water dish for stare out cat door
    then go back inside i love cats i am one wake up scratch humans leg for food then purr then i have a and relax. Annoy kitten brother with poking. Curl up and sleep on the freshly laundered towels eat too much then proceed to regurgitate all over living
    room carpet while humans eat dinner, for sit on human sleep everywhere, but not in my bed i show my fluffy belly but it's a trap! if you pet it i will tear up your hand and sit on human they not getting up ever. Mewl for food at 4am x intently sniff
    hand cat milk copy park pee walk owner escape bored tired cage droppings sick vet vomit but show belly nyan fluffness ahh cucumber! so you call this cat food. Meowing chowing and wowing then cats take over the world for chase ball of string for being
    gorgeous with belly side up. Why use post when this sofa is here milk the cow or favor packaging over toy pet my belly, you know you want to; seize the hand and shred it!. Sniff sniff chew on cable stare at owner accusingly then wink for eat the rubberband,
    asdflkjaertvlkjasntvkjn (sits on keyboard) the door is opening! how exciting oh, it's you, meh. Eat prawns daintily with a claw then lick paws clean wash down prawns with a lap of carnation milk then retire to the warmest spot on the couch to claw
    at the fabric before taking a catnap. Poop in a handbag look delicious and drink the soapy mopping up water then puke giant foamy fur-balls hide head under blanket so no one can see hate dog, so human give me attention meow i can haz. Behind the couch
    climb leg, so sun bathe. Ask to be pet then attack owners hand sleep on dog bed, force dog to sleep on floor lies down , for rub butt on table. Mew chase ball of string so scratch at fleas, meow until belly rubs, hide behind curtain when vacuum cleaner
    is on scratch strangers and poo on owners food, yet intently stare at the same spot, yet plays league of legends mesmerizing birds for cat jumps and falls onto the couch purrs and wakes up in a new dimension filled with kitty litter meow meow yummy
    there is a bunch of cats hanging around eating catnip . Scratch at fleas, meow until belly rubs, hide behind curtain when vacuum cleaner is on scratch strangers and poo on owners food my left donut is missing, as is my right but give me some of your
    food give me some of your food give me some of your food meh, i don't want it i is not fat, i is fluffy, but i like big cats and i can not lie, but lick face hiss at owner, pee a lot, and meow repeatedly scratch at fence purrrrrr eat muffins and poutine
    until owner comes back. Lick sellotape find empty spot in cupboard and sleep all day destroy the blinds and stare at owner accusingly then wink ccccccccccccaaaaaaaaaaaaaaatttttttttttttttttssssssssssssssss but kitty pounce, trip, faceplant you didn't
    see that no you didn't definitely didn't lick, lick, lick, and preen away the embarrassment for mesmerizing birds. Shove bum in owner's face like camera lens Gate keepers of hell or i heard this rumor where the humans are our owners, pfft, what do
    they know?!.
  </p>
</div>
0 голосов
/ 01 апреля 2020

Я думаю, вы можете посмотреть, как это решается в bootstrap. Боковая панель вообще не расширяется. Посмотрите, из чего они состоят, и когда использовать классы:

  • контейнер Этот класс должен иметь ширину dunami c в зависимости от настроек @mediaquery.

  • строка, вам также нужно сделать что-то, чтобы отделить строки. Прочитайте, как работает класс строк.

В общем, сама документация bootstrap относится к странице: https://css-tricks.com/snippets/css/a-guide-to-flexbox/#flexbox -background

Там у вас есть топи c, объясненная на чистом CSS - и это, вероятно, то, что вы имеете в виду ...

Пример сетки с использованным медиазапросом

<style>
.left, .right {
  float: left;
  width: 20%; /* The width is 20%, by default */
}

.main {
  float: left;
  width: 60%; /* The width is 60%, by default */
}

/* Use a media query to add a breakpoint at 800px: */
@media screen and (max-width: 800px) {
  .left, .main, .right {
    width: 100%; /* The width is 100%, when the viewport is 800px or smaller */
  }
}
</style> 
...