简体   繁体   English

如何防止div标签彼此移动?

[英]How do I keep my div tags from moving each other around?

I took time to format a div tag for my main content and then I put that div inside a wrapper div. 我花了一些时间格式化主要内容的div标签,然后将div放入包装div中。 Well, when I went to add my logo to the site, everything shifted. 好吧,当我将徽标添加到网站时,一切都发生了变化。 The div that the logo was in seemed to have pushed the wrapper tag down. 徽标所在的div似乎已将包装标签下移。 Being new to code, I'm trying to keep my design as clean as possible but it is falling apart. 作为代码新手,我试图使我的设计尽可能整洁,但它正在崩溃。 Any suggestions? 有什么建议么? Any help? 有什么帮助吗? In the fiddle, I started the HTML code where the img source, this was the image that -when added- pushed my content down. 在小提琴中,我从img源开始HTML代码,这是添加时将内容压低的图像。

Here is the fiddle http://jsfiddle.net/569Gm/ 这是小提琴http://jsfiddle.net/569Gm/

<div id="logo">
   <img src="images/logo/logo-vector.png" />
</div>

<div id="wrapper">

   <div id="aboutus">   
       <p>We are a Hagerstown-based junk removal and moving service. Able to accomplish jobs both big and small, we accept residential, commerical, and industrial jobs. </p>
       <p>&nbsp;</p>
       <p>Active since 2014, we are a relatively new service looking to help as many people as possible. Visit our Facebook Page to stay posted on our recent works, job openings,        special offers and more. </p>
   </div>

   <div id="scheduling">
     <p>To schedule for a service, please provide the information listed
     below and we will respond promptly.</p>
   </div>

   <div id="contactus">
   <p>If you have any questions, comments, or concerns, our contact information is listed below.</p>
   <p>&nbsp;</p>
   <p>Phone: (443) 690 6421</p>
   <p>Email: service@hagdustboy.com</p>
   </div>   
</div>

</body>
</html>






</div>

This is what my website looks like now that I added the logo. 这是我添加徽标后的网站外观。 http://www.pixentral.com/show.php?picture=1PYUTuzOhcbLcaoadEpTNk2qnm http://www.pixentral.com/show.php?picture=1PYUTuzOhcbLcaoadEpTNk2qnm

Add float:left; 添加float:left; to your #logo , and use clear:left; 到您的#logo ,并使用clear:left; instead of clear:both; 而不是clear:both; .
By adding float:left; 通过添加float:left; & clear:left; clear:left; the #wrapper will come inline with your logo. #wrapper将内嵌您的徽标。
See the Demo 观看演示

Float your logo left "float: left;". 将徽标浮动到左侧“ float:left;”。 Clear your logo left as well "clear: left;". 清除徽标以及“ clear:left;”。 As a general rule of thumb, anything in the flow of the page /not "absolutely" positioned will need to be floated in some form way or shape unless the "div" containing it is floated. 作为一般经验法则,除非非“绝对”定位,否则页面流中/“非”绝对定位的所有内容都需要以某种形式或形状浮动。 A good way of remembering this is, anything composition related most likely needs to be floated. 记住这一点的一个好方法是,最有可能涉及到任何与构图有关的东西。 Float left, assuming your margins and paddings are "margin: 0" "padding:0" will snap your div to as far right or left as the width parameters allow. 向左浮动,假设您的边距和填充为“ margin:0”,“ padding:0”将使您的div在width参数允许的范围内向右或向左对齐。 Floating is really how you build the flow of the page. 浮动实际上是构建页面流程的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM