Summary: Existing CSS code for setting an HTML element's width to 100% of viewport width fails when tailwindcss is added. For an element who's display is set to display: flex;
the children being directly force fit within the viewport. This is not desired. This issue is also faced when Tailwindcss is not used.
Note:
- Not using TailWindCSS is not an option. My main code uses tailwindcss heavily. This feature is being added later.
- I am creating this for the mobile version of the website.
- I want to see each individual element within the flex'ed parent element to be of the same 100 viewport width size.
- I'm saying 100 because it is easier to read and remember. You will find "96vw" in the code. But the issue persists even with "100vw".
Now, going in detail:
Okay. So I have a simple code where the width of section element set to "100vw" - meaning the full screen.
Once I made the appropriate settings, I tried adding TailwindCSS to draw some animations and decorate the webpage.
I followed the Tailwindcss installation docs via CLI: https://tailwindcss.com/docs/installation/tailwind-cli
As soon as I connect my html page with the "output.css" file as shown in step 4, all of the sections are forcefully fit in the same width! It is no longer 100vw for each section. Instead, all sections are fit inside the same 100vw.
You can see how there are no TailwindCSS or even any user defined classes that are added to the HTML file. Why is this happening??
I have added the ability to run my code. If you want to see the rest of the videos as well, then change the 'transform' CSS property of the #slider element to "translateX(-100.5vw)" and "translateX(-200.5vw)".
Now, if you uncomment the <!--<link rel="stylesheet" href="output.css"> -->
in the HTML file, then you would see that all the videos are aligned this way. (See Image)
This is not desired. When that Line of Code is commented.. or in other words, when the TailWindCSS library is disconnected from the main HTML file, it behaves as intended. See image:
Note that I have changed the videos that are being displayed for demonstration. But the issue persists even with the original videos that I want to display.
body{
width: 100vw;
background-color: white;
}
#container{
margin-top: 30vh;
overflow: hidden;
/* transform: translateX(-10vw); */
}
#slider{
display: flex;
transition: transform 1s linear;
transform: translateX(-0.5vw);
}
#project1 video, #project2 video, #project3 video{
width: 96vw;
}
/* #project1 {
margin-right: 4vw;
/* } */
#project1, #project2, #project3 {
margin-inline: 2vw;
}
p{
text-align: center;
color: aqua;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing overflows</title>
<link rel="stylesheet" href="index.css">
<!--<link rel="stylesheet" href="output.css"> -->
</head>
<body >
<section id="container">
<div id="slider">
<section id="project1">
<video controls
src="https://1mm9hhqsjgoh4ol8.public.blob.vercel-storage.com/test_video1"></video>
<div>
<p>This is text</p>
</div>
</section>
<section id="project2">
<video controls
src="https://1mm9hhqsjgoh4ol8.public.blob.vercel-storage.com/test_video2"></video>
<div>
<p>This is text</p>
</div>
</section>
<section id="project3">
<video controls
src="https://1mm9hhqsjgoh4ol8.public.blob.vercel-storage.com/test_video3"></video>
<div>
<p>This is text</p>
</div>
</section>
</div>
</section>
</body>
</html>