컨테이너 요소 상단에 인라인 블록 DIV 정렬
두 개의 inline-block
div
높이가 다른 경우 왜 두 개의 짧은 것이 컨테이너의 상단에 맞지 않습니까? ( 데모 ) :
.container {
border: 1px black solid;
width: 320px;
height: 120px;
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
div
용기 상단에 작은 것을 어떻게 정렬 할 수 있습니까?
vertical-align
이 기본 으로 기본 설정되어 있기 때문 입니다 .
vertical-align:top
대신 사용하십시오 :
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align:top;
}
http://jsfiddle.net/Lighty_46/RHM5L/9/
또는 @ f00644 는 float
하위 요소 에도 적용 할 수 있다고 말했습니다 .
vertical-align
두 개의 자식 div에 속성 을 추가해야합니다 .
.small
항상 짧은 경우 속성을에 적용하면됩니다 .small
. 하나가 가장 높은이 될 수 있다면 그러나, 당신은 모두 재산 적용해야합니다 .small
및 .big
.
.container{
border: 1px black solid;
width: 320px;
height: 120px;
}
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align: top;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
vertical-align: top;
}
Vertical align affects inline or table-cell box's, and there are a large nubmer of different values for this property. Please see https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align for more details.
<style type="text/css">
div {
text-align: center;
}
.img1{
width: 150px;
height: 150px;
border-radius: 50%;
}
span{
display: block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type='password' class='secondInput mt-4 mr-1' placeholder="Password">
<span class='dif'></span>
<br>
<button>ADD</button>
</div>
<script type="text/javascript">
$('button').click(function() {
$('.dif').html("<img/>");
})
Add overflow: auto to the container div. http://www.quirksmode.org/css/clearing.html This website shows a few options when having this issue.
참고URL : https://stackoverflow.com/questions/22092724/align-inline-block-divs-to-top-of-container-element
'Programming' 카테고리의 다른 글
API와 SDK의 차이점 (0) | 2020.05.19 |
---|---|
IISExpress는 원격 컴퓨터에서 503 오류를 반환합니다 (0) | 2020.05.19 |
Atom에서 들여 쓰기 모드를 변경하는 방법은 무엇입니까? (0) | 2020.05.19 |
발생하기 전에 취소 / kill window.setTimeout () (0) | 2020.05.19 |
git reset --hard origin / master의 의미는 무엇입니까? (0) | 2020.05.19 |