[Bootstrap v5.0] 플렉스를 이용한 요소 배치 방법(d-flex)
"d-flex"는 `<div>` 태그 내부의 요소들을 인라인으로 배치시키는 기능을 가지고 있다. `<a>` 태그로 다른 태그를 감싸게 되면 인라인 판정이 감싼 태그 전체로 적용되지만, 이를 막기 위해 `<a>` 태그를 `<div>` 내부에 위치시켜 원하는 레이아웃을 설정할 수 있다.
Apr 12, 2024
d-flex란??
d-flex는 해당
<div>
태그 내부의 요소들을 in-line으로 배치시켜준다.예시 코드1
<div class="card d-flex"> <div th:each="orderItem : ${order.orderItemDtoList}" class="d-flex mb-3"> <a th:href="'/item/' +${orderItem.itemId}" class="text-dark"> <div class="repImgDiv"> <img th:src="${orderItem.imgUrl}" class="rounded repImg" th:alt="${orderItem.itemNm}"> </div> <div class="align-self-center w-75"> <span th:text="${orderItem.itemNm}" class="fs24 font-weight-bold"></span> <div class="fs18 font-weight-light"> <span th:text="${orderItem.orderPrice} +'원'"></span> <span th:text="${orderItem.count} +'개'"></span> </div> </div> </a> </div> </div>
![notion image](https://inblog.ai/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252Fbf922eab-7f14-4cda-aa72-1e3c0f530cdd%252F669f9299-bba3-4455-86da-c9f184e79f5b%252FUntitled.png%3Ftable%3Dblock%26id%3Dc903c9fa-8df1-48ad-a3a6-098541bcb42f%26cache%3Dv2&w=3840&q=75)
위 코드를 실행할 경우
<a>
태그로 다른 태그를 감싸게 되면 in-line 판정이 감싼 태그 전체로 적용된다.예시 코드2
<div class="card d-flex"> <div th:each="orderItem : ${order.orderItemDtoList}" class="d-flex mb-3"> <div class="repImgDiv"> <a th:href="'/item/' +${orderItem.itemId}" class="text-dark"> <img th:src="${orderItem.imgUrl}" class="rounded repImg" th:alt="${orderItem.itemNm}"> </a> </div> <div class="align-self-center w-75"> <a th:href="'/item/' +${orderItem.itemId}" class="text-dark"> <span th:text="${orderItem.itemNm}" class="fs24 font-weight-bold"></span> <div class="fs18 font-weight-light"> <span th:text="${orderItem.orderPrice} +'원'"></span> <span th:text="${orderItem.count} +'개'"></span> </div> </a> </div> </div> </div>
![notion image](https://inblog.ai/_next/image?url=https%3A%2F%2Fwww.notion.so%2Fimage%2Fhttps%253A%252F%252Fprod-files-secure.s3.us-west-2.amazonaws.com%252Fbf922eab-7f14-4cda-aa72-1e3c0f530cdd%252F07e64f6c-cf5f-4549-845a-0919d51b2672%252FUntitled.png%3Ftable%3Dblock%26id%3D4fd55579-7ed7-4319-9b2a-2e90a049e4b7%26cache%3Dv2&w=3840&q=75)
이를 막기 위해
<a>
태그를 <div>
내부에 위치시켜서 원하는 레이아웃을 설정할 수 있다.Share article