Stop wide image from producing horizontal scrollbar

我的未来我决定 提交于 2021-02-19 02:22:48

问题


On a webpage I have a wide image, which should take up the right 50% of the screen. It appears as I want it to, but it produces an unwanted horizontal scroll bar. I don't want the image to scale down, I want it to remain looking exactly as it does, but to not produce a horizontal scroll bar. How could I do this?

HTML:

<div class="image">
</div>

CSS:

.image {
    position:absolute;
    left:50%;
    background-image: url('Images/banneriPhone.png');
    width:774px;
    height:759px;
}

EDIT: I had some suggestions that i remove the overflow option. This didn't work, so i changed the code around (put the image in the html) but this still didn't work. Here's the CSSDesk link:

http://cssdesk.com/mqZpC


回答1:


Use this in your CSS to hide the scrollbar of the CSS class image:

.image {
    position:absolute;
    left:50%;
    background-image: url('Images/banneriPhone.png');
    width:774px;
    height:759px;
    overflow-x:hidden;
    overflow-y:hidden;
}

overflow-x will hide the horizontal scrollbar

overflow-y will hide the vertical scrollbar


Edit: Here you can see some example of the overflow property: http://www.brunildo.org/test/Overflowxy2.html




回答2:


To remove the scrollbar on the image, I did the following and it worked. Add the below to your class where the image is on CSS:

overflow:hidden;



回答3:


Apply the following css rules on the element:

box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;

And set your margins:

margin:0;

The paddings can be left intact because of the box-sizing rules (the padding is not included in the width of the image, which is probably set to 100%).



来源:https://stackoverflow.com/questions/16374068/stop-wide-image-from-producing-horizontal-scrollbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!