2014-05-23 3 views
1

저는 지난 주에 html과 css에 대해 배우고 있으며 실제 프로젝트를 시작하기 전에 다양한 것을 시도하고 있습니다.가짜 열을 사용하지 않고 똑같이 긴 열 만들기

나는 조금 장난되었으며, 이것은 내가 지금까지 무엇을 가지고 : http://jsfiddle.net/94ZDm/1/ http://jsfiddle.net/94ZDm/1/embedded/result/

<!doctype html> 
<html> 
<head> 

    <title>My Website</title> 

    <meta charset="utf-8" /> 

    <link href="css/style.css" type="text/css" rel="stylesheet"/> 

</head> 

<body> 

<div class="container"> 

<div class="nav"> 
<ul id="navi"> 
    <li><a href="">Home</a></li> 
    <li><a href="">News</a></li> 
    <li><a href="">Archives</a></li> 
    <li><a href="">Links</a></li> 
    <li><a href="">About</a></li> 
</ul> 
</div> 

<div class="main-wrap"> 
    <div class="main1"> 
    <h1 id="top"> Hello World!!! </h1> 

     <p> First paragraph </p> 

     <h2> Things I Must Do Today</h2> 

      <ul> 
       <li> <a href="http://google.be" target="_blank" id="externallink"> Go to the mall </a> </li> 
       <li> Shop </li> 
       <li> Get gas</li> 
       <li> Drive home </li> 
      </ul> 

     <p><img src="img/koala.jpeg" alt="a koala sitting in a tree" align="left"/> 

      Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!</p> 

     <p> Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!</p> 

     <p> Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!</p> 

     <p> Text a lot of text! Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text! 
      Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!Text a lot of text!</p> 

     <p><a href="#top">Top</a></p> 
    </div> 
    <div class="main2"> 
     <p> extra navigation... </p> 
    </div> 
</div> 

<footer> 
    &copy; Copyright Blabla Land 2014 
</footer> 

</div> 

</body> 
</html> 

합니다.

* { 
-webkit-box-sizing: border-box; 
-moz-box-sizing: border-box; 
     box-sizing: border-box; 
} 

body { 
font-family: Arial, Verdana, sans-serif; 
background: green; 
} 

.container { 
width:960px; 
margin:0 auto; 
} 

.main-wrap { 
overflow: hidden; 
} 

.nav { 
margin-top: 20px; 
margin-bottom: 20px; 
padding: 10px; 
background-color: #efefef; 
border: 2px solid; 
border-radius: 20px; 
-moz-border-radius: 20px; 
-webkit-border-radius: 20px; 
} 

.main1 { 
float: left; 
width: 652px; 
margin-bottom: 10px; 
padding: 10px; 
background-color: #efefef; 
border: 2px solid; 
border-radius: 20px; 
-moz-border-radius: 20px; 
-webkit-border-radius: 20px; 
} 

.main2 { 
float: right; 
width: 288px; 
min-height: 1000px; 
margin-bottom: 10px; 
padding: 10px; 
background-color: #efefef; 
border: 2px solid; 
border-radius: 20px; 
-moz-border-radius: 20px; 
-webkit-border-radius: 20px; 
} 

footer { 
padding: 10px; 
background-color: #efefef; 
border: 2px solid; 
border-radius: 20px; 
-moz-border-radius: 20px; 
-webkit-border-radius: 20px; 

text-align: center; 
} 

#navi li { 
display: inline-block; 
list-style-type: none; 
margin-right: 25px; 
} 

#navi { 
text-align: center; 
} 

a:link { 
color: black; 
text-decoration: none; 
} 

a:visited { 
color:black; 
} 

a:hover { 
color: #229944; 
text-decoration: underline; 
} 

a:active { 
color:red; 
} 

#externallink { 
text-decoration: underline; 
} 

img { 
padding: 10px; 
} 

어떻게 내 콘텐츠 열이 동등하게 긴해야합니까 가짜 열을 사용하지 않고 (한 주 한만큼 있어야 오른쪽)? 가짜 열은 현재 레이아웃을 사용하지 못하게합니까? 나는 또한 지정된 높이를 사용하고 싶지 않다. 자동으로 내용에 적응해야한다.

미리 감사드립니다.

+0

하나의 게시물에 너무 많은 다른 질문이 있습니다. 한 번에 한 가지 질문을 스스로 제한하십시오. –

+0

죄송합니다. 몰랐습니다. 내 게시물을 수정했습니다. 건배! – bgrt

+0

나는 편집을 보지 못했기 때문에 아래의 나의 대답은 당신의 모든 3 가지 질문에 대한 답을 포함하고 있습니다. – Tarun

답변

0

는 CSS를 사용하여 그것을 을하는 방법 중 하나입니다 표 셀.

.main-wrap를 들어
.container { 
    width:960px; 
    margin:0 auto; 
    overflow: hidden; 
} 
.main-wrap { 
    display: table; 
    width: 980px; /* Container width + 2 x 10px */ 
    margin-bottom: 10px; 
    border: 1px dotted red; 
    border-spacing: 10px 0; 
} 
.nav { 
    margin-top: 20px; 
    margin-bottom: 20px; 
    padding: 10px; 
    background-color: #efefef; 
    border: 2px solid; 
    border-radius: 20px; 
    -moz-border-radius: 20px; 
    -webkit-border-radius: 20px; 
} 
.main1 { 
    display: table-cell; 
    width: 652px; 
    padding: 10px; 
    background-color: #efefef; 
    border: 2px solid; 
    border-radius: 20px; 
    -moz-border-radius: 20px; 
    -webkit-border-radius: 20px; 
} 
.main2 { 
    display: table-cell; 
    width: 288px; 
    padding: 10px; 
    background-color: #efefef; 
    border: 2px solid; 
    border-radius: 20px; 
    -moz-border-radius: 20px; 
    -webkit-border-radius: 20px; 
} 

display: table을 적용하고 display: table-cell 두 자식 요소 .main1.main2에 :

다음과 같이 CSS를 수정합니다.

기본적으로 두 자식 요소는 두 높이 중 큰 값으로 확장됩니다.

.main1.main2 사이의 간격을 가져 오려면 border-spacing: 10px 0을 적용하여 각 셀 주위에 10 픽셀의 가로 간격을 만듭니다. 이것은 또한 테이블의 전체 너비에 영향을 미치므로 두 셀이 의도 한 것보다 약간 좁습니다.

이를 해결하기 위해는 배, 즉 980 픽셀에 10px의 셀 간격을 더한 .container 의 폭을 .main-wrap 폭을 설정.

결과는 overflow: hidden을 사용하여 .container에 숨길 수있는 오버플로 상태입니다.

마지막으로 margin-left: -10px을 적용하여 테이블의 가운데 맞춤을 조정하십시오.

.main-wrapmargin-bottom: 10px을 사용하여 기본 요소와 바닥 글 사이에 공백을여십시오 (선택 사항). http://jsfiddle.net/audetwebdesign/b8Fy7/

+1

안녕하세요. 감사하다고 말하고 싶습니다. 이것은 큰 도움이되었습니다! 모든 것을 단계적으로 수행 했으므로 나는 더 잘 기억할 것입니다. 다시 한번 감사드립니다. – bgrt

0

1) 열을 똑같이 길게 만들려면 컨테이너 너비를 각 열 너비의 두 배로 변경하십시오. 두 번째 열의 너비를 첫 번째 열과 동일하게 설정하십시오. 높이를 자동으로 설정하려면 지정하지 마십시오. (

#container { 
width:1304px; 
margin:0 auto; 
} 

#main2 { 
float: right; 
width: 652px; 
margin-bottom: 10px; 
padding: 10px; 
background-color: #efefef; 
border: 2px solid; 
border-radius: 20px; 
-moz-border-radius: 20px; 
-webkit-border-radius: 20px; 
} 

2) 클래스와 ID는 모두 작동하지만 일반적으로 CSS는 선호됩니다. 아래의 바이올린에서는 레이아웃이 변경되지 않도록 id로 변경했습니다.

3) '#navi li'은 목록 자체를 말하며 '#navi li'은 목록의 각 목록 항목을 나타냅니다.

FIDDLE DEMO

+0

안녕하세요, 감사합니다. 확실히 도움이되었습니다. 건배. – bgrt

0

당신은 또한 당신이 내 텍스트의 크기를 변경할 때 두 가지 요소가 항상 같은 높이에도 수 있도록하려면 동적으로, jQuery를 사용하여 높이를 변경할 수 있습니다. 이 같은

뭔가 : 여기 http://jsfiddle.net/7TjfF/2/

jQuery(document).ready(function(){ 
    $hi1 = jQuery('#id1').height(); 
    $hi2 = jQuery('#id2').height(); 

    jQuery('#id2').css('min-height', $hi1); 
    jQuery('#id1').css('min-height', $hi2); 
}); 

그리고이 사이트에 구현 할 때 비슷한 기능이 작동하는 방법이다 : http://nidrax.eu/pl/about.php

+0

재미있는 것 같습니다, 감사합니다. 일단 내가 자바 스크립트에 도착하면 그것을 들여다 볼 것이다. 지금 나는 실제로 내가 완전히 이해할 수있는 무엇인가에 머무르고있다. 건배! – bgrt

0

가장 쉬운 방법 (작동 볼 브라우저 창 크기를 조절), 당신은 내 플러그인을 사용할 수 있습니다 : https://github.com/Masquerade-Circus/simpleEqualize.js.

그냥 proyect에 추가하고 다음과 같이 호출하면됩니다. 프로젝트가 응답하면

$(".main-wrap").simpleEqualize(true, 'div'); 

, 당신은 다음과 같이 호출 할 수 있습니다 :

$(window).resize(function(){ 
    $(".main-wrap").simpleEqualize(true, 'div'); 
}); 

또는 같은 setInterval을 가진

: 여기

setInterval(function(){ 
    $(".main-wrap").simpleEqualize(true, 'div'); 
},100); 
+0

나는이 자바 스크립트 또는 뭔가 정렬 가정합니다? 나는 아직 그곳에 가지 않고 있지만 배우기 시작하면 곧 시도 할 것입니다. 고맙습니다. – bgrt

0

그냥 몸의 종료 전에 차일 및 붙여 넣기 스크립트에 부모 래퍼 eqh 자녀에 eqh 부모 클래스를 적용에서

참조 데모. 이 코드는 재사용이 가능하며 크롬, FF, IE 8 이상에서 작동합니다.

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title>Faux Columns</title> 
    <style> 
    .eqh-parent .eqh-child{ 
     background: #efefef; 
     margin-bottom: 30px; 
     border-right: 1px solid #ccc; 
     padding: 0 30px; 
    } 
    .eqh-child:last-child{ 
     border-right: none; 
    } 
    body{ 
     padding: 30px 0px; 
    } 
    </style> 
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> 
    <script type="text/javascript" src="js/jquery.min.js"></script> 
    <!--[if lt IE 9]> 
     <script type="text/javascript" src="js/respond.min.js"></script> 
    <![endif]--> 
</head> 
<body> 
    <div class="container"> 
     <h3 align="center">Faux Columns</h3> 
     <div class="row eqh-parent"> 
      <div class="eqh-child col-xs-12 col-sm-3"> 
       <p> 
        Built on the trusted foundation of VMware vCloud- Air. Built.io customers now benefit from Mobile Backend-as-a-Service delivered via a pre-approved IT environment that meets enterprise requirements for compliance, security and SLAs through dedicated Built.io. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-3"> 
       <p> 
        AppGyver enables rapid, multi-platform development with tools for non-technical business users and developers alike. By combining the intuitive nature of AppGyver with the power of Built.io's backend, the two companies have joined forces to enable users to build a robust application with an enterprise backend in minutes. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-3"> 
       <p> 
        Xamarin is a major front-end player that lets developers create fully native apps for iOS and Android using C#. When combined with Built.io, developers get a complete, best-of-breed solution that allows them to rapidly build robust mobile and web applications powered by a platform built for enterprise. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-3"> 
       <p> 
        Student developers at Berkeley's Center for Entrepreneurship & Technology built complex, feature rich apps on top of Built.io, for the 2015 University Mobile Challenge. These bright, young minds are finding new and exciting ways to innovate on top of Built.io's pre-built features, such as intelligent push notifications, geolocation and real-time updates. 
       </p> 
      </div> 
     </div> 
     <div class="row eqh-parent"> 
      <div class="eqh-child col-xs-12 col-sm-4"> 
       <p> 
        Built on the trusted foundation of VMware vCloud- Air. Built.io customers now benefit from Mobile Backend-as-a-Service delivered via a pre-approved IT environment that meets enterprise requirements for compliance, security and SLAs through dedicated Built.io. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-4"> 
       <p> 
        AppGyver enables rapid, multi-platform development with tools for non-technical business users and developers alike. By combining the intuitive nature of AppGyver with the power of Built.io's backend, the two companies have joined forces to enable users to build a robust application with an enterprise backend in minutes. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-4"> 
       <p> 
        Xamarin is a major front-end player that lets developers create fully native apps for iOS and Android using C#. When combined with Built.io, developers get a complete, best-of-breed solution that allows them to rapidly build robust mobile and web applications powered by a platform built for enterprise. 
       </p> 
      </div> 
     </div> 
     <div class="row eqh-parent"> 
      <div class="eqh-child col-xs-12 col-sm-6"> 
       <p> 
        Built on the trusted foundation of VMware vCloud- Air. Built.io customers now benefit from Mobile Backend-as-a-Service delivered via a pre-approved IT environment that meets enterprise requirements for compliance, security and SLAs through dedicated Built.io. 
       </p> 
      </div> 
      <div class="eqh-child col-xs-12 col-sm-6"> 
       <p> 
        AppGyver enables rapid, multi-platform development with tools for non-technical business users and developers alike. By combining the intuitive nature of AppGyver with the power of Built.io's backend, the two companies have joined forces to enable users to build a robust application with an enterprise backend in minutes. 
       </p> 
      </div> 
     </div> 
     <div class="row eqh-parent"> 
      <div class="eqh-child col-xs-12"> 
       <p> 
        Built on the trusted foundation of VMware vCloud- Air. Built.io customers now benefit from Mobile Backend-as-a-Service delivered via a pre-approved IT environment that meets enterprise requirements for compliance, security and SLAs through dedicated Built.io. 
       </p> 
      </div> 
     </div> 
    </div> 
    <script type="text/javascript">  
     function setEqualHeight(){ 
      if($('.eqh-parent').length){ // check if .eqh-parent is available on document 
       $('.eqh-parent').each(function(){ 
        if($(this).children().outerWidth() == $(this).width()){ 
         $(this).children('.eqh-child').css('min-height', 0); 
        } 
        else{ 
         $(this).children('.eqh-child').css('min-height', 0); 
         var large = $(this).children('.eqh-child').map(function(){ 
          return $(this).height(); 
         }); 
         $(this).children('.eqh-child').css('min-height', large.sort(function(a, b){return b-a})[0]); // sort array in desc order and pick first element to get heighest element within array. 
        } 
       }); 
      } 
     } 

     $(window).on('resize', function(){ 
      setEqualHeight(); 
     }); 

     $(document).ready(function(){ 
      setTimeout(function(){ 
       setEqualHeight(); 
      }, 100); 
     }); 
    </script> 
</body> 
</html>