2023.04.21 css

홍왕열·2023년 4월 21일
0

CSS

목록 보기
6/6
post-thumbnail

box-sizing: border-box를 넣었는데 여기에 left에 border 3px를 넣었더니 text는 밀림.

그래서 중첩으로 쌓아야 됨.

코드

const GridRow = styled.div`
    position: relative;
    display: flex;
    width: 100%;
    align-items: center;
    /* border-color: yellow;
  border-style: solid; */
    border-bottom: gray solid 1px;
    /* height: calc(100% / 12); */
    height: 10%;
    background-color: ${palette.primary.gray};
    cursor: pointer;
    :hover {
        background-color: ${palette.gray[4]};
    }
    :active {
        background-color: ${palette.gray[5]};
        :before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 3px;
            background-color: ${palette.primary.blue};
        }
    }
`;

position: absolute 속성을 사용하여 GridRow 요소의 상위 요소를 기준으로 위치를 지정하고, left: 0 속성을 사용하여 왼쪽 끝에 위치하도록 한다.
그리고 top, bottom 속성을 사용하여 높이를 조절한다.

참고로, ::before와 같은 가상 요소를 사용할 때는 content 속성을 사용하여 반드시 콘텐츠를 지정해야 한다.
위 코드에서는 빈 문자열("")을 사용하여 콘텐츠를 지정하였다.

profile
코딩 일기장

0개의 댓글