Creating a horizontal layout for list items that are responsive using CSS

My website has a "Featured" section with 3 equally sized elements displayed horizontally. I want to make the webpage responsive by using percentage widths, but when I resize the window to less than the list width, the items stack on top of each other.

Check out the demo here

I've experimented with adding max-width and adjusting widths to be either auto or 100%, but so far I haven't had any success.

I suspect that my approach might be wrong, as I have list items within anchor tags to make the entire item clickable.

Below is part of my code, with the full version available on the fiddle:

CSS:

.FeatureRow {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
}
.FeatureRow li {
    float: left;
    width: auto;
    margin: 10px;
    background-image:    -moz-linear-gradient(top, #fbfbfb, #ffffff);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fbfbfb), to(#ffffff));
    background-image: -webkit-linear-gradient(top, #fbfbfb, #ffffff);
    background-image:      -o-linear-gradient(top, #fbfbfb, #ffffff);
    background-image:         linear-gradient(to bottom, #fbfbfb, #ffffff);
    background-repeat: repeat-x;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}
.FeatureRow a {
    padding: 10px;
    display: block;
    width: 100%;
    max-width: 260px;
    height: auto;
            border-radius: 5px;
    -webkit-border-radius: 5px;
       -moz-border-radius: 5px;
    -webkit-box-shadow: 0px 4px 8px #f5f5f5;
       -moz-box-shadow: 0px 4px 8px #f5f5f5;
            box-shadow: 0px 4px 8px #f5f5f5;
    background-color: transparent;
    transition: all 500ms ease-in-out;
    -webkit-transition: all 500ms ease-in-out;
       -moz-transition: all 500ms ease-in-out;
        -ms-transition: all 500ms ease-in-out;
         -o-transition: all 500ms ease-in-out;
}

HTML:

<ul class="FeatureRow">
<li>
    <a href="/contact/">
        <h2 class="SpeechBg">Need some help?</h2>
        <p>Feel free to get in contact with us</p>
    </a>
</li>
<li>
    <a href="/property/">
        <h2 class="BinocularsBg">Country or City?</h2>
        <p>You can always find a place, no matter where it is!</p>
    </a>
</li>
<li>
    <a href="/property/">
        <h2 class="CameraBg">Now that's scenery!</h2>
        <p>We guarantee that you will love the views from all of our unique locations</p>
    </a>
</li>
</ul>

Answer №1

This simple addition makes a difference.

.FeatureRow li{
    width: 30%;
    display: inline-block;
}

However, on narrower screens, it's often better to stack them vertically for better readability.

Answer №2

To achieve the desired layout, you must incorporate the @media selector in your CSS code.

For a visual example, check out this fiddle

Below is an excerpt of the CSS3 I used to ensure that the blocks slide underneath each other:

@media(max-width: 880px) {
    .FeatureRow li {
        width: 100%;
    }
}
.FeatureRow a {
    max-width: 100%'

    }
}

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

Place the HTML images in the center of the page

I would like the two images to be centered on the page. Please refer to this visual representation for guidance: Here is the code snippet: * { box-sizing: border-box; } .column { float: left; width: 28%; height: 28%; padding: 5px; } /* Cle ...

What is the process for converting HTML to RTF using Java programming language?

When working with the basic API of JAVA using RTFEditorKit and HTMLEditorKit, I encountered a limitation where certain tags like <br/> and <table> were not recognized. In my search for better solutions to convert HTML to RTF, I came across two ...

How can I retrieve the content from an iframe whenever its state is altered using jQuery?

I am currently working on a project where I need to extract the content from a hidden iframe and display it as HTML in a div every time the iframe changes its loading state. The goal is for it to appear as if the page is being redirected and downloading it ...

The challenges of utilizing breakpoints effectively within Tailwind CSS

So here's the issue. I've gone through various other queries related to this problem but haven't found a solution yet. Tailwind seems to be functioning well except for breakpoints. This is what I have in the head <meta name="viewpo ...

Nightwatch is a tool that allows you to interact with elements on a webpage by clicking on an element within

I have a scenario on my website where I have two separate div elements: <div class="wg-block" data-reactid="10" <div class="wg-header" data-reactid="11"/div> .... <h4 class='condition'> "Text" </h4> <div cl ...

Is there a way to manage specific HTML elements in Angular?

I am working on displaying a list of enable/disable buttons for different users. The goal is to show the appropriate button for each user based on their status - enabling if disabled and disabling if enabled. To achieve this, I have utilized the flags "use ...

The child element extends beyond the boundaries of its parent container in HTML

Have you ever encountered a situation where the inner div element is wider than the outer div? It can be a bit frustrating, but there are ways to address this issue. So, what causes this to happen in the first place? And more importantly, how can we ensur ...

What is the best way to securely transfer data from a Node/Express server to the client using JavaScript, ensuring sanitized HTML and preventing cross-site scripting (X

What is the best method to securely pass data from an Express backend to a client-side JavaScript in order to render it in the DOM using client-side rendering, while also allowing sanitized whitelist HTML and preventing XSS attacks? For example, if the No ...

Issue with customizing Bootstrap5 table colors based on themes

In my latest project, I decided to customize Bootstrap 5.1.3 using Sass in order to introduce some new color themes to the panels. I quickly realized that customizing Bootstrap 5.1.3 is not as straightforward as it was with Bootstrap 4. After updating my ...

SVG tags are not functioning properly

Hello, I am new to working with SVG files. I have a set of icons created using SVG and I am attempting to use the <use> tag in order to display a specific part of an SVG file. However, I seem to be encountering some issues and I am unable to identi ...

Trouble with PHP and HTML Code not functioning properly after loop execution

I created a form with a dropdown menu that pulls options from a MYSQL Database. However, after fetching the options, the button and other components of the code seem to disappear. Everything else works fine when I comment out the PHP Query. <form acti ...

How to achieve a text border effect using inner glow technique

Can someone help me recreate this unique text design? The font used is Gill Sans MT and the text color is a shade of purple although it may be hard to discern. https://i.sstatic.net/HGrB8.png I have been struggling to achieve the vibrant thick border and ...

Paused session in web development

Currently, I am in the process of building a website using HTML and CSS and have encountered an issue. Within my CSS file, I have defined an ID called "full" which sets a wooden background after the sidebar and is intended to span across the entire page. A ...

Show the text area content in an alert when using Code Mirror

When I try to alert the content of a textarea that is being used as a Code Mirror on a button click, it appears blank. However, when I remove the script for Code Mirror, the content displays properly. I am puzzled about what could be causing this issue wi ...

There is a property name missing before the colon in the "(property) : (value)" declaration for a CSS global variable

I have been trying to create a global variable in CSS by following the suggestions I found online. According to various sources, including this article, the correct way to declare a CSS variable is as follows: :root{ --variableName:property; } However, ...

Struggling to find a way to showcase API data on a HTML site

Is there a way to dynamically show the live prices of crypto currencies on my website? I wrote a script that successfully displays the current price, but I'm struggling with implementing auto-refresh using setInterval. Here's the code I have so f ...

What is the optimal location for storing JSON data while dynamically loading via AJAX?

Let's imagine a scenario where there is an HTML page hosting a dynamic modal box. Clicking on different links within the page triggers the modal to open, each showing different content based on the clicked link. The dialog contents are fetched using A ...

Is there a way to prevent the back button from functioning in my web browser?

How can I prevent the back button from being used on my webpage? Can you provide a list of possible methods to achieve this? if($data->num_rows > 0){ while($row = $data->fetch_assoc()){ header('Location:../cashier.php&apo ...

Mobile Chrome allows users to utilize the IFrame player API for enhanced video

Currently, I am working on creating a mobile website where I plan to include some YouTube videos using the IFrame player API (https://developers.google.com/youtube/iframe_api_reference). My main goal is to have the video start playing only after the user ...

``Inconvenience of Extensive URLs Being Displayed in Tables

I've been struggling to find a solution for the problem I'm facing with Chrome when it comes to wrapping long URLs in a table cell. Despite trying various solutions found online, including using the CSS code word-wrap: break-word;, I have not bee ...