Home > Software design >  How do I start an independent new section after 'position: absolute;'
How do I start an independent new section after 'position: absolute;'

Time:05-20

I think it's important to note that I'm a complete beginner in webdev.

However, the point is that I can't yet figure out how to start a new section after using position: absolute; on the previous one.

Each time I start writing something new, it ends up either on the top of the page, or on the center of the page. I have tried using flexbox and grid, however that didn't help me either. So I wonder how do I do it without affecting the layout of the webpage?

It is not even a question that I have to learn more about CSS positioning.

I know it looks a bit messy.

Here's the code:

:root {
    /* colors */
    --clr-white: rgb(235, 255, 209);
    --clr-black: rgb(10, 10, 9);
    --clr-gray: rgb(30, 30, 30);

    --clr-green: rgb(173, 255, 47);
    --clr-orange: rgb(255, 123, 25);

    --ff-main: 'Montserrat', sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    list-style: none;
}

body {
    background-color: var(--clr-black);
    color: var(--clr-white);
    font-family: var(--ff-main);
    font-size: 1.1rem;
    /* line-height: 1.5; */
}

header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1rem 3rem;
    z-index: 1000;
}

nav {
    display: flex;
    position: sticky;
    align-items: center;
    justify-content: space-around;
    top: 100%;
}

nav li {
    line-height: 1.5;
}

main {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

a {
    text-decoration: none;
    color: inherit;
}

.showcase {
    position: absolute;
    right: 0;
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: -2;
}

.showcase video
{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.9;
  z-index: -1000;
}

.background {
    background-size: cover;
    /* overflow: hidden; */
    /* background-repeat: no-repeat; */
    width: 100%;
    filter: saturate(100%) contrast(100%) blur(0.3rem) hue-rotate(111deg);
    z-index: -11;
}

.btn {
    border: none;
    border-radius: 6px;
    background-color: var(--clr-green);
    padding: 0.3rem 0.6rem;
    color: var(--clr-black);
    cursor: pointer;
}

.button {
    border: 1px solid var(--clr-orange);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    color: var(--clr-green);
    background-color: inherit;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 300;
    transition: all 0.6s ease 0s;
}

.button:hover {
    border: 1px solid var(--clr-green);
    background-color: var(--clr-green);
    color: var(--clr-black);
}

.heading {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 0.3rem;
}

.title {
    position: static;
    bottom: 1%;
    font-weight: 100;
    letter-spacing: 0.3rem;
    right: 37.5%;
    width: 100%;
}

.text {
    position: absolute;
    bottom: 9%;
    /* left: 50%; */
    right: 43%;
    font-size: 1.1rem;
    letter-spacing: 0.3rem;
    font-weight: 100;
    font-size: 700;
}

.uppercase {
    text-transform: uppercase;
}

.touch {
    position: absolute;
    top: 27%;
    left: 11%;
    filter: blur(0.1rem);
}

.top-left {
    position: absolute;
    top: 11%;
    left: 9%;
    font-size: 11rem;
    font-weight: 900;
}

.mid-left {
    position: absolute;
    top: 33%;
    left: 33%;
    font-size: 4.3rem;
    font-weight: 400;
}

.mid-center {
    position: absolute;
    top: 42%;
    left: 11%;
    font-weight: 600;
}

.center {
    position: absolute;
    top: 44%;
    font-size: 9rem;
    font-weight: 900;
    left: 38%;
}

.mid-right {
    position: absolute;
    top: 56%;
    right: 18%;
    font-weight: 200;
    font-size: rem;
}

.down-right {
    position: absolute;
    top: 66%;
    right: 11%;
    font-size: 11rem;
    font-weight: 900;
}

.main-content {
    display: flex;
    justify-content: center;
    align-items: center;
}

.down {
    position: absolute;
    bottom: 3%;
    left: 46.6%;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/styles.css">
    <title>stombic</title>
</head>
<body>
    <!-- BACKGROUND -->
    <section >

        <video muted autoplay >
            <source src="videos/1.mp4" type="video/mp4" />
        </video> 
        <!-- MAIN -->
        <main>
            <section >
                <div >
                    <h1 ><span >art</span> <span >is</span> 
                        <span >where</span> 
                        <span >work</span> 
                        <span >meets</span> <span >love</span></h1>
                    <p >created to create.</p>
                    <button type="button" ><a href="#">Learn More</a></button>
                </div>
            </section>
            <!-- <section>
                <img src="images/splash.png" />
                <img src="images/hands.png"  />
            </section> -->
        </main>
    </section>

</body>
</html>

This is one of the longer codes I've seen on this platform. If anyone wants the files it is not a problem for me to send it.

CodePudding user response:

make the two absolute position sections inside a container that has a relative position.

CodePudding user response:

You can use position: absolute on a container.

For example, use position: absolute on the main and then position the sections 'normally'. But if you need sibling sections to go next to each other and not overlap, you'd not use position: absolute on one of them.

I'd highly recommend Kevin Powell's Youtube Channel, where he makes great videos about CSS and demystifies positioning.

  • Related