The problem is clear, you are trying to resize the window. Which indeed, shortens the width and height (
in your case only width is to be discussed) of the browser's viewport.
When you shorten the page, the element moves to the next line, because there is not enough space for the element to be rendered on that row. Thus, it moves to the next row. In such cases, it is better to use CSS3 media queries. This way, you will be able to create a separate theme for your elements in different screen sizes. For example:
@media screen and (max-width: 300px) {
}
In the media case, you can change the layout of your elements or decrease their paddings, margins and widths so that they can fit into that space. I would also recommend that you try to use the developer tools and check into how elements are resized when your viewport resizes. Try pressing
F12 and then check how resolution and elements are rendered. It would at least
give you an idea of what is going on.
For more, please read
CSS Media Queries on MDN[
^].