What is causing the horizontal scrolling issue I am experiencing?

Let's dig into the HTML code I've written:

    /**
font-family: 'Montserrat Subrayada', sans-serif;
font-family: 'Josefin Sans', sans-serif;
font-family: 'Alex Brush', cursive;
font-family: 'Six Caps', sans-serif;
**/

* {
margin: 0;
padding: 0;
}

body {
width: 100vw;
background-color: #fff;
font-size: 100%;
}

#main {
margin: 0;
padding: 0;
position: relative;
height: 100vh;
width: 100%;
background-image: url('../assets/images/bgpattern.png');
}

#vidbox {
margin: 0;
padding: 0;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100vh;
overflow: hidden;
z-index: -1;
}

#bgvid{
width: 100%;
}

#vidfallback{
width: 100%;
}

#navbar {
width: 100%;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #fff;
}

#navbar li {
float: right;
}

#navbar li a {
display: block;
color: rgb(35,85,125);
font-family: 'Josefin Sans', sans-serif;
text-decoration: none;
font-size: 28px;
text-align: center;
padding: 35px 40px;
}

#navbar li a:hover{
color: #666;
-webkit-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    -moz-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
}

#navbar li a:active{
-webkit-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    -moz-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
}

#logo {
height: 80px;
margin: 10px;
}

.left {
float: left!important;
background-color: rgb(35,85,125);
}

.white{
color: #fff!important;
}

#tagline{
font-size: 50px;
font-family: 'Alex Brush', cursive;
margin: 130px;
color: #fff;
}

.bigger{
font-size: 80px;
}

.box{
width: 100%;
height: 200px;
}
<!DOCTYPE html>
    <html>
    <head>
    <title>Testing</title>
    <link rel="stylesheet" type="text/css" href="css/home.css">
    <link href="https://fonts.googleapis.com/css?family=Alex+Brush|Josefin+Sans|Montserrat+Subrayada|Six+Caps" rel="stylesheet">
    <!--<script src="assets/js/jquery-1.12.3.js" type="text/javascript"></script>-->
    </head>
    <body>
    <div id="main">
    <div id="vidbox">
    <video autoplay  poster="" id="bgvid" loop>
    <source src="assets/video/filxe.mp4" type="video/mp4">
    <img src="assets/images/vidfallback.png" id="vidfallback">
    </video>
    </div>
    <ul id="navbar">
    <li class="left"><img src="assets/images/logomini.png" id="logo"></li>
    <li class="left"><a href="" class="white">HK Construction Company</a></li>
    <li><a href="#home" id="home">Home</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">About Us</a></li>
    </ul>
    <h1 id="tagline"><span class="bigger">"</span> You Dream, We Build <span class="bigger">"</span></h1>
    </div>
    <div class="box about">
    
    </div>
    </body>
    </html>

I'm puzzled by the appearance of a horizontal scroll bar in the browser despite all elements having zero padding and margin. Can someone help me identify the issue?

Answer №1

The sizing of the vw unit is determined by the width of the viewport, but browsers calculate the viewport size based on the entire browser window, including space for the scrollbar.

When an element is set to 100vw, it extends beyond the html and body elements causing a horizontal scroll.

Therefore :

Replace :

body {

    width:100vw;

}

With :

body {

    width:100%;

}

Full code:

* {
    margin: 0;
    padding: 0;
}

body {
    width: 100%;
    background-color: #fff;
    font-size: 100%;
}

#main {
    margin: 0;
    padding: 0;
    position: relative;
    height: 100vh;
    width: 100%;
    background-image: url('../assets/images/bgpattern.png');
}

#vidbox {
    margin: 0;
    padding: 0;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    z-index: -1;
}

#bgvid{
    width: 100%;
}

#vidfallback{
    width: 100%;
}

#navbar {
    width: 100%;
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #fff;
}

#navbar li {
    float: right;
}

#navbar li a {
    display: block;
    color: rgb(35,85,125);
    font-family: 'Josefin Sans', sans-serif;
    text-decoration: none;
    font-size: 28px;
    text-align: center;
    padding: 35px 40px;
}

#navbar li a:hover{
    color: #666;
    -webkit-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    -moz-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
}

#navbar li a:active{
    -webkit-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    -moz-box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
    box-shadow:inset 0px -5px 0px 0px rgb(35,85,125);
}

#logo {
    height: 80px;
    margin: 10px;
}

.left {
    float: left!important;
    background-color: rgb(35,85,125);
}

.white{
    color: #fff!important;
}

#tagline{
    font-size: 50px;
    font-family: 'Alex Brush', cursive;
    margin: 130px;
    color: #fff;
}

.bigger{
    font-size: 80px;
}

.box{
    width: 100%;
    height: 200px;
}
<!DOCTYPE html>
    <html>
    <head>
    <title>Testing</title>
    <link rel="stylesheet" type="text/css" href="css/home.css">
    <link href="https://fonts.googleapis.com/css?family=Alex+Brush|Josefin+Sans|Montserrat+Subrayada|Six+Caps" rel="stylesheet">
    <!--<script src="assets/js/jquery-1.12.3.js" type="text/javascript"></script>-->
    </head>
    <body>
    <div id="main">
    <div id="vidbox">
    <video autoplay  poster="" id="bgvid" loop>
    <source src="assets/video/filxe.mp4" type="video/mp4">
    <img src="assets/images/vidfallback.png" id="vidfallback">
    </video>
    </div>
    <ul id="navbar">
    <li class="left"><img src="assets/images/logomini.png" id="logo"></li>
    <li class="left"><a href="" class="white">HK Construction Company</a></li>
    <li><a href="#home" id="home">Home</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">About Us</a></li>
    </ul>
    <h1 id="tagline"><span class="bigger">"</span> You Dream, We Build <span class="bigger">"</span></h1>
    </div>
    <div class="box about">
    
    </div>
    </body>
    </html>

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

"Exploring the variations in design between wordpress.com and self-hosted wordpress

I'm currently puzzling over the source of the disparities in style between my Wordpress site hosted elsewhere and my identical theme on Wordpress.com. It's perplexing to see such contrasting appearances while I migrate my blog. After some irrele ...

Maintain the proportional scale of images set to a percentage with window resizing

Currently working on developing a web application. The images in the app are sized using percentages, with three overlapping another image that functions as a toolbar. Everything looks great when viewed in fullscreen mode, but the problem arises when the s ...

The dominance of CSS over other attributes in styling

Imagine having a main body text div and a navigation div for a website. What if you want to make links in the body text green instead of blue, but have the links in the navigation div be red? If you use CSS to make links green, then all links turn green. ...

css - Tips for reducing the speed of inertia/momentum scrolling on mobile devices

I have been working on creating a scrollable card gallery using a CSS grid layout. The structure I am following is similar to this: <div class="gallery-wrapper"> <div class="gallery-container"> <div id="card-1" class="gallery-ca ...

Prevent CSS background resize caused by toggling the Chrome URL bar on Android devices

When browsing a website using Chrome for Android, the height of the view area changes when scrolling causes the URL bar to hide. This can lead to annoying resizing of a fixed background image, especially when scrolling down and back up again. https://i.ss ...

A guide on transferring model value from a view to a controller upon button click in ASP.NET MVC

Is there a way to pass a value from a model in the view to a controller when a button is clicked, while also redirecting the user to that controller? Here is the code for the view: @model Status_Pedido.ViewModels.CodigoPedidoViewModel @{ ViewBag.Titl ...

New and improved Bootstrap 5 menu bar

I am seeking to customize my navigation bar by adding a black background that spans its entire length. I do not want to rearrange the links or logo; just apply a background color. Another issue arises during SASS compilation: I am trying to change the col ...

When I use `console.log` with `req.body` in Node, the password is

Currently, I am utilizing NodeJs on the backend to console.log(req.body) data from a form that gathers usernames and passwords from users. I have noticed that this method exposes the collected username and password information. Should I be concerned abou ...

Cyrillic - best practices for PHP configurations, headers, and MySQL (can UTF8 be the answer?)

I am currently working on a project that requires users to input special characters, specifically Cyrillic ones like 'Врати се на почетак' (which means return to top). I need to make some special settings and I would appreciate ad ...

Dynamically extract key values from JSON data and display them on an HTML page with checkboxes for selection. Generate a new JSON object containing

I am facing the challenge of parsing an unknown JSON with uncertain key-value pairs. As I do not have prior knowledge of the keys to access, my goal is to traverse through every key in the JSON and display all keys and their corresponding values on the scr ...

Adjusting the size of images in real time

Currently, I am in the process of creating a Fluid grid style website and I am looking to decrease the size of all images by 75% when the screen is below 1280px, 50% at 800px, and so forth. Is there a way to achieve this using the IMG tag? My attempt so ...

Looking for assistance with embedding content into an iFrame?

Having trouble writing into an iframe, I can locate the iframe but unable to input anything into it. Every time I attempt to write into the iframe, I encounter the following error. <div id="offer_description_field" class="control-group wysihtml5_type d ...

Some web browsers do not support video html5, except for Google Chrome

Not all browsers support HTML5 video, with the exception of Google Chrome. In Firefox, there may be a message saying "No video with supported format and MIME type found." To embed a video in your page, you can use the following code: <video width="3 ...

Display a modal upon successful validation of a form

As a newcomer to JavaScript and Bootstrap, I have a specific requirement: 1. When a user clicks the submit button, 2. The form needs to be validated using the entry_check() function. 3. Upon successful validation of the form, a Bootstrap modal should be op ...

Purge the external CSS files

Scenario In my React Router setup, most pages include their own .css files along with the default antd (UI framework) stylesheet: import '../styles.css'; This ensures that all components inherit these styles automatically. Issue at Hand Now, I ...

Having trouble with the dropdown feature on AngularJs?

Encountering an issue while trying to display the dropdown list. Upon inspecting in Chrome, it seems like the data is loading correctly but when clicked, the dropdown menu does not show up. The data is fetched from the BooksController and all options are ...

With the simple click of a button, I aim to refresh and enhance the appearance of a polygon

My goal is to create a button that, when clicked, causes the gray stripe in the middle to transition to the right. I am not very familiar with HTML, CSS, and JavaScript so I could use some help figuring out how to achieve this effect. Here is a quick illus ...

Enable selecting text within a Bootstrap table

When I first encountered the issue, selecting text from my bootstrap table seemed like an impossible task. My initial attempts to address this involved focusing on CSS, and I managed to find a somewhat limited solution utilizing webkit-select-user Howe ...

"Using Flexbox to Align Child Elements of Varying

After learning about flexbox, a pressing question arose: How can I create a layout of columns similar to the one shown in this image? Check out MyCodeFiddle for more details! (http://jsfiddle.net/1s3bo913/) Click here to view the layout project: Layout Pr ...

Removing a session when the client has left

I wanted to simplify what I'm trying to achieve. Imagine two people have PHP sessions on a webpage. One person leaves the page while the other remains. After 60 seconds, the session of the person who left should be terminated automatically (like a ti ...