2016-12-23 1 views
0

이전에 답변을 드렸던 경우 사과드립니다.수평으로 정렬 된 div 4 개를 작은 화면 크기에서 두 개로 나눕니다.

저는 가로로 정렬 된 div가 4 개 있습니다. 각각은 img와 텍스트가 들어 있습니다. 나는 화면 크기를 줄일 때

box box box box 

, 내가 중간에서 내려 분할이 원하는 나에게주는 :

box box 
box box 

을 대신 나는 현재 받고 있어요 무엇 :

box box box 
    box 

현재 화면 크기를 줄이면 2x2 크기로 쌓아서 아주 작은 화면 (이 경우 여전히 필요)에서 세로 레이아웃으로 분할합니다. 여기

JS 바이올린 : https://jsfiddle.net/zyrkstnk/

어떤 아이디어? 나는 & nbsp로 어지럽 혔지만 작동시키지 못했습니다. 감사!

+0

당신이 twitter- 사용할 수 있습니다 이것에 대한 부트 스트랩 – Banzay

+0

알아,하지만 한 페이지에 대한 wordpress & 나는 부트 스트랩을 사용하지 않으려는 나머지 사이트입니다. – ts123

+0

div에 2 개의 미리보기 이미지를 감 쌉니다. https://jsfiddle.net/zyrkstnk/1/ – pol

답변

0

#homethumbs { 
 
\t width: 100%; 
 
\t text-align: center; 
 
} 
 

 
.homethumb { 
 
\t width: 300px; 
 
} 
 
.homethumb, .wrap { 
 
\t display: inline-block; 
 
}
<div id="homethumbs"> 
 
    <div class="wrap"> 
 
     <div class="homethumb"> 
 
      <img src="http://placehold.it/250x250"> 
 
      <h2>Start here with the basics</h2> 
 
     </div> 
 
     <div class="homethumb"> 
 
      <img src="http://placehold.it/250x250"> 
 
      <h2>Start here with the basics</h2> 
 
     </div> 
 
    </div> 
 
    <div class="wrap"> 
 
     <div class="homethumb"> 
 
      <img src="http://placehold.it/250x250"> 
 
      <h2>Start here with the basics</h2> 
 
     </div> 
 
     <div class="homethumb"> 
 
      <img src="http://placehold.it/250x250"> 
 
      <h2>Start here with the basics</h2> 
 
     </div> 
 
    </div> 
 
</div>

+0

이것은 완벽하게 작동했습니다. 감사합니다! 왜 내가 그걸 미리 생각하지 않았는지 모르겠다. – ts123

+0

이 대답이 당신을 halp하면 투표 할 수있다. – Banzay

0

당신은 플렉스 시도해야합니다!

#homethumbs { 
    width: 100%; 
    text-align: center; 

    display: -webkit-box; 
    display: -moz-box; 
    display: -ms-flexbox; 
    display: -webkit-flex; 
    display: flex; 
    -ms-flex-flow: wrap; 
    -webkit-flex-flow: wrap; 
    flex-flow: wrap; 
} 

.homethumb { 
     flex: 0 0 50%; 
    -webkit-flex: 0 0 50%; 
    -ms-flex: 0 0 50%; 
} 

@media (min-width: 1000px){ 

    .homethumb { 
     flex: 0 0 25%; 
    -webkit-flex: 0 0 25%; 
    -ms-flex: 0 0 25%; 
    } 

} 

뷰포트 메타 태그를 넣는 것을 잊지 마십시오. 다음은이 결과의 비디오입니다. http://www.screencast.com/t/lYV6tFvhn9

+0

이것을 워드 프레스 사이트의 일부로 쉽게 사용할 수 있습니까? 나는 웹 개발에 익숙하지 않고 여전히이 모든 것들에 대한 나의 머리를 감싸고있다. – ts123

+0

그것을 사용해보십시오! 워드 프레스 인터페이스에서 스타일 시트를 찾으십시오. 모양/편집기에 있어야하며 style.css라고합니다. 그런 다음 두 요소를 찾아 위 스타일로 스타일을 덮어 씁니다. 뷰포트 태그가 이미 있어야합니다. 이 태그는 위의 @media를 사용할 수 있도록 화면 크기를 감지하는 데 사용됩니다. 그래서 그것이하는 일은 1000px보다 넓은 화면에서 작업하는 경우입니다. – Vcasso

+0

고마워요. 플렉스는 추가 스타일 시트를로드 할 필요가 없다 (부트 스트랩처럼)? – ts123

0

동일 장치 및 소형 장치에 대해 flex를 사용할 수 있습니다. 각 div의 너비를 50 %로 설정하고 flex-wrap을 설정할 수 있습니다.이 랩으로 2 * 2 그리드를 얻을 수 있습니다

확인이 조각은

#homethumbs { 
 
    display: flex; 
 
} 
 
@media (min-width: 200px) and (max-width: 1000px) { 
 
    #homethumbs { 
 
    flex-wrap: wrap; 
 
    width: 100vw; 
 
    border: 1px solid; 
 
    } 
 
    .homethumb { 
 
    width: 50vw; 
 
    } 
 
}
<div id="homethumbs"> 
 
    <div class="homethumb"> 
 
    <img src="http://placehold.it/250x250"> 
 
    <h2>Start here with the basics</h2> 
 
    </div> 
 

 

 

 

 

 
    <div class="homethumb"> 
 
    <img src="http://placehold.it/250x250"> 
 
    <h2>Start here with the basics</h2> 
 
    </div> 
 

 

 

 
    <div class="homethumb"> 
 
    <img src="http://placehold.it/250x250"> 
 
    <h2>Start here with the basics</h2> 
 
    </div> 
 

 

 

 
    <div class="homethumb"> 
 
    <img src="http://placehold.it/250x250"> 
 
    <h2>Start here with the basics</h2> 
 
    </div> 
 
</div>

희망이