2014-09-23 57 views
0

我不知道如何移動搜索字段與紅色矩形中的藍色按鈕是正確的「Поискмероприятий:」標籤?如何使用「div」和「css」重新組織頁面?

下面的代碼:

<style> 
    #header { 
     border: 4px solid red; 
     background-color:white; 
     color:black; 
     text-align:left; 
    } 
    #nav { 
     border: 4px solid green; 
     line-height:20px; 
     height:420px; 
     width:250px; 
     float:left; 
     padding:5px;   
    } 
    #section1 { 
     border: 4px solid blue; 
     width:700px; 
     float:left; 
     padding:5px;   
    } 
    #section2 { 
     border: 4px solid brown; 
     background-color: gainsboro; 
     width:700px; 
     float:right; 
     padding:5px;   
    } 
</style> 

<div id="header"> 
    <h2>Поиск мероприятий:</h2> 
    <div id="searchKeyword" class="input-group"> 
     <i class="glyphicon glyphicon-search input-group-addon"></i> 
     <input type="text" class="form-control" placeholder="Часть названия мероприятия" ng-model="actionsQuery.searchText" on-enter="queryResult()"> 
     <!--<span class="input-group-btn" ng-hide="!actionsQuery.searchText">--> 
     <span class="input-group-btn"> 
      <button class="btn btn-primary" type="button" ng-click="queryResult()">Найти мероприятия</button> 
     </span> 
    </div> 
</div> 

<div id="nav"> 
    ... 
</div> 

<div id="section1"> 
    ... 
</div> 

<div id="section2"> 
    ... 
</div> 

Screen shot It looks like this after I've added display: inline-block; I have the page as in screen shot attached.

+0

屏幕截圖在那裏。 – tesicg 2014-09-23 11:52:39

回答

0

使用CSS display: inline-block

#header h2, #searchKeyword{ 
     display:inline-block; 
    } 

#header { 
 
     border: 4px solid red; 
 
     background-color:white; 
 
     color:black; 
 
     text-align:left; 
 
    } 
 
    #header h2, #searchKeyword{ 
 
     display:inline-block; 
 
    } 
 
    #nav { 
 
     border: 4px solid green; 
 
     line-height:20px; 
 
     height:420px; 
 
     width:250px; 
 
     float:left; 
 
     padding:5px;   
 
    } 
 
    #section1 { 
 
     border: 4px solid blue; 
 
     width:700px; 
 
     float:left; 
 
     padding:5px;   
 
    } 
 
    #section2 { 
 
     border: 4px solid brown; 
 
     background-color: gainsboro; 
 
     width:700px; 
 
     float:right; 
 
     padding:5px;   
 
    }
<div id="header"> 
 
    <h2>Поиск мероприятий:</h2> 
 
    <div id="searchKeyword" class="input-group"> 
 
     <i class="glyphicon glyphicon-search input-group-addon"></i> 
 
     <input type="text" class="form-control" placeholder="Часть названия мероприятия" ng-model="actionsQuery.searchText" on-enter="queryResult()"> 
 
     <!--<span class="input-group-btn" ng-hide="!actionsQuery.searchText">--> 
 
     <span class="input-group-btn"> 
 
      <button class="btn btn-primary" type="button" ng-click="queryResult()">Найти мероприятия</button> 
 
     </span> 
 
    </div> 
 
</div> 
 

 
<div id="nav"> 
 
    ... 
 
</div> 
 

 
<div id="section1"> 
 
    ... 
 
</div> 
 

 
<div id="section2"> 
 
    ... 
 
</div>

或使用float - CSS

#header h2, #searchKeyword{ 
    float:left; 
} 

#header { 
 
    border: 4px solid red; 
 
    background-color:white; 
 
    color:black; 
 
    text-align:left; 
 
    overflow: auto; 
 
} 
 
#header h2, #searchKeyword{ 
 
    float:left; 
 
} 
 
#searchKeyword{ 
 
    line-height:64px; 
 
} 
 
#nav { 
 
    border: 4px solid green; 
 
    line-height:20px; 
 
    height:420px; 
 
    width:250px; 
 
    float:left; 
 
    padding:5px;   
 
} 
 
#section1 { 
 
    border: 4px solid blue; 
 
    width:700px; 
 
    float:left; 
 
    padding:5px;   
 
} 
 
#section2 { 
 
    border: 4px solid brown; 
 
    background-color: gainsboro; 
 
    width:700px; 
 
    float:right; 
 
    padding:5px;   
 
}
<div id="header"> 
 
    <h2>Поиск мероприятий:</h2> 
 
    <div id="searchKeyword" class="input-group"> 
 
     <i class="glyphicon glyphicon-search input-group-addon"></i> 
 
     <input type="text" class="form-control" placeholder="Часть названия мероприятия" ng-model="actionsQuery.searchText" on-enter="queryResult()"> 
 
     <!--<span class="input-group-btn" ng-hide="!actionsQuery.searchText">--> 
 
     <span class="input-group-btn"> 
 
      <button class="btn btn-primary" type="button" ng-click="queryResult()">Найти мероприятия</button> 
 
     </span> 
 
    </div> 
 
</div> 
 

 
<div id="nav"> 
 
    ... 
 
</div> 
 

 
<div id="section1"> 
 
    ... 
 
</div> 
 

 
<div id="section2"> 
 
    ... 
 
</div>

+0

您使用浮動的原始答案是一種有效的方法。 – 2014-09-23 12:02:10

+0

添加'#header {overflow:auto}'以確保浮標包含在標題中,否則其餘佈局可能會中斷。 – 2014-09-23 12:05:45

+0

好的,謝謝。 – 2014-09-23 12:08:08

0

試試這樣說: http://jsfiddle.net/o2tkn8pL/

你必須確保的div的寬度不大於大屏幕尺寸。 因此,在我看來,使用固定寬度並不是一個好主意。使用百分比值,你的設計也將更加適應

例子:

width:25%; 

E:嗯,我想我missunderstood原來的問題...我想OP希望藍格是插圖中的導航和棕色格 因此,要回答這個問題: 使用

#header h2, #searchKeyword{ 
     display:inline-block; 
    } 
0

只需添加這display: inline-block到你的CSS:

#searchKeyword, h2 { 
    display:inline-block; 
} 
+0

我做到了,搜索字段向右移動了標籤,但您可以在上面的第二個屏幕截圖中看到它現在的樣子。 – tesicg 2014-09-23 12:33:49