简体   繁体   English

HTML / CSS图片未包装

[英]HTML/CSS image not wrapping

I'm trying to build a website and when I try make a wrapper for an image, nothing happens. 我正在尝试建立一个网站,当我尝试为图像包装时,什么也没发生。 The aim is to make a section with an image I can use as a background and the wrapper hold the content in order (centered etc). 目的是用我可以用作背景的图像制作一个部分,包装器将内容按顺序放置(居中等)。

CSS CSS

.image-wrapper {
    width:150px;
    margin:0 auto;
}

HTML HTML

<section>
    <img src="img/animebreeze.jpg" alt="animeb-image">
    <div class="image-wrapper">
    </img>
    </div>
</section>

You have mistake in your HTML </img> 您的HTML错误</img>

<section>
    <img src="img/animebreeze.jpg" alt="animeb-image">
        <div class="image-wrapper">
    </img>
</div> </section>

Should be 应该

<section>
    <div class="image-wrapper">
        <img src="img/animebreeze.jpg" alt="animeb-image">
    </div>
</section>

Fiddle 小提琴

Place the img tag inside the image-wrapper . img标签放在image-wrapper

There is no closing tag for <img> tag. <img>标签没有结束标签。

CSS CSS

.image-wrapper { margin: 0 auto; }  

HTML HTML

<section>
      <div class="image-wrapper"><img src="img/animebreeze.jpg" alt="animeb-image"></div>
    </section>

You can try this way as well: 您也可以尝试这种方式:

CSS CSS

.image-wrapper { background: url(img/animebreeze.jpg)no-repeat center center; }

Using a background-image in your CSS, you don't use the <img> tag now. 在CSS中使用background-image ,您现在不使用<img>标签。

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

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