Is it possible to create horizontal scrolling lanes using HTML and CSS?

Simple code snippet:

<div id="page-wrap">

    <div class="post horizontal">

        <h2>Headline 01</h2>

        <div class="entry">
            <p>Lorem ipsum dolor...</p>
<p class="image"><img class="alignnone" src="some.jpg" alt="" width="1024" height="768"></p>
<p class="image"><img class="alignnone" src="some.jpg" alt="" width="1024" height="768"></p>
<p class="image"><img class="alignnone" src="some.jpg" alt="" width="1024" height="768"></p>
        </div>
    </div>

    <div class="post horizontal">

        <h2>Headline 02</h2>

        <div class="entry">
            <p>Lorem ipsum dolor...</p>
            <p class="image"><img class="alignnone" src="some.jpg" alt="" width="1024" height="768"></p>
            <p class="image"><img class="alignnone" src="some.jpg"" alt=""""" width="1024" height="768"></p>
            <p class="image"><img class="alignnone" src="some.jpg" alt="" width="1024" height="768"></p>
        </div>
    </div>

</div>;
;

CSS for formatting:

.horizontal {
    overflow-x:scroll;
    clear:both;
}

.horizontal p {
    float:left;
    width:500px;
    padding:0 20px 20px 0;
}

.horizontal p.image {
    width:1024px;
}
;

I am trying to create horizontal frames similar to the mockup below without using actual frames.

Right now, the images do not float within .horizontal because of its width being set at 100% inside #page-wrap. They appear underneath each other instead of side by side. I want all images to be aligned horizontally within .horizontal with separate scrollbars for scrolling through the images.

;

Any solutions on how to achieve this?

;

Additionally, I need help with implementing scrollbars and making sure .horizontal only appears when there is content to be scrolled (i.e., if no images are present, the scrollbar should not appear).

;

Your assistance would be greatly appreciated!

;

By the way, jQuery is part of my project. Can this be achieved solely with JavaScript?

;

Answer №1

After reviewing the provided mockup, it appears that:

  1. Despite each image being in its own paragraph in the markup, you prefer them to be displayed inline, on the same line.

  2. You require the container to have a horizontal scroll bar.

  3. The images should utilize this scroll bar by not wrapping onto multiple lines when exceeding the width of the container.

To achieve this layout, CSS can be used as shown below:

.horizontal p.image {
    display: inline;         /* 1 */
}

.entry {
    overflow-x: scroll;      /* 2 */
    white-space: nowrap;     /* 3 */
}

For demonstration purposes, here is a sample utilizing the CSS above with your markup (image constraints adjusted for better display in a smaller window): http://jsfiddle.net/TT9hq/

If the scroll bar should only appear when there are enough wide images to warrant it, replace overflow-x: scroll with overflow-x: auto.

Answer №2

To ensure your images appear on the same line, consider using spans instead of enclosing them in a paragraph tag like p. Alternatively, you can apply the style display:inline directly to the images without any wrapping element. To address the scrolling issue, set overflow-x: auto on the container div rather than using overflow-x:scroll.

UPDATE: If keeping the images within p tags is necessary, add display:inline to the p tags themselves.

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

Adjust the left and right margins while maintaining the vertical margin spacing

Is there a way to apply horizontal margin while inheriting vertical margin without explicitly setting margin-left and margin-right? I was hoping for something like margin: inherit 20px; to be effective. Take a look at the example here: https://jsfiddle.ne ...

css background-size and image position not working

On my website, users/members can upload or link a custom image for the start page. This feature works well with modern browsers that support background-size in CSS. However, if the browser does not support css3 background-size, the image may not fill the e ...

Is it possible to apply a complete style sheet to a single div element only?

I'm currently working on a website and I want to incorporate a dynamic bootstrap calendar. The issue I'm facing is that my site has its own style sheet, but the calendar comes with its own styles. When I try to integrate the two, it seems like el ...

Add a new class to an element located in a separate div using JavaScript

$(document).ready(function() { $('.btn').click(function() { $(this).parent().addClass('show'); }); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div clas ...

The header and sub-navigation are in disarray and require some help

Dear web experts, After six months of learning to code websites, I'm tackling a big project with some challenges. The recent changes to the header and subnav have thrown everything off balance, making it look wonky and not quite right. Specifically, ...

What is the best way to define my background image using markup language?

I'm facing a challenge with some code that I didn't write which includes a background-image. While I want to maintain the identical appearance, I prefer to set the image in my markup rather than CSS. However, I'm unsure of how to do this. T ...

View text preview split across multiple pages

When using the <p> tag to display information, I noticed that when I print preview it, the words are split onto another page. Is there a way to prevent this from happening? See the sample below: https://i.sstatic.net/1EHIV.jpg ...

Showing Stationary Pictures at Full Size in OpenLayers

I am trying to showcase static images as maps using a StaticImage layer in ol3, with the image size set at 100% in pixels. However, I am facing difficulty in ensuring that the displayed images are always the correct size based on the extent and zoom variab ...

Updating background image of subclass with hover effect in CSS

Here is the code I have for a tab that can be selected: <div class="tabOff"> <div class="lightCorner TL"></div><div class="lightCorner TR"></div> <div class="cornerBoxInner"> <p>My Tab</p> &l ...

Understanding the integration of sass with webpack in an Angular 4 project

Is it possible to reference a sass file instead of a css file directly in the index.html? If so, how does webpack compile the sass into a css file? Additionally, what is the most effective way to bundle the sass file when building the application? The ve ...

Purchase Now with Paypal Button

Just starting out with PHP and PayPal buttons! Important: Referring to Mysql items here. I'm attempting to set up an online shop, but I have a concern about PayPal "Buy Now" buttons. If a customer purchases an item, the website receives the money, b ...

Using jQuery to smoothly animate a sliding box horizontally

Is there a way to smoothly slide a div left and right using jQuery animation? I have been trying to achieve this by implementing the code below, which can be found in this fiddle. The issue I am facing is that every time I click on the left or right butto ...

Searching for mobile WiFi preferences through a web browserHere are the steps to

Is there a method to access mobile connectivity settings through a website? I am interested in determining the connection type (3G\4G\WiFi) and if it is WiFi, identifying the security method being used. Is this achievable? If so, how? Edit: If ...

Error message in JS/Ajax alert box

I keep receiving an alert box saying "Image uploaded" even when the variable $imagename is empty. Below is the script in question: <script> function ajax_post1(ca){ var cat = ca; var name = document.getElementById("name").value; var ...

What is the best way to position one of my links at the end of a bootstrap navbar?

insert image description here I'm currently working on implementing a Bootstrap navbar and I am trying to align one of the links, specifically the last one, to the right side. Although I have searched through the documentation, I have not been able t ...

Is It Always Necessary to Specify a Width and Height for an Image?

Is it necessary to specify both the Width and Height of an image on a webpage for consistent display across all browsers, or is specifying just one sufficient? While it may appear fine on certain browsers, I want to double-check for accuracy. Appreciate ...

Tips for enabling the background div to scroll while the modal is being displayed

When the shadow view modal pops up, I still want my background div to remain scrollable. Is there a way to achieve this? .main-wrapper { display: flex; flex-direction: column; flex-wrap: nowrap; width: 100%; height: 100%; overflow-x: hidden; ...

The process of enriching an ASP.NET hyperlink by making it both bold and under

I'm currently working on a webpage in asp.net. I have two hyperlinks and I want to make them active by applying a style sheet that makes them bolder and underlined, but for some reason it's not working. Here is the HTML: <li style="margin-le ...

I am facing an issue where my CSS file is not connecting with my HTML

I added the link to my html pages, but my css is only showing up on the first page and not on any of the others. <head> <title>Angels Drawings</title> <link rel="stylesheet" href="style.css"> <STYLE> <!- ...

Ajax calls within nested functions are not being executed in the correct sequence

Currently, I am utilizing the geonames API to retrieve geographical information. My objective is to extract the names of states within a country using the getStateInfo function and subsequently obtain a list of cities in each state through the getCityInfo ...