2015-04-27 13 views
5

Przygotowuję dzienny widok planisty i mam problem z jego sformatowaniem. Oto kod mam poniżej:Nie można uzyskać% szerokości do pracy na tabeli div

CSS

.responsive-calendar .controls { 
    color: #666; 
    font-weight: normal; 
    font-size: 18px; 
    font-family: "Open Sans",Arial,Verdana,sans-serif; 
    text-align: left; 
} 

.responsive-calendar .controls a { 
    cursor: pointer; 
} 

.responsive-calendar .controls h4 { 
    display: inline; 
} 

.responsive-calendar .day-headers, .responsive-calendar .days, .responsive-calendar .timeslots { 
    font-size: 0; 
} 

.responsive-calendar .header { 
    background-color: #f3f2f2 !important; 
    box-shadow: 0px 1px 0px 0px rgb(255, 255, 255) inset; 
    color: rgb(102, 102, 102); 
    font-size: 13px; 
    line-height: 18px; 
    padding: 10px 0px; 
    font-weight: bold; 
    cursor:default !important; 
} 

/* Daily Planner CSS */ 
.responsive-calendar .timeslot { 
    height:auto; 
    display:flex; 
    display:-webkit-flex; 
    flex-flow: row column; 
    -webkit-flex-flow: row column; 
} 

.responsive-calendar .hour { 
    display: inline-block; 
    position: relative; 
    font-size: 10px; 
    border:1px solid rgb(221, 221, 221); 
    width: 10%; 
    text-align: center; 
    flex: 1 1 100%; 
    -webkit-flex:1 1 100%; 
} 

.responsive-calendar .appts { 
    height:auto; 
    display:flex; 
    display:-webkit-flex; 
    width: 900%; 
    flex-flow: row column; 
    -webkit-flex-flow: row column; 
} 

.responsive-calendar .appt { 
    background-color:#CCC; 
    display: inline-block; 
    position: relative; 
    font-size: 10px; 
    border:1px solid rgb(221, 221, 221); 
    width: 90%; 
    text-align: center; 
    flex: 1 1 100%; 
    -webkit-flex:1 1 100%; 
} 

.responsive-calendar .appt a { 
    color: #000000; 
    display: block; 
    cursor: pointer; 
    padding: 5% 0 5% 0; 
} 

.responsive-calendar .timesection { 
    display: inline-block; 
    position: relative; 
    font-size: 10px; 
    border:1px solid rgb(221, 221, 221); 
    text-align: center; 
    flex: 1 1 100%; 
    -webkit-flex:1 1 100%; 
} 

.responsive-calendar .timesection:hover { 
    background-color: rgb(227, 235, 253); 
    cursor: pointer; 
    text-decoration: none; 
} 

.responsive-calendar .timesection a { 
    color: #000000; 
    display: block; 
    cursor: pointer; 
    padding: 3% 0 3% 0; 
} 

.responsive-calendar .timesection a:hover { 
    /* background-color: #eee; */ 
    text-decoration: none; 
} 

.responsive-calendar .timesection.header { 
    border-bottom: 1px gray solid; 
} 

.responsive-calendar .timesection.active { 
    background-color: rgb(209, 206, 224); 
} 

.responsive-calendar .timesection.active:hover { 
    background-color: rgb(227, 235, 253); 
} 

.responsive-calendar .timesection.not-current { 
    background-color: rgb(205, 205, 205); 
    cursor:default; 
} 

HTML

<div class="responsive-calendar"> 
    <div class="controls"> 
     <img src="images/left_16.png" /> 
     <?php echo date("M d, Y", mktime(0,0,0,$cMonth,$cDay,$cYear)); ?> 
     <img src="images/right_16.png" /> 
     <a style="padding-left:15px;">Today</a> 
     <a style="padding-left:15px;">Monthly View</a> 
    </div> 
    <div class="day-headers"> 
     <div class="hour header"><strong>Times</strong></div> 
     <div class="appt header"><strong>Appointments</strong></div> 
    </div> 
    <div class="timeslots"> 
     <div class="timeslot"> 
      <div class="timesection hour">10:00am</div> 
      <div class="timesection appt">Test 1</div> 
     </div> 
     <div class="timeslot"> 
      <div class="timesection hour">11:00am</div> 
      <div class="timesection appt">Test 2</div> 
      <div class="timesection appt">Test 3</div> 
     </div> 
     <div class="timeslot"> 
      <div class="timesection hour">12:00pm</div> 
      <div class="appts"> 
       <div class="timesection appt">Hack Result 1</div> 
      </div> 
     </div> 
     <div class="timeslot"> 
      <div class="timesection hour">12:00pm</div> 
      <div class="appts"> 
       <div class="timesection appt">Hack Result 2</div> 
       <div class="timesection appt">Hack Result 3</div> 
      </div> 
     </div> 
    </div> 
</div> 

Oto JSFiddle demo.

Więc w wersji demonstracyjnej chcę uzyskać zhakowany wynik (ostatnie 2 wiersze tabeli div).

Używam bootstrap 3.3.4 i dołączonego CSS do stylu strony. Nie mam pewności, dlaczego nie mogę uzyskać poprawnego wyrównania wierszy nagłówka według procentów (10%, 90%), ale poniższe elementy div nie chcą się zgadzać poniżej.

W wyniku ataku hakerskiego dodałem tylko inną klasę, wyliczono i zawyżono ją do 900%, a to zbliża się do tego, co chciałem. Ale chcę, żeby to zostało zrobione właściwie i aby zrozumieć, dlaczego to nie działa tak, jak miałem nadzieję.

Zawsze chcę mieć 10% dostępnej szerokości, a następnie uzyskać 90% dostępnej szerokości. Jeśli jest więcej niż jeden .appt, wtedy równomiernie dzielą szerokość 90%.

+2

Po prostu nie interesuje Cię, czy istnieje jakikolwiek powód, dla którego nie używasz rzeczywistej "tabeli" dla tych informacji (są to dane tabelaryczne)? –

+0

@HiddenHobbes - Chcę, żeby to wyglądało dobrze na komórkach i dobrze się skalowało. Zrobiłem to przy stole i po prostu nie skaluje się prawidłowo, a przynajmniej nie mogłem go skalować. –

+2

@DavidAvellan Przygotowanie do pracy na urządzeniach mobilnych i skalowanie poprawnie powinno być * łatwiejsze * z tabelami niż z divami, imo. –

Odpowiedz

3

Jak o tym:

.responsive-calendar .controls { 
 
    color: #666; 
 
    font-weight: normal; 
 
    font-size: 18px; 
 
    font-family: "Open Sans", Arial, Verdana, sans-serif; 
 
    text-align: left; 
 
} 
 
.responsive-calendar .controls a { 
 
    cursor: pointer; 
 
} 
 
.responsive-calendar .day-headers, 
 
.responsive-calendar .days, 
 
.responsive-calendar .timeslots { 
 
    font-size: 0; 
 
} 
 
.responsive-calendar .header { 
 
    background-color: #f3f2f2 !important; 
 
    box-shadow: 0px 1px 0px 0px rgb(255, 255, 255) inset; 
 
    color: rgb(102, 102, 102); 
 
    font-size: 13px; 
 
    line-height: 18px; 
 
    padding: 10px 0px; 
 
    font-weight: bold; 
 
    cursor: default !important; 
 
} 
 
.responsive-calendar .hour { 
 
    font-size: 10px; 
 
    border: 1px solid rgb(221, 221, 221); 
 
    width: 10%; 
 
    text-align: center; 
 
    max-width: 10%; 
 
    float: left; 
 
} 
 
.responsive-calendar .appts { 
 
    height: auto; 
 
    display: flex; 
 
} 
 
.responsive-calendar .appt { 
 
    background-color: #CCC; 
 
    font-size: 10px; 
 
    border: 1px solid rgb(221, 221, 221); 
 
    text-align: center; 
 
} 
 
.responsive-calendar .appt a { 
 
    color: #000000; 
 
    display: block; 
 
    cursor: pointer; 
 
    padding: 5% 0 5% 0; 
 
} 
 
.responsive-calendar .timesection { 
 
    display: inline-block; 
 
    position: relative; 
 
    font-size: 10px; 
 
    border: 1px solid rgb(221, 221, 221); 
 
    text-align: center; 
 
    flex: 1 1 100%; 
 
    -webkit-flex: 1 1 100%; 
 
} 
 
.responsive-calendar .timesection:hover { 
 
    background-color: rgb(227, 235, 253); 
 
    cursor: pointer; 
 
    text-decoration: none; 
 
} 
 
.responsive-calendar .timesection a { 
 
    color: #000000; 
 
    display: block; 
 
    cursor: pointer; 
 
    padding: 3% 0 3% 0; 
 
} 
 
.responsive-calendar .timesection a:hover { 
 
    text-decoration: none; 
 
} 
 
.responsive-calendar .timesection.header { 
 
    border-bottom: 1px gray solid; 
 
} 
 
.responsive-calendar .timesection.active { 
 
    background-color: rgb(209, 206, 224); 
 
} 
 
.responsive-calendar .timesection.active:hover { 
 
    background-color: rgb(227, 235, 253); 
 
} 
 
.responsive-calendar .timesection.not-current { 
 
    background-color: rgb(205, 205, 205); 
 
    cursor: default; 
 
} 
 
.appt { 
 
    max-width: 100%; 
 
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> 
 

 
<div class="responsive-calendar"> 
 
    <div class="controls"> 
 
    <img src="images/left_16.png" /> 
 
    <?php echo date("M d, Y", mktime(0,0,0,$cMonth,$cDay,$cYear)); ?> 
 
    <img src="images/right_16.png" /> <a style="padding-left:15px;">Today</a> 
 
    <a style="padding-left:15px;">Monthly View</a> 
 

 
    </div> 
 
    <div class="day-headers"> 
 
    <div class="hour header"><strong>Times</strong> 
 
    </div> 
 
    <div class="appt header"><strong>Appointments</strong> 
 
    </div> 
 
    </div> 
 
    <div class="timeslots"> 
 
    <div class="timeslot"> 
 
     <div class="timesection hour">10:00am</div> 
 
     <div class="appts"> 
 

 
     <div class="timesection appt">Test 1</div> 
 
     </div> 
 
    </div> 
 
    <div class="timeslot"> 
 
     <div class="timesection hour">11:00am</div> 
 
     <div class="appts"> 
 
     <div class="timesection appt ">Test 2</div> 
 
     <div class="timesection appt ">Test 3</div> 
 
     </div> 
 
    </div> 
 
    <div class="timeslot"> 
 
     <div class="timesection hour">12:00pm</div> 
 
     <div class="appts"> 
 
     <div class="timesection appt">Hack Result 1</div> 
 
     </div> 
 
    </div> 
 
    <div class="timeslot"> 
 
     <div class="timesection hour">12:00pm</div> 
 
     <div class="appts"> 
 
     <div class="timesection appt">Hack Result 2</div> 
 
     <div class="timesection appt">Hack Result 3</div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

Co robiłem:

HTML:

  • owinięte elementy, które mają .timesection .appt z div.appts.

CSS:

  • całkowicie usunięte .responsive-calendar .timeslot css.

  • Usunięto display:inline-block;, position:relative; i dodano float:left; do .responsive-calendar .hour.

  • Usunięto display:-webkit-flex;, width: 900%;, flex-flow: row column;, -webkit-flex-flow: row column; od .responsive-calendar .appts.

  • Usunięto flex, width, position i display z .responsive-calendar .appt.

  • Na koniec dodaje .apptmax-width: 100%;

znaleźć również example pen.

+2

Musisz umieścić 'bootstrap.min.css' gdzieś w swoim fragmencie kodu. –

+0

Dzięki za napiwek, jest teraz dołączony. – cch

+0

OK, więc jest to krok we właściwym kierunku, ale wciąż istnieje jeden problem. Jeśli appt div jest wyższy (dodaj
lub dwa), to appt div i appts div rozciąga się odpowiednio, ale div godzina nie. Chciałbym, żeby wszyscy razem się skalowali. Oto przykład tego, co mam na myśli używając nowego kodu: https://jsfiddle.net/davellan/ndv51kqz/ –

Powiązane problemy