Tips for maintaining element size without reducing it

I am trying to create a scrollable slider with these rectangles, but the issue arises when the window size is reduced and the rectangles scale down.

I have included images for better clarification.

I attempted to set the width and height of the div elements with the "years" class, but it did not resolve the problem.

.years-center {
    text-align: center;
    display: flex;
    overflow-x: scroll;
}

.years {
    display: inline-block;
    margin: 10px;
    width: 220px;
    height: 150px;
    background-color: #FFFFFF;
    margin-top: -60px;
    box-shadow: 0 0px 29px rgba(0,0,0,0.15);
}

.years-p {
    font-size: 80px;
    color: rgb(68, 68, 68);
    font-weight: 900;
    line-height: 0.252;
    text-align: center;
    padding-top: 45px;
}

.years-name {
    font-size: 21px;
    font-family: "Muli";
    color: rgb(68, 68, 68);
    font-weight: bold;
    line-height: 1.238;
    text-align: center;
    padding-top: 34px;
}
<div class="years-center">
    <div class="years years1">
        <p class="years-p">8</p>
        <p class="years-name">let na trhu</p>
    </div>
    <div class="years years2">
        <p class="years-p">10</p>
        <p class="years-name">profesionálů</p>
    </div>
    <div class="years years3">
        <p class="years-p">32</p>
        <p class="years-name">stálých klientů</p>
    </div>
    <div class="years years4">
        <p class="years-p">27</p>
        <p class="years-name">věkový průměr</p>
    </div>
</div>

Another similar issue can be seen in this section. The solution provided only addresses the first problem.

incorrect correct

HTML

     <div class="trusts-slider">
        <div class="company">
            <div><img src="img/duveruje/prima.png" alt="prima"></div>
            <div><img src="img/duveruje/hayashi.png" alt="hayashi"></div>
            <div><img src="img/duveruje/projekt.png" alt="projekt"></div>
            <div><img src="img/duveruje/heckl.png" alt="heckl"></div>
        </div>
        <div class="company second-company">
            <div><img src="img/duveruje/energy.png" alt="energy"></div>
            <div><img src="img/duveruje/ipconnect.png" alt="ipconnect"></div>
            <div><img src="img/duveruje/rts.png" alt="rts"></div>
            <div><img src="img/duveruje/cejka.png" alt="cejka"></div>
        </div>
    </div>

CSS

.trusts-slider {
    overflow-x: scroll;
}

.company {
    margin-left: 14%;
    margin-right: 14%;
    display: flex;
    justify-content: space-between;
    text-align: center;
    padding-bottom: 17px;
}

.company div {
    padding-top: 50px;
    background-color: white;
    width: 240px !important;
    height: 170px !important;
    box-shadow: 0 0px 29px rgba(0,0,0,0.06);
    margin-left: 10px;
    margin-right: 10px;
}

.second-company {
    padding-bottom: 69px;
}

Answer №1

To prevent elements from adjusting to the width of the parent element, try using white-space: nowrap;. Keep in mind that this may not work if the display is set to flex.

Give this a shot!

.years-center {
    white-space: nowrap; /* <--- added */
    text-align: center;
    display: block; /* <--- updated */
    overflow-x: scroll;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Employing the html.validationmessagefor to display a client-side error notification

My text fields have server-side validation messages. The field 'title' is a required field on the server side with a '[Required]' data attribute in the class, but it only seems to be checked on a postback or form submit. I am saving the ...

The navigation menu links that are meant to stay fixed at the top of the page are not functioning

On my website, I implemented Foundation's Magellan sticky menu at the bottom. Strangely, when I view the site in Firefox, the menu functions properly. However, when I try to open it in Google Chrome, the links don't work (and the cursor pointer d ...

Error Encountered in HTML Form

I've created a form, but when I hit the submit button, an error pops up, and I can't figure out what's causing it. <div class="status alert alert-success" style="display: none"></div> <form name="contactform" method="post" ...

Making the Select Tag function as an on-click event in JQuery

So I currently have a tab set up that functions as on click links when viewed on desktop. However, for tablet and mobile devices, I need it to be transformed into a select drop down list while maintaining the same functionality. Below is the code used for ...

What makes the AngularJS ng-repeat search term filter fail to function properly?

I am attempting to create a dynamic table that filters and displays only rows containing the search term entered in the search box. Following a basic example from the w3schools tutorial, I am trying to get it to work properly: https://www.w3schools.com/ang ...

Can you suggest some unconventional HTML/CSS attributes and tools for arranging a form in a way that results in a unique tab order?

As part of my role, I am tasked with transforming mock specs provided by our clients into custom web forms. Our application comes equipped with tools specifically developed to streamline this process. Recently, I was presented with a particularly intriguin ...

Adjusting the height of table rows based on the content within the <td> element

I am facing a challenge with a table that includes rows with 2 columns - one for images and the other for text. The issue arises when resizing large images in one column, causing the row to take its height from the image cell rather than the text cell. Sin ...

Spin Picture while Moving Down

I'm currently working on a website where I want the arrow images to rotate when a contact form is expanded, and then rotate back when it's collapsed. Here's the code I've been using: $(document).ready(function(){ $ ...

Eliminate spaces between divs without any margins or padding

In my HTML code, I have two divs with different classes - mini-date-holder and mini-event-holder. Even though both of these divs are set to have no margin or padding, they are still displaying with a gap between them. I'm struggling to understand why ...

Revealing information about a photo when hovering over it

I am currently working on a project where I need to display images from a database in two columns. My goal is to have additional details about each image, such as the country and year it was taken, appear when I hover over them. A good example of what I&ap ...

The absolute positioning of the element makes it invisible

I've run into an issue with adding arrows to my slider. The arrows aren't displaying on the page properly - they show up for a split second when I refresh the page, and then disappear. Any ideas on what might be causing this problem? .slider { ...

How can you use CSS to style an image's title attribute?

I am trying to customize the text displayed when hovering over an image. Despite my efforts, the code I used doesn't seem to be working properly: <body> <img src="img.jpg" title="<span class='title'>title</span>" &g ...

Full scale intricate grid arrangement

Is there a way to make this header 'full width' so that the image appears on the left side of the screen while keeping the content in the grid? https://i.sstatic.net/U6pft.png I was considering creating a new container. .container--full { max- ...

The MDB Bootstrap collapse fails to display on the initial click

Every time I click on the button, there seems to be a delay in showing the collapse feature. It's strange because on subsequent clicks it works fine ...

The variable that was posted in the JavaScript 'if' statement seemed to vanish in an instant

My website has forms that send data to a PHP file, triggering the appearance of items in a cart: <form method="post"><fieldset> <input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" /> <i ...

Leveraging SweetAlert with JavaScript

My question echoes that of a fellow user: Sweetalert - Call function in Javascript Despite the responses provided in the aforementioned question, I am unable to identify the issue. Following guidelines, I downloaded the .js and .css files from , saving ...

The Javascript style.opacity function eliminates the leading zero from the input string

In my application, users have the ability to change the color of the background but not the pattern. They can adjust the background behind the pattern and the opacity of the pattern. Users are prompted to input a percentage, which is actually a number betw ...

What is preventing me from assigning all padding values at once?

I attempted to modify all paddings of the html element using JavaScript, with the following code: const pd = 1 document.getElementsByClassName('board')[0].style.paddingRight = pd + 'px' document.getElementsByClassName('board') ...

Make HTML design responsive to any screen size

After completing the design of a mobile app interface with dimensions 750w by 1334H, I encountered an issue where it appears too large on the app testing screen. I am seeking a way to automatically adjust the design to fit all screens without compromising ...

Stop the canvas from repainting when focus is lost

I've been working on a game with Box2D and encountered an issue. Whenever I click on the canvas and then press the "tab" key, the canvas repaint functionality stops. Does anyone have any insights on how to address this problem? Check out the demo o ...