html - 怎么把文字移到图片旁边

标签 html css

您已经构建了一个 HTML 页面和一个文章,但它出现在图像中减去图像和文本之间的空间

我想让文字紧挨着图片,这样它的形状就与众不同

html:

/* Start content Article .. */

.contentmqal {
    width: 80%;
    float: left;
}

article {
    margin: 15px;
    background: #f7e9e3;
    border-radius: 8px;
    padding: 8px;
}

article section {
    float: right;
    clear: left
}

article section p {
    font-family: 'Source Sans Pro', sans-serif;
}
            <div class="contentmqal">
            <!-- Start Content Article -->
            <article>
                <section>
                    <h3>One Year ago: Durian Fruit</h3>
                    <p>The durian is a tropical fruit. It is from Malaysia. People know it for its sharp smell. Some people say... <span>read more</span></p>
                </section>
                <img src="image/a1.jpg" alt="Durain Fruit" title="One Year ago: Durian Fruit" width="238px" />
            </article>
            </div>
<!-- End Content Artcle -->

http://prntscr.com/lo22wh

我想要红框里的文字

最佳答案

对容器使用flex

试试这个。如果你想让它们居中,也可以使用 align-items:center

同时将 order:2 设置为 section 使其 float 到右侧

试试这个

/* Start content Article .. */

.contentmqal {
    width: 80%;
    float: left;
}

article {
    margin: 15px;
    background: #f7e9e3;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    align-items: center;
}

article section {
    float: right;
    clear: left;
    order: 2;
}

article section p {
    font-family: 'Source Sans Pro', sans-serif;
}
            <div class="contentmqal">
            <!-- Start Content Article -->
            <article>
                <section>
                    <h3>One Year ago: Durian Fruit</h3>
                    <p>The durian is a tropical fruit. It is from Malaysia. People know it for its sharp smell. Some people say... <span>read more</span></p>
                </section>
<img src="image/a1.jpg" alt="Durain Fruit" title="One Year ago: Durian Fruit" width="238px" />
            </article>
            </div>
<!-- End Content Artcle -->

关于html - 怎么把文字移到图片旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53520305/

相关文章:

javascript - 删除以前的 "droppable"jQuery UI

html - 仅在 FireFox 中文档顶部附近存在无法解释的空格

html - div高度显示为零

javascript - 如何知道网页中的flash来自哪里?

html - 在 ReactJS 上,我的 'root' div 并没有一直向上延伸。我怎样才能扩大它?

jquery - jQuery能否获取未绘制的动态元素的大小

javascript - 如何使工具提示在超宽元素上围绕光标 float

javascript - 突出显示列表的 parent ,但不是所有 child

html - 如何将下拉菜单中的子菜单从垂直更改为水平

css - SASS/SCSS @extend 规则选择器