2016-08-02 149 views
0

我已经编写代码在div标签内显示图像,并在不同div中的图像下面显示与其相关的文本。但我现在有4个div标签和2个图像。但我想将它们排列在同一行。但它显示在其他div标签下面这样.. In the screenshot u can see i have added a image and below the image, text saying browse base layouts. both of them are in different div tags.. and then u can see i have added another image and text below the image as easy matchmaking strategy. and these two are also in different div tags.如何在同一行显示多个div标签的内容

但现在我想要在同一行上对齐两个图像。但他们现在对齐一个在另一个之下..任何人都可以请帮助我如何安排他们在同一行。这将是很大的帮助.. 这里是html代码: -

<!doctype html> 
<html> 
<head> 
<link href="Layout.css" rel="stylesheet" type="text/css" /> 
<link href="Menu.css" rel="stylesheet" type="text/css" /> 
<meta charset="utf-8"> 
<title>Home</title> 
</head> 
<body> 
<div id="Holder"> 
<div id="Header"></div> 
<div id="Heading1"><center><font size="+2" color="#FBFBFB">-Follow Us At-</font></center></div> 
<div id="Heading1content"><center> 
<a href="#"><img src="images/download.png" alt="Facebook" width="60" height="55" title="Facebook"/> </a> &nbsp; 
<a href="#"><img src="images/images.jpg" width="60" height="60" alt="Google+" title="Google+"/></a> &nbsp; 
<a href="#"><img src="images/download.jpg" width="64" height="60" alt="Twitter" title="Twitter"/></a> &nbsp; 
</center></div> 
<div id="Navbar"> 
<nav> 
<ul> 
<li><a href="#"> HOME</a> </li> 
<li><a href="#">LOG IN</a></li> 
<li><a href="#">BLOGS</a></li> 
</ul> 
</nav> 
</div> 
<hr/> 
<div id="Heading2"><center><font size="+2" color="#FFFFFF">-Hi Clasher! What Are You Looking For?-</font></center> </div> 
<div id="polaroid" align="center"> 
<a href="#"><img src="images/IMG-20160802-WA0012.jpg" alt="Base Layouts" title="Base Layouts"/></a> 
</div> 
<div id="text" align="center"><center><font size="+2" color="#F7F4F4"><a href="#">Browse Base Layouts</a></font></center></div> 
<div id="polaroid"> 
<a href="#"><img src="images/IMG-20160802-WA0014.jpg" alt="War Strategy" title="Easy War Matchmaking Strategy"/></a></div> 
<div id="text"><center><font size="+2" color="#F7F4F4"><a href="#">Easy War Matchmaking Strategy</a></font></center></div> 
<hr/> 
<div id="footer1"> 
</div> 
<div id="footer2"> 
<center> 
<font color="#F7F4F4" size="+1">Made With Love For All Clashers <br/> 
&copy; Brothers Gaming 2016</font> 
</center> 
</div> 
</div> 
</body> 
</html> 

这里是CSS代码.. layout.css中: -

#Holder { 
width: 900px; 
height: auto; 
margin-left: auto; 
margin-right: auto; 
margin-top: 25px; 
margin-bottom: 25px; 
} 
#Header { 
height:200px; 
background-image:url(images/main.jpg); 
background-color:#CCCCCC; 
background-repeat:no-repeat; 
background-position:center; 
margin-bottom: 5px; 
} 
#Heading1 { 
height: 36px; 
line-height: 32px; 
background-color:#0B6D96; 
margin-bottom: 11px; 
} 
#Navbar { 
height: 55px; 
margin-top: 8px; 
margin-left:24%; 
background-color:rgb(13, 13, 13); 
width: 450px; 
padding: 3px; 
} 
#Heading2 { 
height: 36px; 
background-color: #0B6D96; 
margin-bottom: 11px; 
line-height: 32px; 
} 
#polaroid{ 
width:45%; 
background-color: white; 
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 
} 
#text{ 
height:35px; 
background-color:#253FB7; 
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 
margin-bottom:11px; 
width:45%; 
line-height:32px; 
} 
#text a{ 
text-decoration:none; 
color:#F7F4F4; 
display:block; 
} 
#footer1{ 
height:200px; 
width:900px; 
background-color:#f0e6ff; 
margin-top: 11px; 
} 
#footer2{ 
height:55px; 
width:900px; 
background-color:#000000; 
line-height: 27px; 
} 

而且Menu.css: -

nav ul { 
margin: 0; 
padding: 0; 
} 
nav ul li { 
list-style-type: none; 
float: left; 
display: block; 
width: 150px; 
height: 55px; 
text-align:center; 
line-height: 57px; 
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif; 
font-size:22px; 
} 
nav ul li a { 
text-decoration:none; 
color:#FFF; 
} 
nav ul li:hover { 
background-color:rgb(242, 242, 242); 
} 
nav ul li:hover a { 
display:block; 
color:#000000; 
} 

这里是网站:http://www.brothersgaming.16mb.com/Home.html

回答

0

你应该使用一个共同ntainer div包含图像和文本,并使用CSS浮动属性。 另外请记住,您应该使用多次使用对象的类,而对于只出现一次的对象使用ID。

HTML

<div class="container"> 
<div id="polaroid" align="center"> 
<a href="#"><img src="images/IMG-20160802-WA0012.jpg" alt="Base Layouts" title="Base Layouts"/></a> 
</div> 
<div id="text" align="center"><center><font size="+2" color="#F7F4F4"><a href="#">Browse Base Layouts</a></font></center></div> 
</div> 
<div class="container"> 
<div id="polaroid"> 
<a href="#"><img src="images/IMG-20160802-WA0014.jpg" alt="War Strategy" title="Easy War Matchmaking Strategy"/></a></div> 
<div id="text"><center><font size="+2" color="#F7F4F4"><a href="#">Easy War Matchmaking Strategy</a></font></center></div> 
</div> 

CSS

#polaroid{ 
width:100%; 
background-color: white; 
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 
} 
#text{ 
height:35px; 
background-color:#253FB7; 
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 
margin-bottom:11px; 
width:100%; 
line-height:32px; 
} 
.container{ 
width:45%; 
    float:left; 
} 

CSS float Property Documentation

+0

感谢ü..它的工作..但它的倒塌,我想这两个图像之间增加一些空间..ü能帮助我的空间太? – Jyotishmoy

+0

我会将宽度设置为50%,以便它们相等并填充行,并使用填充在容器内创建偏移量。 – Marco

0

更新HTML

<!doctype html> 
<html> 

    <head> 
    <link href="Layout.css" rel="stylesheet" type="text/css" /> 
    <link href="Menu.css" rel="stylesheet" type="text/css" /> 
    <meta charset="utf-8"> 
    <title>Home</title> 
    </head> 

    <body> 
    <div id="Holder"> 
     <div id="Header"></div> 
     <div id="Heading1"> 
     <center><font size="+2" color="#FBFBFB">-Follow Us At-</font></center> 
     </div> 
     <div id="Heading1content"> 
     <center> 
      <a href="#"><img src="images/download.png" alt="Facebook" width="60" height="55" title="Facebook" /> </a> &nbsp; 
      <a href="#"><img src="images/images.jpg" width="60" height="60" alt="Google+" title="Google+" /></a> &nbsp; 
      <a href="#"><img src="images/download.jpg" width="64" height="60" alt="Twitter" title="Twitter" /></a> &nbsp; 
     </center> 
     </div> 
     <div id="Navbar"> 
     <nav> 
      <ul> 
      <li><a href="#"> HOME</a> </li> 
      <li><a href="#">LOG IN</a></li> 
      <li><a href="#">BLOGS</a></li> 
      </ul> 
     </nav> 
     </div> 
     <hr/> 
     <div id="Heading2"> 
     <center><font size="+2" color="#FFFFFF">-Hi Clasher! What Are You Looking For?-</font></center> 
     </div> 
     <section id="polaroid-wrap"> 
     <div id="polaroid" align="center"> 
      <a href="#" style=" 
    "><img src="images/IMG-20160802-WA0012.jpg" alt="Base Layouts" title="Base Layouts" kasperskylab_antibanner="on"></a> 
      <div id="text" align="center"> 
      <center><font size="+2" color="#F7F4F4"><a href="#">Browse Base Layouts</a></font></center> 
      </div> 
     </div> 

     <div id="polaroid" align="center"> 
      <a href="#"><img src="images/IMG-20160802-WA0014.jpg" alt="War Strategy" title="Easy War Matchmaking Strategy" kasperskylab_antibanner="on"></a> 
      <div id="text" align="center"> 
      <center><font size="+2" color="#F7F4F4"><a href="#">Easy War Matchmaking Strategy</a></font></center> 
      </div> 
     </div> 

     </section> 
     <div id="footer1"> 
     </div> 
     <div id="footer2"> 
     <center> 
      <font color="#F7F4F4" size="+1">Made With Love For All Clashers <br/> 
&copy; Brothers Gaming 2016</font> 
     </center> 
     </div> 
    </div> 
    </body> 

</html> 

添加在你的CSS文件的末尾这CSS代码

#text { 
    width: 100% !important; 
} 

div#polaroid:nth-child(odd) { 
    float: left; 
} 

div#polaroid:nth-child(even) { 
    float: right; 
}