Issues surrounding horizontal scrolling using CSS and HTML

Recently, I've been honing my coding skills by creating websites using HTML and CSS. I came up with an interesting concept for a horizontal scrolling menu. You know the type I'm talking about - where clicking on one item jumps to another in a cyclical pattern (e.g., clicking 'a' takes you to 'b', then 'b' to 'c', and so on). However, I've hit a roadblock when it comes to implementing the href tags. The functionality seems to work only once; after that initial jump from 'a' to 'b,' subsequent clicks fail to navigate further. Can anyone assist me with this issue? Your help is greatly appreciated.

.portfolioWrapper .portScroller {
  overflow: auto;
  white-space: nowrap;
  height: 100%;
}

.portfolioWrapper .portScroller li.a {
  width: 100%;
  background-color: blue;
  display: inline-block;
  text-align: center;
}

.portfolioWrapper .portScroller li.b {
  width: 100%;
  background-color: red;
  display: inline-block;
  text-align: center;
}

.portfolioWrapper .portScroller li.c {
  width: 100%;
  background-color: green;
  display: inline-block;
  text-align: center;
}

li.a a.oneAnch {
  text-align: right;
}

li.a a.twoAnch {
  text-align: right;
}

li.a a.threeAnch {
  text-align: right;
}
<div class="portfolioWrapper">
  <a id="portAnchor"></a>
  <div class="portScroller">
    <li class="a"><a href="#prj2" class="one">a</a></li>
    <a id="prj1" class="oneAnch"></a>
    <li class="b"><a href="#prj3" class="two">b</a></li>
    <a id="prj2" class="twoAnch"></a>
    <li class="c"><a href="#prj1" class="three">c</a></li>
    <a id="prj3" class="threeAnch"></a>
  </div>
</div>

Answer №1

To prevent encountering this issue, you can address it by specifying an <a> element to indicate the initial position before the list.

/* The styles below have been newly implemented. */
a {
  color: white;
  text-decoration: none;
}

.portfolioWrapper .portScroller {
  overflow: auto;
  white-space: nowrap;
  height: 100%;
}

.portfolioWrapper .portScroller li.a {
  width: 100%;
  background-color: blue;
  display: inline-block;
  text-align: center;
}

.portfolioWrapper .portScroller li.b {
  width: 100%;
  background-color: red;
  display: inline-block;
  text-align: center;
}

.portfolioWrapper .portScroller li.c {
  width: 100%;
  background-color: green;
  display: inline-block;
  text-align: center;
}

li.a a.oneAnch {
  text-align: right;
}

li.a a.twoAnch {
  text-align: right;
}

li.a a.threeAnch {
  text-align: right;
}
<div class="portfolioWrapper">
    <a id="portAnchor"></a>

    <div class="portScroller"> 
        <!-- New line included below. -->
        <a id="start" class="oneAnch"></a>

        <li class="a">
            <a href="#prj2" class="one">First</a>
        </li>
        <a id="prj1" class="oneAnch"></a>

        <li class="b">
            <a href="#prj3" class="two">Second</a>
        </li>
        <a id="prj2" class="twoAnch"></a>

        <li class="c">
            <!-- Modified line displayed beneath. -->
            <a href="#start" class="three">Third</a>
        </li>
        <a id="prj3" class="threeAnch"></a>

    </div>
</div>

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

What is the process for creating a two-column table in Angular?

Currently, I have an Angular template code that displays the header on the left and data on the right in a top to bottom layout. <div class="panel-body"> <table class="table table-striped"> <tr ng-repeat="f in fields"&g ...

Tips for customizing WTForm fields with unique CSS classes

I've recently put together a basic form snippet: class PostForm(FlaskForm): # for publishing a new blog post title = StringField("Title", validators=[DataRequired()]) submit = SubmitField('Post') The structure of my HT ...

HTML/Javascript/CSS Templates: Keeping Tabs on Progress

I'm looking for templates that use notepad as an editor for html/javascript/css. I want to find a template that displays text or pictures upon clicking, like the example below: Sorry if this is a silly question, it's been 8 years since I last di ...

Utilize the DataTables plugin to arrange a column based on icons with hidden boolean values in rows

I am currently utilizing the DataTables plugin to enhance my HTML table. While I have managed to successfully implement most functionalities, I am facing a challenge with the boolean column. This particular column consists of icons representing X (value 0) ...

The z-index property in CSS is ineffective on Firefox browsers

My current project involves implementing a dual slider input range. The HTML code I have written looks like this: .acCalcInputRange input[type="range"] { pointer-events: none; position: absolute; bottom: 0.6rem; border: none; outline: none; ...

The line segment refuses to remain hidden beneath the h2 tag

Just getting started with HTML/CSS here! I'm trying to figure out how to keep a line directly under an h2 tag. In my code, there's an h2 tag labeled 'Instructions' followed by a div containing 3 other divs making up a line segment. By d ...

Tips for choosing the class=" * " using jQuery's .html() function

Is there a way to target the string "class" or any other specified string within code retrieved from .html()? If we have an element's HTML content stored in another element (similar to a snippet with preview) <div class="myClass">1</div> ...

Reorganizing bootstrap grids for smaller devices such as extra small screens

Below is a snippet of my HTML markup: <div class="row"> <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12"> Some contents </div> <div class="col-lg-1 col-md-1 col-sm-1 col-xs-12" > Some Content </d ...

Tips for displaying a table with a button click

I am struggling to figure out how to embed a table inside a button in order to display the table when the button is clicked and hide it when clicked again. Below is the code I have been working with: function toggleTable(){ document.getElementById ...

Retrieving the Href attribute from a designated div class with JQuery

I'm currently developing a Google Chrome extension where I need to extract the source code of a webpage using a jQuery get function. Here is how I implemented it: $.get(link,function(data){ // The entire source code of the link will be stored in the ...

template for login page with google closure UI design

Just starting out with google closure... are there any templates provided by Google for creating a basic user registration/login page? Most of what I've found so far seems to focus on UI manipulation and DOM creation. ...

The dimensions of the HTML table have expanded excessively following the execution of mysql_fetch_assoc

I have encountered an issue where, after inserting the database values into an HTML table, the table becomes too large. I've tried using CSS code to adjust it, but it doesn't help. Should I consider changing something in the database value type? ...

Adding flair to a fresh element and then removing it upon its inception

I'm working with a JavaScript code that creates a new element when a button is clicked. I have a question about it. Here's the JavaScript code snippet: var comment = document.querySelector("#AddComment"); var req = new XMLHttpRequest(); if(comm ...

What is the method for including a TabIndex property in a JSON file?

https://i.sstatic.net/ISi72.png I discussed the integration of HTML fields within a JSON file and highlighted how to utilize the TabIndex property effectively in JSON files. ...

Is there a way to delay loading 'div' until a few seconds after the 'body' has been fully loaded?

Is there a way to delay the appearance of the "text-container" div after the image is displayed? I have attempted to achieve this using JavaScript with the following code: <script> window.onload = function(){ var timer = setTimeout("showText()",700 ...

The sticky navigation bar becomes fixed at the top prematurely

Having a sticky navbar on my Bootstrap-based website, I've implemented the following jQuery code: $(document).ready(function () { var flag = false; function stickNav() { $(".navbar-default").affix({ o ...

How can I eliminate the border appearance from a textfield fieldset component in Material-UI?

I have been struggling to remove the border using CSS code I found on Stack Overflow, but unfortunately, the issue persists. If anyone could kindly assist me in fixing this problem, I would be extremely grateful. Can someone please advise me on the specif ...

Challenger arises in the realm of Chakra UI styling

Recently, I've encountered an issue with displaying a card using chakra UI and next js. The CSS of chakra UI seems to be messed up, causing all my components to display incorrectly. It was working perfectly fine until yesterday. I tried deleting the . ...

Tips for positioning a hero image perfectly using HTML and CSS

I am looking to display two hero images on the index page and wondering how to align them. My goal is to have both images centered with 50px separation under the header, ensuring they are of equal height. Will using the flex property work for hero images? ...

Images within inline blocks appear to be extending beyond their containing div as though they are

When I check my website in various browsers such as Firefox, IE, Edge, and Safari, I noticed that the images in the "My Specialties" section of the left column are extending outside of the div instead of fitting within it. This problem also occurs in Chrom ...