简体   繁体   English

如何在图片旁边对齐文本div?

[英]How do I align my text div next to my image?

I need to display my text next to my image. 我需要在图片旁边显示文字。 The image info with social links need to stay below the image. 具有社交链接的图像信息需要保持在图像下方。 I've tried clearfix codes but no result has worked sufficiently. 我已经尝试过clearfix代码,但是没有任何结果能令人满意。 I am working with a bootstrap build and I may be missing something simple, thus I've left in all my html in case I moved something (can't see that I did though). 我正在使用Bootstrap构建,可能遗漏了一些简单的内容,因此,如果我移动了某些内容,我将留在我的所有html中(虽然我看不到)。 I've included the specific css as well although I have global code too (not added here). 我也包括了特定的CSS,尽管我也有全局代码(此处未添加)。 Any suggestions? 有什么建议么?

 #team { padding: 60px 0; text-align: center; } #team h2 { text-transform: uppercase; } #team .team { margin-top: 40px; margin-bottom: 20px; } #team .team h4 { margin-top: 20px; text-transform: uppercase; font-weight: 700; } #team .team p { color: #a3a3a3; } #team .team a { color: #0d0d0d; font-size: 22px; padding-right: 10px; -moz-transition: all 0.3s ease-in-out; -o-transition: all 0.3s ease-in-out; -webkit-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out; } #team .team a:hover, #team .team a:focus, #team .team a:active { color: #a3a3a3; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <section id="team"> <div class="container"> <h2>INFO</h2> <hr class="sep"> <p>MORE INFO</p> <div class="row wow fadeInUp" data-wow-delay=".3s"> <div class="col-md-4"> <img class="img-responsive center-block" src="IMAGE FILE" alt="THIS IS AN IMAGE"> <h4>NAME</h4> <p>PROFESSION</p> <div class="team-social-icons"> <a href="***" target="_blank"><i class="fa fa-facebook"></i></a> <a href="***" target="_blank"><i class="fa fa-twitter"></i></a> <a href="***" target="_blank"><i class="fa fa-instagram"></i></a> </div> </div> <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> </div> </section> 

Problem 问题

Align text to the side of an image. 将文本对齐到图像的侧面。

Solution

If you want text to sit on the side of the image you need to add a float to the image. 如果希望文本位于图像的侧面,则需要在图像上添加float

your code is going to need more css to obtain your complete desired result but to get you going you should create a class to add to the image which will have the float: left; 您的代码将需要更多的CSS来获得完整的所需结果,但是要开始使用,您应该创建一个类以添加到具有float: left;的图像中float: left; property. 属性。

.floatImg { float: left;}

Then apply it to the image, 然后将其应用于图像,

<img class="floatImg">

To show you a small example of this all I did was add a float to your image existing class. 为了给您展示一个小例子,我所做的就是在现有图像类中添加一个float。 "but you should create a new one". “但是您应该创建一个新的”。 Then I moved the h4 above the image so the <p> would wrap. 然后将h4移到图像上方,以便<p>换行。 Once you apply this to your project you can apply more css to make it all look nice. 将其应用于项目后,您可以应用更多的css ,使它们看起来都不错。

Padding / margin etc Padding / margin

Bootstrap 引导程序

Luckily you are using bootstrap . 幸运的是,您正在使用bootstrap So to take this a step further there is a lot of options here you can use to make this look nice. 因此,要进一步进行此操作,可以在此处使用很多选项来使外观看起来更好。 Bootstrap gives you the ability to use columns and rows . Bootstrap使您能够使用columnsrows

So if you know you need to create a 2 column row. 因此,如果您知道需要创建一个两列的行。 img in one and text in the other you could do that. 一个可以使用img ,另一个可以使用文本。

Example of bootstrap 2 col bootstrap 2 col的示例

<div class="row">
    <div class="col-lg-6 col-md-6">
          <img>
    <div>  
    <div class="col-lg-6 col-md-6">
         <p> txt here</p>
    <div>    
</div>

 #team { padding: 60px 0; text-align: center; } #team h2 { text-transform: uppercase; } #team .team { margin-top: 40px; margin-bottom: 20px; } #team .team h4 { margin-top: 20px; text-transform: uppercase; font-weight: 700; } #team .team p { color: #a3a3a3; } #team .team a { color: #0d0d0d; font-size: 22px; padding-right: 10px; -moz-transition: all 0.3s ease-in-out; -o-transition: all 0.3s ease-in-out; -webkit-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out; } #team .team a:hover, #team .team a:focus, #team .team a:active { color: #a3a3a3; } .img-responsive { float: left; } 
 <section id="team"> <div class="container"> <h2>INFO</h2> <hr class="sep"> <p>MORE INFO</p> <div class="row wow fadeInUp" data-wow-delay=".3s"> <div class="col-md-4"> <h4>NAME</h4> <p>PROFESSION</p> <img class="img-responsive center-block" src="IMAGE FILE" alt="THIS IS AN IMAGE"> <div class="team-social-icons"> <a href="***" target="_blank"><i class="fa fa-facebook"></i></a> <a href="***" target="_blank"><i class="fa fa-twitter"></i></a> <a href="***" target="_blank"><i class="fa fa-instagram"></i></a> </div> </div> <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> </div> </section> 

A <div> 's content will go to the next line, adding a break before it. <div>的内容将转到下一行,并在其前面添加一个空格。 I would look at organising the layout into a <table> with a left <td> for the image, and a right <td> for the description and the links to social media. 我将看一下如何将布局组织成一个<table> ,其中图像的左侧<td> ,右侧的<td>进行描述以及与社交媒体的链接。

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

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