Search code examples
htmlcssimagemarkdownfigure

Scroll bar is automatically added to figure element


When I try to add an image inside a <figure> element, sometimes I get a vertical scroll bar next to it in my markdown editor. If I export it to HTML, it is gone, but if I export it to PDF, the scroll bar persists. This is unpleasant and ugly and I do not know how to get rid of it. This is what I use as html and CSS:

figure {
    display: block;
}

figure img{
    max-width: 70%;
    height: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
}
figcaption {
    color: #9BB4BC;
    text-align: center;
    font-style: italic;
    font-size: 1em;
}
<figure>
    <img src="https://i.imgur.com/RGLj3oV.jpg" />
    <figcaption>Hello</figcaption>
</figure>

figure with scroll bar


Solution

  • The vertical scroll bars appears because the height of the element is not big enough, to fix this use the css attribute height: auto; in the figure section.

    for now I interpret you want to keep the scrolling but simply disable the showing of the scrolling bar, to do this do the following.

    Add overflow: hidden; to hide both the horizontal and vertical scrollbar.

    body { overflow: hidden; /* Hide scrollbars */ } To only hide the vertical scrollbar, or only the horizontal scrollbar, use overflow-y or overflow-x:

    body { overflow-y: hidden; /* Hide vertical scrollbar */ overflow-x: hidden; /* Hide horizontal scrollbar */ }

    source: w3school