【问题标题】:Moving one div next to multiple divs (CSS)将一个 div 移动到多个 div 旁边 (CSS)
【发布时间】:2015-08-25 08:07:00
【问题描述】:

我有以下网页:

我正在尝试将左下角的红色边框 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 旁边?为什么浮动不起作用?

【问题讨论】:

    标签: html css


    【解决方案1】:

    我给了你左边的内容一个包装器并将它向左浮动。这应该非常接近您要查找的内容 - 只需更改一些边距即可让所有内容完全按照您的要求排列:

    现场演示:

        	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%;
        	    float: right;
        	}
    #left_section {
     float: left;   
    }
        	
    <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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2014-03-15
      • 2010-10-24
      相关资源
      最近更新 更多