如何将此段落移动到图像的右侧

时间:2017-08-05 13:35:34

标签: html css

here is the picture of it

我试图做一个udacity的任务,我想把图片右边的段落移动请帮忙。 我实际上尝试为每个块添加div标签,即标题和图像以及段落

<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
 <div>
    <div class="heading">
        <h1>MY FAVOURITE APP</h1>
    </div>
    <div class="data">
        <div class="data">
            <img src="C:\Users\sreem\Desktop\pix.jpeg" alt="">
            <div>
            <p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </p>
        </div>
        </div>

    </div>
    </div>
 </div>
</body>
</html>

**style.css**

html文件的css代码

img {
    height: 250px;
    width: 250px;
    margin-top: 20px;
    margin-left: 100px;
}

.heading {
    height: 70px;
    width: 80%;
    margin-top: 50px;
    color:white;
    background-color:#5AB9BA;
    padding-top: 70px;
    letter-spacing: 5px;
    margin-left: 100px;
}
.para{
height: 250px;
width: 250px;
margin-left: 400px;

}

3 个答案:

答案 0 :(得分:0)

Float左边的图片。

img {
  height: 250px;
  width: 250px;
  margin-top: 20px;
  margin-left: 100px;
  float: left; /** float the image to the left **/
}

.heading {
  height: 70px;
  width: 80%;
  margin-top: 50px;
  color: white;
  background-color: #5AB9BA;
  padding-top: 70px;
  letter-spacing: 5px;
  margin-left: 100px;
}

.para {
  height: 250px;
  width: 250px;
  margin-left: 400px;
}
<div>
  <div class="heading">
    <h1>MY FAVOURITE APP</h1>
  </div>
  <div class="data">
      <img src="http://lorempixel.com/250/250/" alt="">
      <p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
        It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
        desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
  </div>
</div>

答案 1 :(得分:0)

您可以使用float属性。我将float: left;提供给img代码。

img {
    height: 250px;
    width: 250px;
    margin-top: 20px;
    margin-left: 100px;
    float: left;
}

.heading {
    height: 70px;
    width: 80%;
    margin-top: 50px;
    color:white;
    background-color:#5AB9BA;
    padding-top: 70px;
    letter-spacing: 5px;
    margin-left: 100px;
}
.para{
height: 250px;
width: 250px;
margin-left: 400px;

}
<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
 <div>
    <div class="heading">
        <h1>MY FAVOURITE APP</h1>
    </div>
    <div class="data">
        <div class="data">
            <img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
            <div>
            <p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
            </p>
        </div>
        </div>

    </div>
    </div>
 </div>
</body>
</html>

答案 2 :(得分:0)

强制图像向左浮动:

    display:inline-block;
    float:left;


img {
    height: 250px;
    width: 250px;
    margin-top: 20px;
    margin-left: 100px;
    display:inline-block;
    float:left;
}