CSS页面分页样式

huangapple go评论74阅读模式
英文:

CSS Page Pagination Style

问题

以下是翻译好的内容:

CSS 样式概述

我正在尝试设计一个 CSS 样式,其中左侧包括客户部分,右侧包括选定的客户详细信息,并在底部放置分页按钮。您可以参考图片以进行可视化。

尝试实现的目标

我的目标是在客户容器内启用滚动,以便内容可以根据需要扩展。但是,我希望分页按钮始终可见,即使滚动时也保持在页面底部。请给我一个实现这种布局的想法。

使用 Chakra UI 与 Next.js。

import { Flex, Heading, Input, InputGroup, Stack, Text, Avatar, Box, Center, Divider } from "@chakra-ui/react";
import ContentHeader from "./design/ContentHeader";
import WhiteButton from "./design/WhiteButton";

export default function Customers() {
  return (
    <Flex width="100%" flexDir="column" gap="1rem" height="100%">
      <ContentHeader description="" heading="Total Customers (50)" />
      <Flex gap="0.1rem">
        <CustomersList />
        <Flex flex={1} bg="var(--grey-color)" rounded="lg" height={'auto'} justifyContent={'center'}>
            <Flex py = {'2rem'} flexDir={'column'} alignContent={'center'} gap={'1rem'}>
                <Center>
                    <Avatar size="xl" name="Kent Dodds" src="link" />
                </Center>
                <Center flexDir={'column'}>
                    <Heading fontSize={'xl'}>Kent C Dodds</Heading>
                    <Text fontSize={'sm'}>Owner at Corsa Auto Rentals</Text>
                </Center>

                <Divider color={'white'}/>

                <Center flexDir={'column'}>
                    <Heading fontSize={'xl'}>Email Address</Heading>
                    <Text fontSize={'md'}>ethan@ethanduran.com</Text>
                </Center>

                <Center gap={'1rem'} flexWrap={'wrap'}>
                    <WhiteButton>Message</WhiteButton>
                    <WhiteButton>Edit</WhiteButton>
                    <WhiteButton>Documents</WhiteButton>
                </Center>
            </Flex>
        </Flex>
      </Flex>
      {/*pagination bar*/}
      <WhiteButton>pagination button 1</WhiteButton>
      <WhiteButton>pagination button 2</WhiteButton>
    </Flex>
  );
}

const CustomersList = () => {
  return (
    <Flex flex={3} width={'100%'}>
      <Stack spacing={4} padding="1rem" width={'100%'} maxH={'100%'}>
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
        <CustomerData />
      </Stack>
    </Flex>
  );
}

const CustomerData = ({ }) => {
  return (
    <Flex
      background="var(--grey-color)"
      padding="1rem"
      gap="1.5rem"
      flexDir="row"
      rounded="lg"
      overflowX="auto"
    >
      <Avatar size="md" name="Kent Dodds" src="link" />
      <Stack spacing={0}>
        <Text fontSize="lg" whiteSpace="nowrap">
          Kent C Dodds
        </Text>
        <Text fontSize="xs" whiteSpace="nowrap">
          +92 311 628****
        </Text>
      </Stack>

      <Flex gap="1rem" marginLeft="auto">
        {["Vehicles", "Payments", "Referrals"].map((title, idx) => {
          return (
            <Stack key={idx} spacing={0} textAlign="center">
              <Text fontWeight="bold">{title}</Text>
              <Text fontWeight="bold">20</Text>
            </Stack>
          );
        })}
      </Flex>
    </Flex>
  );
}

代码链接

CSS页面分页样式

英文:

CSS Style Overview

I'm attempting to design a CSS style that includes a customer section on the left side, the selected customer details on the right side, and pagination buttons at the bottom. You can refer to the image for visualization.

Try to achive

>My goal is to enable scrolling within the customer container so that the content can expand as needed. However, I want the pagination buttons to always remain visible beneath the customer container, even when scrolling, and stay at the bottom of the page. please give me an idea how can i achive this kind of layout.

===========================
=                    |  u =
=                    |  s =
=   N Customers      |  e =
=                    |  r =
= pagination Buttons |    =
===========================

Using chakra ui with next-js.

import { Flex, Heading, Input, InputGroup, Stack, Text, Avatar, Box, Center, Divider } from &quot;@chakra-ui/react&quot;;
import ContentHeader from &quot;./design/ContentHeader&quot;;
import WhiteButton from &quot;./design/WhiteButton&quot;;

export default function Customers() {
  return (
    &lt;Flex width=&quot;100%&quot; flexDir=&quot;column&quot; gap=&quot;1rem&quot; height=&quot;100%&quot;&gt;
      &lt;ContentHeader description=&quot;&quot; heading=&quot;Total Customers (50)&quot; /&gt;
      &lt;Flex gap=&quot;0.1rem&quot;&gt;
        &lt;CustomersList /&gt;
        &lt;Flex flex={1} bg=&quot;var(--grey-color)&quot; rounded=&quot;lg&quot; height={&#39;auto&#39;} justifyContent={&#39;center&#39;}&gt;
            &lt;Flex py = {&#39;2rem&#39;} flexDir={&#39;column&#39;} alignContent={&#39;center&#39;} gap={&#39;1rem&#39;}&gt;
                &lt;Center&gt;
                    &lt;Avatar size=&quot;xl&quot; name=&quot;Kent Dodds&quot; src=&quot;link&quot; /&gt;
                &lt;/Center&gt;
                &lt;Center flexDir={&#39;column&#39;}&gt;
                    &lt;Heading fontSize={&#39;xl&#39;}&gt;Kent C Dodds&lt;/Heading&gt;
                    &lt;Text fontSize={&#39;sm&#39;}&gt;Owner at Corsa Auto Rentals&lt;/Text&gt;
                &lt;/Center&gt;

                &lt;Divider color={&#39;white&#39;}/&gt;

                &lt;Center flexDir={&#39;column&#39;}&gt;
                    &lt;Heading fontSize={&#39;xl&#39;}&gt;Email Address&lt;/Heading&gt;
                    &lt;Text fontSize={&#39;md&#39;}&gt;ethan@ethanduran.com&lt;/Text&gt;
                &lt;/Center&gt;

                &lt;Center gap={&#39;1rem&#39;} flexWrap={&#39;wrap&#39;}&gt;
                    &lt;WhiteButton&gt;Message&lt;/WhiteButton&gt;
                    &lt;WhiteButton&gt;Edit&lt;/WhiteButton&gt;
                    &lt;WhiteButton&gt;Documents&lt;/WhiteButton&gt;
                &lt;/Center&gt;
            &lt;/Flex&gt;
        &lt;/Flex&gt;
      &lt;/Flex&gt;
      {/*pagination bar*/}
      &lt;WhiteButton&gt;pagination button 1&lt;/WhiteButton&gt;
      &lt;WhiteButton&gt;pagination button 2&lt;/WhiteButton&gt;
    &lt;/Flex&gt;
  );
}

const CustomersList = () =&gt; {
  return (
    &lt;Flex flex={3} width={&#39;100%&#39;}&gt;
      &lt;Stack spacing={4} padding=&quot;1rem&quot; width={&#39;100%&#39;} maxH={&#39;100%&#39;}&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
        &lt;CustomerData /&gt;
      &lt;/Stack&gt;
    &lt;/Flex&gt;
  );
}

const CustomerData = ({ }) =&gt; {
  return (
    &lt;Flex
      background=&quot;var(--grey-color)&quot;
      padding=&quot;1rem&quot;
      gap=&quot;1.5rem&quot;
      flexDir=&quot;row&quot;
      rounded=&quot;lg&quot;
      overflowX=&quot;auto&quot;
    &gt;
      &lt;Avatar size=&quot;md&quot; name=&quot;Kent Dodds&quot; src=&quot;link&quot; /&gt;
      &lt;Stack spacing={0}&gt;
        &lt;Text fontSize=&quot;lg&quot; whiteSpace=&quot;nowrap&quot;&gt;
          Kent C Dodds
        &lt;/Text&gt;
        &lt;Text fontSize=&quot;xs&quot; whiteSpace=&quot;nowrap&quot;&gt;
          +92 311 628****
        &lt;/Text&gt;
      &lt;/Stack&gt;

      &lt;Flex gap=&quot;1rem&quot; marginLeft=&quot;auto&quot;&gt;
        {[&quot;Vehicles&quot;, &quot;Payments&quot;, &quot;Referrals&quot;].map((title, idx) =&gt; {
          return (
            &lt;Stack key={idx} spacing={0} textAlign=&quot;center&quot;&gt;
              &lt;Text fontWeight=&quot;bold&quot;&gt;{title}&lt;/Text&gt;
              &lt;Text fontWeight=&quot;bold&quot;&gt;20&lt;/Text&gt;
            &lt;/Stack&gt;
          );
        })}
      &lt;/Flex&gt;
    &lt;/Flex&gt;
  );
}

code link

CSS页面分页样式

答案1

得分: 1

在您分享的代码中,无法获取分页组件。

但是可以通过将 display: flex; flex-direction: column; 应用于包裹 &lt;List /&gt;&lt;Pagination/&gt; 组件的包装器 div(例如 .list)来实现此目的。

如果列表有时可能较小,并且您希望分页栏始终位于页面底部,请将 flex:grow: 1; 添加到包装器 div(.list)中的 &lt;List /&gt;&lt;Pagination /&gt;

查看我创建的类似结构的 JSFiddle,其中包括列表较小的情况: https://jsfiddle.net/4zqvny5f/2/

英文:

In Your shared code, could not get the pagination component.

However this can be achived by applying display: flex; flex-direction: column; to the wrapper div (say .list) of &lt;List /&gt; and &lt;Pagination/&gt; component.

And if the list can be smaller sometimes and you want the pagination bar to always be at the bottom of the page, add flex:grow: 1; to the wrapper div (.list) of &lt;List /&gt; and &lt;Pagination /&gt;

Checkout the similar structured JSFiddle I created. Including the case when list is small: https://jsfiddle.net/4zqvny5f/2/

答案2

得分: 0

解决你的问题的是CSS中的position: fixed;。假设你的分页栏是div.bar,请添加以下CSS规则集:

div.bar {
  position: fixed;
  bottom: 0;
  height: 20px;
  left: 100px;
  right: 100px;
}

当然,这只是一个概念验证/示例,你可以根据需要更改这些值。

英文:

What solves your problem is the position: fixed; in CSS.
Supposing that your pagination bar is div.bar, add to it the following CSS ruleset:

div.bar {
  position: fixed;
  bottom: 0;
  height: 20px;
  left: 100px;
  right: 100px;
}

For sure this is just a Proof of Concept / example, and you can change the values as you want.

huangapple
  • 本文由 发表于 2023年5月28日 02:08:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定