How do I stop an image displaying outside of the div

后端 未结 6 946
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 01:25

Consider this code...

&l
相关标签:
6条回答
  • 2021-01-04 01:36

    Add overflow: hidden to your #outer rule: http://jsfiddle.net/saluce/qJWte/

    <div id="outer" style="position:absolute;width:100px;height:100px;border:1px solid black; overflow: none">
      <div id="inner">
        <img src="http://rabbitempire.org/wp-content/uploads/Pet-Rabbit-Facts.jpg">
      </div>
    </div>​
    
    0 讨论(0)
  • 2021-01-04 01:41
    div#outer { overflow:hidden; }​
    

    demo here: http://jsfiddle.net/J34aJ/

    0 讨论(0)
  • 2021-01-04 01:51

    re-write your outer div style to apply overflow:hidden

    <div id="outer" style="position:absolute;width:100px;height:100px;border:1px solid black; overflow:hidden;">
          <div id="inner">
            <img src="http://rabbitempire.org/wp-content/uploads/Pet-Rabbit-Facts.jpg">
          </div>
        </div>
    
    0 讨论(0)
  • 2021-01-04 01:53

    You can just apply img { max-width: 100%; height: auto; } to image tag

    0 讨论(0)
  • 2021-01-04 02:01

    You can lose the #inner div and add overflow: hidden; to the #outer div.

    #outer {
      overflow: hidden;
    }
    
    0 讨论(0)
  • 2021-01-04 02:03

    It's as simple as this:

    overflow: hidden;
    
    0 讨论(0)
提交回复
热议问题