IT

부트 변형 유체 레이아웃에서 그리드 요소를 하단 정렬하는 방법

lottoking 2020. 7. 16. 07:53
반응형

부트 변형 유체 레이아웃에서 그리드 요소를 하단 정렬하는 방법


유동적 인 레이아웃을 가지고 있는데, 두 개의 열이있는 행이 있습니다. 첫 번째 열에는 많은 내용이 일반적으로 범위를 채우고 싶습니다. 두 번째 열에는 버튼과 일부 텍스트가 표시되며 첫 번째 열의 셀을 기준으로합니다.

내가 가진 것은 다음과 같다.

-row-fluid-------------------------------------
+-span6----------+ +-span6----------+
|                | |short content   |
| content        | +----------------+
| that           | 
| is tall        |    
|                |
+----------------+
-----------------------------------------------

내가 원하는 것은 다음과 같다.

-row-fluid-------------------------------------
+-span6----------+
|                |
| content        |
| that           | 
| is tall        | +-span6----------+    
|                | |short content   |
+----------------+ +----------------+
-----------------------------------------------

첫 번째 스팬을 절대 높이로 만들고 두 번째 스팬을 기준으로 배치하는 솔루션을 브라지만 div의 절대 높이를 절대 높이는 솔루션이 선호됩니다. 또한 동일한 효과를 얻는 방법을 완전히 다시 생각할 수 있습니다. 나는이 비계 사용과 결혼하지 갑자기 발생하는 것이 나에게 가장 의미가 것처럼 보였습니다.

바이올린 으로이 레이아웃 :

http://jsfiddle.net/ryansturmer/A7buv/3/


작동하는 솔루션 http://jsfiddle.net/jhfrench/bAHfj/참조하십시오 .

//for each element that is classed as 'pull-down', set its margin-top to the difference between its own height and the height of its parent
$('.pull-down').each(function() {
  var $this = $(this);
  $this.css('margin-top', $this.parent().height() - $this.height())
});

긍정적 인 내용에서는 :

  • 부트 기존의 기존 도우미 클래스의 정신으로 클래스 이름을 지정했습니다 pull-down.
  • "풀다운"되는 요소 만 분류하면 분류 ...
  • ... 다른 요소 (div, span, section, p 등)에 유형 가능
  • 상당히 잘 지원됩니다 (모든 주요 브라우저는 마진을 지원합니다)

지금 나쁜 소식 :

  • jQuery가 필요합니다.
  • 작성되지 않은 현상 반응이 없습니다 (죄송합니다)

이 CSS / LESS 만 사용하는 Bootstrap 3 (이전 버전에서는 작동해야 함)에 대한 업데이트 된 솔루션입니다.

http://jsfiddle.net/silb3r/0srp42pb/11/

당신은 행 (그렇지 당신은 열 사이 성가신 공간이 될 것), 다음 열 수레로 설정의 제거 제거에 0으로 글꼴 크기를 설정 inline-block한 후, 다시 설정 자신의 글꼴 크기를 사용하고 vertical-align수 있습니다.

jQuery가 필요하지 않습니다.


flex를 사용할 수 있습니다.

@media (min-width: 768px) {
  .row-fluid {
    display: flex;
    align-items: flex-end;
  }
}

span6다음과 같은 스타일을 추가해야 합니다.

.row-fluid .span6 {
  display: table-cell;
  vertical-align: bottom;
  float: none;
}

그리고 이것은 당신의 바이올린입니다 : http://jsfiddle.net/sgB3T/


이 기능을 구현하기 위해 angularjs 지시어도 있습니다.

    pullDown: function() {
      return {
        restrict: 'A',
        link: function ($scope, iElement, iAttrs) {
          var $parent = iElement.parent();
          var $parentHeight = $parent.height();
          var height = iElement.height();

          iElement.css('margin-top', $parentHeight - height);
        }
      };
    }

부모 display:flex;와 자녀를 로 설정하십시오 margin-top:auto. 부모 요소의 높이가 더 요소보다 크다고 가정하면 부모 요소의 맨 아래에 어떤 내용이 배치됩니다.

margin-top부모 요소에 높이가 있거나 부모 요소 내에서 관심있는 자식 요소보다 큰 다른 요소가있는 경우 값을 계산할 필요가 없습니다 .


여기에 다른 답변을 기반으로 훨씬 더 반응이 빠른 버전이 있습니다. 나는 Ivan의 버전에서 <768px 너비의 뷰포트를 지원하고 느린 창 크기 조정을 더 잘 지원하도록 변경했습니다.

!function ($) { //ensure $ always references jQuery
    $(function () { //when dom has finished loading
        //make top text appear aligned to bottom: http://stackoverflow.com/questions/13841387/how-do-i-bottom-align-grid-elements-in-bootstrap-fluid-layout
        function fixHeader() {
            //for each element that is classed as 'pull-down'
            //reset margin-top for all pull down items
            $('.pull-down').each(function () {
                $(this).css('margin-top', 0);
            });

            //set its margin-top to the difference between its own height and the height of its parent
            $('.pull-down').each(function () {
                if ($(window).innerWidth() >= 768) {
                    $(this).css('margin-top', $(this).parent().height() - $(this).height());
                }
            });
        }

        $(window).resize(function () {
            fixHeader();
        });

        fixHeader();
    });
}(window.jQuery);

이것은 cfx의 솔루션을 기반으로하지만, 표시로 인해 추가 된 열 간 공백을 제거하기 위해 부모 컨테이너에서 글꼴 크기를 0으로 설정하는 대신 : 인라인 블록을 재설정해야하고 간단히 추가했습니다.

.row.row-align-bottom > div {
    float: none;
    display: inline-block;
    vertical-align: bottom;
    margin-right: -0.25em;
}

보상하기 위해 열 div에.


글쎄, 나는 그 대답 중 어느 것도 마음에 들지 않았고, 같은 문제에 대한 나의 해결책은 이것을 추가하는 것이 었습니다 <div>&nbsp;</div>. 따라서 귀하의 계획에서는 다음과 같이 보일 것입니다 (다소), 제 경우에는 스타일 변경이 필요하지 않았습니다.

-row-fluid-------------------------------------
+-span6----------+ +----span6----------+
|                | | +---div---+       |
| content        | | | & nbsp; |       |
| that           | | +---------+       |
| is tall        | | +-----div--------+|   
|                | | |short content   ||
|                | | +----------------+|
+----------------+ +-------------------+
-----------------------------------------------

.align-bottom {
    position: absolute;
    bottom: 10px;
    right: 10px;
}

참고 URL : https://stackoverflow.com/questions/13841387/how-do-i-bottom-align-grid-elements-in-bootstrap-fluid-layout

반응형