简体   繁体   English

如何将图像并排而不是彼此对齐?

[英]How do align the images side by side instead of on top of each other?

I want the images to display side by side not on top of each other. 我希望图像不能并排显示。

I tried adding float:left but that didn't help. 我尝试添加float:left,但这没有帮助。

 <div class="body"> <div style=" display:inline-block; width: 33.33%; height:110px; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;" </div> <div style=" display:inline-block; width: 33.33%; height:110px; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;" </div> <div style=" display:inline-block; width: 33.33%; height:110px; vertical-align:top; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;" </div> 

As mentioned by @LeeTaylor, your divs aren't being closed and missing > s. 正如@LeeTaylor所提到的,您的divs没有被关闭并且缺少> s。

Secondly, using inline style is not the recommended way to do markup now but to use Cascading Style Sheets ( CSS ) instead and use element classes and or id's to apply set styling. 其次,不建议立即使用内联样式来进行标记,而应使用级联样式表( CSS )并使用元素类和/或ID来应用集合样式。

Example with Fix using Flexbox . 使用Flexbox修复的示例

 .flex{ display:flex; justify-content:center; } .img-div{ width: 33.33%; height:110px; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } 
 <!DOCTYPE html> <html> <head> <title>Example</title> <!-- You add the Stylesheet to the html file in the head like this --> <link type="text/css" rel="stylesheet" href="css/style.css"/> </head> <body> <div class="flex"> <div class="img-div"> </div> <div class="img-div"> </div> <div class="img-div"> </div> </div> </body> </html> 

More information on CSS and its usage 有关CSS及其用法的更多信息

  1. Give float: left in style. float: left样式。
  2. End your starting div tag. 结束您的起始div标签。

Code: 码:

 <div style=" display:inline-block; width: 33.33%; height:110px; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; float: left;"></div> <div style=" display:inline-block; width: 33.33%; height:110px; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; float: left;"></div> <div style=" display:inline-block; width: 33.33%; height:110px; vertical-align:top; background: url(https://wallpaperfm.com/img/original/6/1/3/13347.jpg) no-repeat center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; float: left;"></div> 

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

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