简体   繁体   English

创建列表,标题和图像左对齐,文本右对齐?

[英]Create list with title and image left aligned and text right aligned?

I'd like to create a layout like the one in the image 我想创建一个与图片中的布局类似的布局

在此处输入图片说明

What is the best and cleanest way create the layout in HTML and the cleanest way to do it in the CSS ? 什么是用HTML创建布局的最佳和最简洁的方法,以及在CSS中做布局的最简洁的方法? This what I have tried : codepen.io/hafsadanguir/pen/bZQLdL 这是我尝试过的:codepen.io/hafsadanguir/pen/bZQLdL

Thanks in advance for your help :) 在此先感谢您的帮助 :)

I think the best and the cleanest way to achieve result like what you're showing is by using Bootstrap. 我认为最好的和最干净的方式来获得所显示的结果是使用Bootstrap。 The following code is for structure like what you're showing as what I'll use for my own. 以下代码适用于结构,例如您将要显示的结构。 Also by using Bootstrap you'll benefit responsive layout for multiple screens 另外,通过使用Bootstrap,您将受益于多个屏幕的响应式布局

HTML: HTML:

<div class="container" id="container">
  <div class="row">
    <div class="col-sm-1">
      <div class="img" id="imgOne"></div>
    </div>
    <div class="col-sm-2">
      <h1>Lorem ipsum dolor sit amet</h1>
    </div>
    <div class="col-sm-9">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec lacus vel nunc sodales ultrices. Integer sodales lacus ac molestie fermentum. Integer ac tempor massa. </p>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-1">
      <div class="img" id="imgTwo"></div>
    </div>
    <div class="col-sm-2">
      <h1>Lorem ipsum dolor sit amet</h1>
    </div>
    <div class="col-sm-9">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec lacus vel nunc sodales ultrices. Integer sodales lacus ac molestie fermentum. Integer ac tempor massa. </p>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-1">
      <div class="img" id="imgThree"></div>
    </div>
    <div class="col-sm-2">
      <h1>Lorem ipsum dolor sit amet</h1>
    </div>
    <div class="col-sm-9">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec lacus vel nunc sodales ultrices. Integer sodales lacus ac molestie fermentum. Integer ac tempor massa. </p>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-1">
      <div class="img" id="imgFour"></div>
    </div>
    <div class="col-sm-2">
      <h1>Lorem ipsum dolor sit amet</h1>
    </div>
    <div class="col-sm-9">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec lacus vel nunc sodales ultrices. Integer sodales lacus ac molestie fermentum. Integer ac tempor massa. </p>
    </div>
  </div>
</div>

CSS: CSS:

#container {
  background: red;
}
.img{
  height: 50px;
  background: green;
}
#container .row {
  margin-bottom: 15px;
}
#container h1 {
  margin: 0;
}
#imgOne {
    background-image: url(#your_image_path);
}
#imgTwo {
    background-image: url(#your_image_path);
}
#imgThree {
    background-image: url(#your_image_path);
}
#imgFour {
    background-image: url(#your_image_path);
}

And by using a little bit of jQuery we can acheave a sharp square images containers: 通过使用一些jQuery,我们可以实现清晰的方形图像容器:

$('.img').height($('.img').width());

Remember to add Bootstrap files in your document tag, from Here , And you'll need to tweak the design for your awn preferences. 记住要从此处在文档标签中添加Bootstrap文件,然后您需要针对awn偏好调整设计。

A Bootply Preview from Here . 这里开始预览。

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

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