The ability to scroll horizontally for individual items within a larger container div

JSFIDDLE: http://jsfiddle.net/7zk1bbs2/

If you take a look at the JSFiddle project, you'll notice that the icons are placed inside an orange box. However, there is a vertical scroll needed to browse through them and I am attempting to enable horizontal scrolling. How can I achieve this?

HTML

<!DOCTYPE>
<HTML>

<head>
    <meta charset="UTF-8">
    <title> My Home Page</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

    <div class="banner">   
        <h1> Welcome!<span style="color:#FF009D" class="dot">•‌</span><span style="color:#12E00B" class="dot">•‌</span><span style="color:#FF9D00" class="dot">•‌</span> </h1>
    </div>
            <div class="wrap"> 
                    <div class="item">    
                        <a href="https://www.youtube.com/user/maxxchewning">
                            <img src="http://i.ytimg.com/vi/HrkZQ3EOmFQ/hqdefault.jpg"/>
                                <div class="button"></div>
                        </a>    
                    </div>

                    <div class="item">
                        <a href="https://www.youtube.com/user/Christianguzmanfitne">
                            <img src="http://i.ytimg.com/vi/zsD_7hkfEwY/hqdefault.jpg"/>
                            <div class="button"></div>
                        </a>         
                    </div>

                    <div class="item">
                        <a href="https://www.youtube.com/user/PhysiquesOfGreatness">
                            <img src="http://v017o.popscreen.com/VzFBeVBjMHhpRWMx_o_new-physiques-of-greatness-intro-25.jpg"/>
                            <div class="button"></div>
                        </a>     
                    </div>

                    <div class="item">    
                        <a href="https://www.reddit.com">
                            <img src="https://pbs.twimg.com/profile_images/459083822470946816/VGv0AGio.png"/>
                                <div class="button"></div>
                        </a>    
                   </div>
                   <div class="item">    
                        <a href="https://www.ebay.com">
                            <img src="https://pbs.twimg.com/profile_images/471350614132129793/NCDCFXva.jpeg"/>
                                <div class="button"></div>
                        </a>    
                   </div>
                    <div class="item">    
                        <a href="https://www.facebook.com">
                            <img src="https://pbs.twimg.com/profile_images/3513354941/24aaffa670e634a7da9a087bfa83abe6_400x400.png"/>
                                <div class="button"></div>
                        </a>    
                   </div>  
            </div>

    <div class="footer"></footer>
</body>

</HTML> 

CSS

body {       
        margin-top:-3px;
}
.banner {
    width:100%;
    height:200px;
    background-color: rgba(64, 201, 255, 1);
    margin-left:-10px;
}

h1 { 
    font-size:80px;
    margin-left:30px;
    font-family:Futura;
    line-height:120px;
    color:rgba(255, 255, 255, 1);
    text-shadow: 2px 2px 3px rgba(255,255,255,0.1);
    width:100%;
    letter-spacing:1px;
    padding-top:30px;

}


h1:hover { 
    font-size:80px;
    font-family:Futura;
    color: rgba(64, 201, 255,.8);
    text-shadow: 2px 2px 3px rgba(255, 255, 255,0.9);
    width:100%;
    padding-top:30px;
}

.wrap{ 
    margin-top:20px;
    width: 100%;
    background-color: rgba(255, 190, 77, 1);
    height:200px;
    margin-left:-10px;
    overflow:auto;
}


.item {
    float:left;
    width:25%;
    padding:0px;
    margin-left: 60px;
    margin-top: 20px;


}

.item img {
    width:100%;
    padding-top:10px;
    max-height:100px;
    opacity:1;
}
.item img:hover {
    opacity:.4;
    -webkit-transform: scale(1.2);
    -moz-transform:    scale(1.2);
    -o-transform:      scale(1.2);
    -ms-transform:     scale(1.2);
}

.button {
    background-color:rgba(64, 201, 255,1);
    height:50px;
    缀width:100%;
    border-bottom-right-radius:.5em;
    border-bottom-left-radius:.5em;    
    transition: background-color 0.3s linear;     
}
.item:hover .button{
    background-color: rgba(255, 0, 157, 1);
    -webkit-transform: scale(1.2);
    -moz-transform:    scale(1.2);
    -o-transform:      scale(1.2);
    -ms-transform:     scale(1.2);

}

Answer №1

Revamp your .wrap class overflow setting to include

overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;

also update the float property of your .item class with

display: inline-block;

The final versions of .wrap and item will resemble this

.wrap{ 
    margin-top:20px;
    width: 100%;
    background-color: rgba(255, 190, 77, 1);
    height:200px;
    margin-left:-10px;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;
}

.item {
    display: inline-block;
    width:25%;
    padding:0px;
    margin-left: 60px;
    margin-top: 20px;
}

This adjustment could potentially solve your issue

Answer №2

With just a few adjustments, you can achieve this by checking out the updated fiddle

Click here to view the changes

 .wrap-in { width:2000px; }
 .item {width:200px}
 .wrap{overflow:hidden;overflow-x:scroll;width:960px}

Answer №3

Your h1 element is extending beyond the boundaries of the .banner container, causing a horizontal scroll on the page.

Here are two solutions:

Option 1: Make the .banner hide any overflow(http://jsfiddle.net/TheIronDeveloper/7zk1bbs2/3/)

.banner {
    overflow:hidden;
}

Although it may require additional styling to look better...

Option 2: Remove the left margin from the h1 element (http://jsfiddle.net/TheIronDeveloper/7zk1bbs2/2/)

h1 {
    margin-left: 0;
}

However, this might affect the padding you intended to have.

Alternatively, you can combine the two solutions (I have tidied up the code for you):

http://jsfiddle.net/TheIronDeveloper/7zk1bbs2/4/

Furthermore, as a CSS tip for your fiddle, when using {selector}:hover, you only need to specify the styles that should change, without repeating what is already defined within {selector}.

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

Prevent cross-site scripting vulnerabilities by replacing the characters "'<'" and "'>'"

Is it possible to protect my website from XSS attacks by simply replacing < and > with &lt; and &gt;, or is there more to consider? For example: <?php echo '<div>' . $escaped . '</div>' ?> I am alread ...

How can you utilize CSS grid to position an alternate symbol alongside ordinary text?

Does anyone have suggestions on how to align an "alt symbol" with "regular text"? I'm struggling to center both elements without resorting to hacky solutions. Currently, I am using CSS grid, but I am open to exploring other solutions that are easy an ...

I would like to know how to create a dropdown menu that shows the country name, flag, and code based on the

I have successfully generated the telephone input field. One requirement is to display the Country flag along with the country name as soon as the dropdown is selected. Another requirement is that once the country is selected, it should display the countr ...

Can someone guide me on how to customize the CSS of a fab element in Onsen UI?

I've been struggling to change the background color or border of the onsen fab element. I'm working with angular 2 and onsen v2. Even after trying the !important rule, my CSS doesn't seem to take effect unless I disable the fabs default styl ...

Error: Unexpected end of argument list in file c:/.../list.ejs during ejs compilation

Hello, I am a beginner in programming and I have been working hard to learn. Unfortunately, I encountered a SyntaxError: missing) after argument list in c://.../list.ejs while compiling ejs error and I am struggling to find the solution. I am reaching out ...

Add a CSS class to a dropdown menu option in HTML and JavaScript (JQuery) if it has a specified ID

I am brand new to HTML and JQuery, and I'm struggling with setting a class for my select element when the currently selected option has an ID of "answer". This is crucial for checking the correctness of a multiple choice question. If achieving this i ...

Upon the second click, the addEventListener function is triggered

When using the window.addEventListener, I am encountering an issue where it only triggers on the second click. This is happening after I initially click on the li element to view the task information, and then click on the delete button which fires the eve ...

Is it possible to achieve the same functionality as :first-child by employing :nth-of-type without a selector?

Currently tackling a console warning related to MUI5/emotion (I believe) I have noticed that the pseudo class ":first-child" might pose potential risks during server-side rendering. It may be worth considering replacing it with ":first-of-type". I wonder ...

Is it possible to alter the name of a slot before displaying the element in the shadowDOM, depending on the slot utilized in the DOM?

In my project, I am working on implementing different features for both desktop and mobile devices. Some of these features can be replaced by slots. My goal is to have a slot that can be either replaced by a desktop slot called poster-foreground, or a mobi ...

Adding dashes as padding in HTML/CSS

I am currently working on updating the user management block on my website and I want to showcase it with some visual examples. I believe that using images is the most effective way to demonstrate changes. This is the current appearance of the block: ...

Turn off scroll bar to create a seamless browsing experience on your website

As I work on creating the frontend for a single-page website with seamless scrolling between divs, I'm looking to eliminate mouse scrolling altogether. I understand that using overflow:hidden; can hide scroll bars, but my goal is to make the page scr ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

Encountering an issue while trying to execute the pagination page demo in PHP?

<?php include("include/db.inc.php"); $sql = mysql_query("SELECT * FROM emp"); $nr = mysql_num_rows($sql); if(isset($_GET['page'])){ $pn = preg_replace('#[^0-9]#i','',$_GET['page']); ...

What could be causing jQuery animate to malfunction on mobile devices when a viewport is present?

Everything seems to be working fine on my desktop webpage, but when I try it on mobile, there is no scroll... $("HTML, BODY").animate({ scrollTop: 500 }, 1000); This post suggests that mobile devices may not scroll on the body, but on the vi ...

Empty screen appears when "npm run serve" command is executed following the build process

I am currently utilizing Material-ui. Following the project build with npm run build, I encounter a blank page when running npm run serve. I attempted to set homepage: "./" in the package.json as suggested here, however, it still displays a blank ...

Chrome is failing to run the keyframe animation transform

This solution seems to function properly on Firefox and Safari, and even on IE! However, it encounters issues when used on Chrome. (It runs smoothly on Firefox and IE, but on Chrome the animation does not display at all!) @keyframes animationFrames{ 0% ...

How can I create my own unique scrolling behavior in JavaScript?

Looking to create a similar effect as seen on this website: where the vertical scrollbar determines the movement of the browser "viewport" along a set path. I believe that using Javascript to track the scroll bar value and adjust background elements acco ...

As the value steadily grows, it continues to rise without interruption

Even though I thought it was a simple issue, I am still struggling to solve it. What I need is for the output value to increment continuously when I click the button. Here is the code snippet I have been working on: $('.submit').on('click&a ...

Does Less undergo a compilation process in a single pass?

Does Less execute a single pass on the files, or does it perform multiple passes? I am particularly worried about what will happen if I include another file that redefines variables and mixins. Will the generated output use the original values, or will it ...

exploring for a keyword on the primary Amazon platform (analyzing)

Hey everyone, I noticed that Amazon's main search bar code looks like this: <input type="submit" class="nav-input" value="Go" tabindex="7"> I'm considering creating a function that will locate this tag on amazon.co.uk and perform a search ...