Heim >Web-Frontend >HTML-Tutorial >为什么div右浮动后还会换行_html/css_WEB-ITnose

为什么div右浮动后还会换行_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-24 11:31:441788Durchsuche

为什么div右浮动后还会换行:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
让两个div排列在同一行有多种方法,有些初学者可能会这样写,那就是左边的div不浮动,右边的div右浮动,以为这样就可以达到两个div在同一行的效果的,但是事实并非如此。代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.left{  width:200px;  height:200px;  background-color:blue;}.right{  width:200px;  height:200px;  background-color:red;  float:right;}</style></head><body><div class="left"></div><div class="right"></div></body></html>

所以我们想要让两个div在同一行上,还是需要将两个div都要浮动起来。代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.left{  width:200px;  height:200px;  float:right;  background-color:blue;}.right{  width:200px;  height:200px;  background-color:red;  float:right;}</style></head><body><div class="left"></div><div class="right"></div></body></html>

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4659

更多内容可以参阅:http://www.softwhy.com/divcss/

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn