/* body{
overflow-x: hidden;
} */
.divOne{
/* overflow-y: hidden; */
position: relative;
background-color: aqua;
height: 100px;
width: 100%;
}
.divTwo{
background-color: red;
height: 300px;
width: 300px;
position: absolute;
top: -30px;
right: -80px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./index.css" />
<title>learning about canvas</title>
</head>
<body>
<div class="container-div">
<div class="divOne">div1</div>
<div class="divTwo">div2</div>
</div>
</body>
</html>
I want to make it so that the horizontal scroll bar wouldn't appear below. I want to make the overflowing 2 div overflow: hidden . but overflow : hidden only works when its applied to body and that causes a lot of problems.
You need to add absolute positioning rules for the container-div class, relative positioning for the body tag, with the overflow-x: hidden rule.
Now your block .divTwo is hidden in the viewing area, I have a width of 300x300.
body {
position: relative;
overflow-x: hidden;
}
.container-div {
position: absolute;
left: 0;
right: 0;
}
.divOne{
/* overflow-y: hidden; */
background-color: aqua;
height: 100px;
width: 100%;
}
.divTwo{
background-color: red;
height: 300px;
width: 300px;
position: absolute;
top: -30px;
right: -80px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./index.css" />
<title>learning about canvas</title>
</head>
<body>
<div class="container-div">
<div class="divOne">div1</div>
<div class="divTwo">div2</div>
</div>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With