简体   繁体   English

HTML和CSS注释列表

[英]HTML & CSS Comment List

I have tried tried coding a comment list where the avatar is supposed to display on the left, and the name and comment are supposed to display on the right. 我尝试过对注释列表进行编码,在该列表中,化身应该显示在左侧,名称和评论应该显示在右侧。 Any help solving the issue is appreciated. 任何帮助解决该问题的帮助表示赞赏。

Outcome 结果

Desired Outcome 期望的结果

在此处输入图片说明

HTML 的HTML

    <section>
    <div class='friend'>
        <h3>John Smith</h3>
        <p>Just another comment</p>
        <img src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
    </div>
    <div class='friend'>
        <h3>John Smith</h3>
        <p>Just another comment</p>
        <img src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
    </div>
    <div class='friend'>
        <h3>John Smith</h3>
        <p>Just another comment</p>
        <img src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
    </div>
</section>

CSS 的CSS

  body {
    font: 14px/20px 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: #333;
}
    a {
    color: #333;
    text-decoration: none;
    }

    h1, h2, h3 {
    font-weight: 400;
    }

    h1 {
    font-size: 30px;
    }

    h2 {
    font-size: 24px;
    }

    h3 {
    font-size: 20px;
    }

    img {
      height: auto;
      width: 100%;
    }

    section {
    padding: 30px 60px;
    }

    .friend img {
    height: 70px;
    width: 100px;
    display: block;
    }

you would want to add float to your image 您想在图片中添加浮点数
like 喜欢

.friend img{
 float:left;
}

here's a fiddle 这是一个小提琴

Float your h3 and p tags to the right. 将您的h3p标签浮动到右侧。

.friend h3, .friend p {
    float: right;
}

Altneratively, have the image first and float it to the left. 替代性地,先放置图像并将其浮动到左侧。

http://css-tricks.com/all-about-floats/ http://css-tricks.com/all-about-floats/

https://developer.mozilla.org/en-US/docs/Web/CSS/float https://developer.mozilla.org/zh-CN/docs/Web/CSS/float

I would recommend you to use inline-block instead of float in CSS with vertical-align, here you can see the result: http://jsfiddle.net/gG5uv/3/ . 我建议您在CSS中使用inline-block而不是float进行垂直对齐,在这里您可以看到结果: http : //jsfiddle.net/gG5uv/3/

.friend img {
    height: 70px;
    width: 100px;
    display: inline-block;
    vertical-align: top;
}
.friend .data {
    display: inline-block;
    vertical-align: top;
}

I've also added a semantic separation between image and personal data of each item creating a div with class data . 我还添加了每个项目的图像和个人数据之间的语义分隔,以类data创建div

Hey You can check your solution here at http://jsbin.com/edit/637/ . 嘿,您可以在http://jsbin.com/edit/637/上查看您的解决方案。 Just a few changes in your code. 只需对代码进行一些更改。

HTML 的HTML

<div class="friend">
  <img id ='friend-image' src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
                <div id="friend-bio">
                    <h4>John Smith</h4>
                    <p>Just another comment</p>
                </div>
</div>
<br>
<div class="friend">
  <img id ='friend-image' src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
                <div id="friend-bio">
                    <h4>John Smith</h4>
                    <p>Just another comment</p>
                </div>
</div>
<br>
<div class="friend">
  <img id ='friend-image' src='http://media.dunkedcdn.com/assets/prod/13/700x0-5_p17o72pss9bbmvuspb1gl61ot23.jpg'>
                <div id="friend-bio">
                    <h4>John Smith</h4>
                    <p>Just another comment</p>
                </div>
</div>

and CSS 和CSS

.friend #friend-image {
    border: 1px solid #F0F2F8;
    display: inline-block;
    float: left;
    height: 85px;
    width: 84px;
}
#main #friend #friend-bio {
    float: left;
    font-size: 14px;
    margin: -7px 0 0 20px;
    width: 454px;
}
#main #friend #friend-bio h4 {
    font-size: 18px;
    font-weight: normal;
    margin: 0 0 5px;
}

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

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