2015-08-24 23 views
1

我有以下網頁: enter image description here移動一個DIV毗鄰多個div(CSS)

我想左下,紅色邊框的div移動到畫紅框。 (旁邊的主要內容,3.5%的右邊距)

我的代碼似乎沒有工作,不管什麼。

body { 
 
    margin-top:20px; 
 
    margin-right:0; 
 
    margin-left:0; 
 
    margin-bottom:0; 
 
    overflow: auto; 
 
    background-color:#FFFFF0; 
 
} 
 

 
.cap { 
 
    text-transform: capitalize; 
 
} 
 

 
.p { 
 
    color:#37FDFC; 
 
    max-height:inherit; 
 
} 
 

 
#container { 
 
    width:90%; 
 
    margin:auto; 
 
    background-color:#F6F4F1; 
 
    border: 5px solid #00b4b4; 
 
    padding:0; 
 
    border-radius: 25px; 
 
} 
 

 
#header { 
 
    width:100%; 
 
    top:0; 
 
} 
 

 
#header p { 
 
    text-align:right; 
 
    margin-right:3%; 
 
} 
 

 
#footer { 
 
    width:100%; 
 
    bottom:0; 
 
    color:#838B8B; 
 
    font-family:verdana; 
 
} 
 

 
#footer:after { 
 
    content: ""; 
 
    clear: both; 
 
    display: table; 
 
} 
 

 
.register_form { 
 
    border-radius: 6px; 
 
    border: 4px solid #C1CDCD; 
 
    width:70%; 
 
} 
 

 
#register_form { 
 
    margin-left:4%; 
 
    border-right: 2px dotted #00CDCD; 
 
    width:30%; 
 
    margin-right:0%; 
 
    display:inline-block; 
 
} 
 

 
#register_form h2 { 
 
    color:#00CDCD; 
 
    font-family:verdana; 
 
} 
 

 
#side_text { 
 
    width:30%; 
 
    float:right; 
 
    margin-right:30%; 
 
} 
 

 
#side_text h3 { 
 
    color:#00CDCD; 
 
    font-family:verdana; 
 
} 
 

 
#side_text p { 
 
    color:#838B8B; 
 
    font-family:verdana; 
 
} 
 

 
#login_form { 
 
    margin-left:4%; 
 
    border-right: 2px dotted #00CDCD; 
 
    width:30%; 
 
    margin-right:0%; 
 
    display:inline-block; 
 
} 
 

 
#login_form h2 { 
 
    color:#00CDCD; 
 
    font-family:verdana; 
 
} 
 

 
.login_form { 
 
    border-radius: 6px; 
 
    border: 4px solid #C1CDCD; 
 
    width:70%; 
 
} 
 

 
#just_registered_text { 
 
    text-align:center; 
 
    color:#00CDCD; 
 
    font-family:verdana; 
 
} 
 

 
#errors { 
 
    float: left; 
 
    margin-left:4.5%; 
 
    text-align:left; 
 
    color:red; 
 
} 
 

 
#other { 
 
    float: right; 
 
    text-align:right; 
 
    margin-right:3%; 
 
    display:inline-block; 
 
} 
 

 
#profile_name_div { 
 
    margin-left:3%; 
 
    color: #00b4b4; 
 
    font-size: 27px; 
 
    font-family:verdana; 
 
    font-weight: 700; 
 
    display:inline; 
 
} 
 

 
#change_settings a { 
 
    margin-left:5%; 
 
    color:lightblue; 
 
    font-size: 16px; 
 
    font-family:verdana; 
 
    font-weight: 700; 
 
} 
 

 
#settings_space h2 { 
 
    margin-left:3%; 
 
    color:#00CDCD; 
 
    font-size: 27px; 
 
    font-family:verdana; 
 
    font-weight: 700; 
 
} 
 

 
#settings_space textarea { 
 
    overflow: hidden; 
 
    resize: none; 
 
    border: 2px solid #00CDCD; 
 
    margin-left:3%; 
 
    border-radius: 8px; 
 
} 
 

 
#settings_space:first-letter { 
 
    text-transform: capitalize; 
 
} 
 

 
#settings_space label { 
 
    margin-left:8%; 
 
    color: #009acd; 
 
} 
 

 
.settings_submit { 
 
    margin-left:5%; 
 
} 
 

 
.info { 
 
    margin-left:3%; 
 
    display:inline; 
 
    color:#838B8B; 
 
    font-family:verdana; 
 
    width:100%; 
 
} 
 

 
#photo { 
 
    display:block; 
 
    border: 1px solid black; 
 
    width:200px; 
 
    height:200px; 
 
    margin-left:3.5%; 
 
} 
 

 
#actual_photo { 
 
    width:200px; 
 
    height:200px; 
 
} 
 

 
#change_pp { 
 
    background:#f9f9f9; 
 
    border-bottom: 1px dashed #ccc; 
 
    border-top: 1px dashed #ccc; 
 
    border-left: 1px dashed #ccc; 
 
    border-right: 1px dashed #ccc; 
 
    width:200px; 
 
    margin-left:3.5%; 
 
    padding:0; 
 
} 
 

 
#proj { 
 
    display: none; 
 
} 
 

 
#button { 
 
    width:100%; 
 
} 
 

 
#change_pp input[type=file] { 
 
    width:100%; 
 
} 
 

 
.info > b { 
 
    color:#00CDCD; 
 
} 
 

 
#about_me_header { 
 
    margin-left:3.5%; 
 
    color:#B4CDCD; 
 
    border: 5px solid #00b4b4; 
 
    border-radius:20px; 
 
    width:50%; 
 
} 
 

 
#about_section { 
 
    border:2px solid red; 
 
    width:30%; 
 
}
<div id='container'> 
 
    <div id='header'> 
 
     <p>The current date is $date:</p> 
 
    </div> 
 
    <span id="profile_name_div"> example </span> 
 
    <span id="change_settings"> 
 
     <a href='account_settings.php'>Change Settings</a> 
 
    </span> 
 
    <div id="photo">example</div> 
 
    <div id="change_pp">  
 
     <button id="button" onclick="showForm()" >Change Profile Picture</button> 
 
     <form id="proj" action="include/form_handle.php" method="POST" enctype="multipart/form-data"> 
 
      <input type="file" value="change" name="pp_file"/> 
 
      <input type="submit" name="pp_submit" value="Upload Photo"/> 
 
     </form> 
 
    </div> 
 
    <div id="about_section">  
 
     <h1 id="about_me_header">About me header</h1> 
 
     <br/> 
 
     <div class="info"><b>Bio: </b>text</div> 
 
     <br/><br/>   
 
     <div class="info"><b>Interests: </b>text</div> 
 
     <br/><br/> 
 
     <div class="info"><b>Favorite Quotes: </b>text</div> 
 
     <div id='footer'></div> 
 
    </div> 
 
</div>

的jsfiddle:https://jsfiddle.net/8jczhzaL/2/

  • 我試圖浮動的div並沒有什麼作品。

如何將我的div移到其他div旁邊?爲什麼沒有浮動工作?

回答

0

我給你的左邊的內容一個包裝,並將它左移。這應該是非常接近你要找的東西 - 只是改變了一些邊緣的把一切排隊你到底怎麼想的那樣:

現場演示:

 \t body { 
 
    \t  margin-top:20px; 
 
    \t  margin-right:0; 
 
    \t  margin-left:0; 
 
    \t  margin-bottom:0; 
 
    \t  overflow: auto; 
 
    \t  background-color:#FFFFF0; 
 
    \t } 
 
    \t .cap { 
 
    \t  text-transform: capitalize; 
 
    \t } 
 
    \t .p { 
 
    \t  color:#37FDFC; 
 
    \t  max-height:inherit; 
 
    \t } 
 
    \t #container { 
 
    \t  width:90%; 
 
    \t  margin:auto; 
 
    \t  background-color:#F6F4F1; 
 
    \t  border: 5px solid #00b4b4; 
 
    \t  padding:0; 
 
    \t  border-radius: 25px; 
 
    \t } 
 
    \t #header { 
 
    \t  width:100%; 
 
    \t  top:0; 
 
    \t } 
 
    \t #header p { 
 
    \t  text-align:right; 
 
    \t  margin-right:3%; 
 
    \t } 
 
    \t #footer { 
 
    \t  width:100%; 
 
    \t  bottom:0; 
 
    \t  color:#838B8B; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t #footer:after { 
 
    \t  content:""; 
 
    \t  clear: both; 
 
    \t  display: table; 
 
    \t } 
 
    \t .register_form { 
 
    \t  border-radius: 6px; 
 
    \t  border: 4px solid #C1CDCD; 
 
    \t  width:70%; 
 
    \t } 
 
    \t #register_form { 
 
    \t  margin-left:4%; 
 
    \t  border-right: 2px dotted #00CDCD; 
 
    \t  width:30%; 
 
    \t  margin-right:0%; 
 
    \t  display:inline-block; 
 
    \t } 
 
    \t #register_form h2 { 
 
    \t  color:#00CDCD; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t #side_text { 
 
    \t  width:30%; 
 
    \t  float:right; 
 
    \t  margin-right:30%; 
 
    \t } 
 
    \t #side_text h3 { 
 
    \t  color:#00CDCD; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t #side_text p { 
 
    \t  color:#838B8B; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t #login_form { 
 
    \t  margin-left:4%; 
 
    \t  border-right: 2px dotted #00CDCD; 
 
    \t  width:30%; 
 
    \t  margin-right:0%; 
 
    \t  display:inline-block; 
 
    \t } 
 
    \t #login_form h2 { 
 
    \t  color:#00CDCD; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t .login_form { 
 
    \t  border-radius: 6px; 
 
    \t  border: 4px solid #C1CDCD; 
 
    \t  width:70%; 
 
    \t } 
 
    \t #just_registered_text { 
 
    \t  text-align:center; 
 
    \t  color:#00CDCD; 
 
    \t  font-family:verdana; 
 
    \t } 
 
    \t #errors { 
 
    \t  float: left; 
 
    \t  margin-left:4.5%; 
 
    \t  text-align:left; 
 
    \t  color:red; 
 
    \t } 
 
    \t #other { 
 
    \t  float: right; 
 
    \t  text-align:right; 
 
    \t  margin-right:3%; 
 
    \t  display:inline-block; 
 
    \t } 
 
    \t #profile_name_div { 
 
    \t  margin-left:3%; 
 
    \t  color: #00b4b4; 
 
    \t  font-size: 27px; 
 
    \t  font-family:verdana; 
 
    \t  font-weight: 700; 
 
    \t  display:inline; 
 
    \t } 
 
    \t #change_settings a { 
 
    \t  margin-left:5%; 
 
    \t  color:lightblue; 
 
    \t  font-size: 16px; 
 
    \t  font-family:verdana; 
 
    \t  font-weight: 700; 
 
    \t } 
 
    \t #settings_space h2 { 
 
    \t  margin-left:3%; 
 
    \t  color:#00CDCD; 
 
    \t  font-size: 27px; 
 
    \t  font-family:verdana; 
 
    \t  font-weight: 700; 
 
    \t } 
 
    \t #settings_space textarea { 
 
    \t  overflow: hidden; 
 
    \t  resize: none; 
 
    \t  border: 2px solid #00CDCD; 
 
    \t  margin-left:3%; 
 
    \t  border-radius: 8px; 
 
    \t } 
 
    \t #settings_space:first-letter { 
 
    \t  text-transform: capitalize; 
 
    \t } 
 
    \t #settings_space label { 
 
    \t  margin-left:8%; 
 
    \t  color: #009acd; 
 
    \t } 
 
    \t .settings_submit { 
 
    \t  margin-left:5%; 
 
    \t } 
 
    \t .info { 
 
    \t  margin-left:3%; 
 
    \t  display:inline; 
 
    \t  color:#838B8B; 
 
    \t  font-family:verdana; 
 
    \t  width:100%; 
 
    \t } 
 
    \t #photo { 
 
    \t  display:block; 
 
    \t  border: 1px solid black; 
 
    \t  width:200px; 
 
    \t  height:200px; 
 
    \t  margin-left:3.5%; 
 
    \t } 
 
    \t #actual_photo { 
 
    \t  width:200px; 
 
    \t  height:200px; 
 
    \t } 
 
    \t #change_pp { 
 
    \t  background:#f9f9f9; 
 
    \t  border-bottom: 1px dashed #ccc; 
 
    \t  border-top: 1px dashed #ccc; 
 
    \t  border-left: 1px dashed #ccc; 
 
    \t  border-right: 1px dashed #ccc; 
 
    \t  width:200px; 
 
    \t  margin-left:3.5%; 
 
    \t  padding:0; 
 
    \t } 
 
    \t #proj { 
 
    \t  display: none; 
 
    \t } 
 
    \t #button { 
 
    \t  width:100%; 
 
    \t } 
 
    \t #change_pp input[type=file] { 
 
    \t  width:100%; 
 
    \t } 
 
    \t .info > b { 
 
    \t  color:#00CDCD; 
 
    \t } 
 
    \t #about_me_header { 
 
    \t  margin-left:3.5%; 
 
    \t  color:#B4CDCD; 
 
    \t  border: 5px solid #00b4b4; 
 
    \t  border-radius:20px; 
 
    \t  width:50%; 
 
    \t } 
 
    \t #about_section { 
 
    \t  border:2px solid red; 
 
    \t  width:30%; 
 
    \t  float: right; 
 
    \t } 
 
#left_section { 
 
float: left; 
 
} 
 
    \t
<body> 
 
    <div id='container'> 
 
     <div id='header'> 
 
      <p>The current date is $date:</p> 
 
     </div> <span id="profile_name_div"> example </span> 
 
<span id="change_settings"> 
 
<a href='account_settings.php'>Change Settings 
 
</a> <br /> 
 
</span> 
 
     <div id="left_section"> 
 
     <div id="photo">example</div> 
 
     <div id="change_pp"> 
 
      <button id="button" onclick="showForm()">Change Profile Picture</button> 
 
      <form id="proj" action="include/form_handle.php" method="POST" enctype="multipart/form-data"> 
 
       <input type="file" value="change" name="pp_file" /> 
 
       <input type="submit" name="pp_submit" value="Upload Photo" /> 
 
      </form> 
 
     </div> 
 
     </div> 
 
     <div id="about_section"> 
 
      <h1 id="about_me_header">About me header</h1> 
 

 
      <br/> 
 
      <div class="info"><b>Bio: </b>text</div> 
 
      <br/> 
 
      <br/> 
 
      <div class="info"><b>Interests: </b>text</div> 
 
      <br/> 
 
      <br/> 
 
      <div class="info"><b>Favorite Quotes: </b>text</div> 
 
      <div id='footer'></div> 
 
      
 
     </div> 
 
     <div style="clear: both;"></div> 
 
</body>

JSFiddle版本:https://jsfiddle.net/8jczhzaL/3/