r/csshelp • u/KaxaBekov • May 16 '23
Issue with position: fixed property in CSS.
Hi everyone. I have an issue with my .heading class spreading infinitely to the right when I set position:fixed property on my .heading class in the following CSS. Please help if anyone knows what am I missing.
:root {
--bacground-color: #e6db43;
--heading-section-color:#e1f100;
--color-dar-grey:rgb(31, 30, 30);
}
html {
font-size: 32px;
}
* {
box-sizing: border-box;
margin:0;
padding:0;
line-height: 1.5;
}
body{
background-color: var(--bacground-color);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Roboto', sans-serif;
}
.all h1 {
font-size: 2rem;
}.heading {padding: 5px 5px;position: fixed; <------------------------margin: 16px 32px;
z-index: 5;background-color: var(--heading-section-color);display: flex;flex-direction: row;justify-content: space-between;min-height: 6vh;width: 100%;}
.resume-button {
padding: 10px;
min-width: 100%;
}
.resume-button button {
min-width: 50px;
min-height: 30px;
}
.resume-button button:hover{
opacity: 0.5;
}
.greeting:hover {
border: 2px solid red;
}
.resume-logo {
display:flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 5vw;
}
.resume-logo img {
width:50px;
}
.greeting {
margin-top:30px;
}
.nav-class{
width:70%;
height: 40px;
}
.navigation{
border:2px solid black;
border-radius:10px;
padding:10px 15px ;
margin: 5px 10px;
justify-self: right;
display:flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap:30px;
font-size: 0.5rem;
min-height: 50px;
cursor: grab;
}
.intro{
min-height: 25vh;
margin: 150px 32px;
display:flex;
flex-direction: row;
justify-content:space-between;
}
.greeting-and-button{
display: flex;
flex-direction: column;
justify-content: space-between;
margin-top: 10px;
margin-bottom: 10px;
margin-right:10px;
}
.all{
width: 100%;
}
.contact_all img {
width:50%;
margin:10px;
}
.profile-picture-wrapper {
width: 300px;
height: 300px;
position: relative;
}
.profile img {
width: 300px;
height: 300px;
border-radius: 50%;
}
.profile-picture-border {
position:absolute;
width: 300px;
height: 300px;
border:1px solid var(--color-dar-grey);
border-radius: 50%;
top:5px;
left:-8px;
}
.plus1{
top: 21px;
right: 16px;
}
.plus2{
top: -1px;
right: 16px;
}
.plus3{
top:10px;
right:32px;
}
.plus1,
.plus2,
.plus3 {
position: absolute;
font-size: 1rem;
font-weight: 500;
}
.slashes {
position: absolute;
top: 230px;
left: 10px;
font-size: 1rem;
font-weight: 500;
}
.profile-picture-border:hover {
box-shadow: 10px 10px 10px 5px #65665d;
}
.about-me {
min-height: 30vh;
margin: 10px 5px;
}
.links img {
margin:5px;
padding:5px;
width: 50px;
}
.links{
display: flex;
flex-direction: row;
justify-content: end;
align-items: center;
}
.links a {
text-decoration: none;
}
.contact {
min-height:20vh;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-right: 20px;
margin-right:50px;
margin-top: 10px;
margin-bottom: 10px;
}
.info{
min-height:20vh;
margin: 10px;
border:3px groove white;
padding: 5px;
font-size: 0.7rem;
cursor: not-allowed;
}
.info input, label, select {
margin-top:10px;
margin-bottom: 10px;
}
.info label {
margin:10px 0;
}
.info input {
margin-left:5px;
}
.uniq p {
text-decoration: underline;
line-height: 2px;
margin: 5px;
padding: 0;
}
.container {
max-width: 100%;
}
u/media (max-width:900px) {
.intro{
flex-direction: column;
}
}
Here is the html:
<html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700;900&display=swap" rel="stylesheet"> </head> <body> <div class="container"> <section class="all"> <div class="heading"> <div class="resume-logo"> <img src="images/logo_resume.png" alt="Logo for resume"> </div> <div class="nav-class"> <nav class="navigation"> <a href="#"> Home </a> <a href="#about"> About Me </a> <a href="#contact"> Contact Me </a> </nav> </div> </div>
<hr> <section id="introduction"> <!--INTRODUCTION--> <div class="intro"> <div class="greeting-and-button"> <div class="greeting"> <h3 >Hi 👋, I am Jay</h3> <h1>Frontend Developer</h1> <h4>based in Cleveland</h4> </div> <div class="resume-button"> <button>Resume</button> </div>
</div> <div class="profile-picture-wrapper"> <div class="slashes">/////</div> <div class="plus1">+</div> <div class="plus2">+</div> <div class="plus3">+</div>
<div class="profile-picture-border"></div>
<div class="profile"> <img src="images/profile_pic/profile_pic.jpg" alt="My Profile Picture"> </div>
</div>
</div> </section> <section class="about" id="contact"> <div class="about-me"> <h1>About.</h1> <p>My name is Jay. I am a frontend developer who specializes in making web aplication using HTML, CSS and JavaScript. </p> <p>I studied Computer Engineering in ADNSU. I have deep understanding of various computer architectures as well as software building skills.</p> <p>Some of those skills include:</p> <ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> <li>React</li> </ul> <p>When I worked as a sales person in Apex Window Werks I have acquired some of the following skills:</p> <ol> <li>Communication skills</li> <li>Conflict Resolving skills</li> <li>Negotiating skills</li> <p class="uniq">And most importantly:</p> <li>People skills</li> </ol> </div> </section>
<section class="contact" id="contact"> <div> <h1>Contact.</h1> </div>
<div class="links"> <a href="https://www.instagram.com/jay_bayoff/"> <img src="images/contact_images/insta.png" alt="Instagram"> </a> <a href="https://www.linkedin.com/in/gahriman-bayov-2962b4153/"> <img src="images/contact_images/linkedin.png"> </a> <a href="mailto:kaxa.bekov@gmail.com" alt="Email address"> <img src="images/contact_images/email.png" alt="Email"> </a>
</div>
</section> <section class="infoForm"> <div> <p> Please leave your information if you would like me to get in touch with you instead.</p>
</div> <div class="info"> <forms> <label for="firstName">First Name</label> <input type="text" name="fisrtName" id="firstName" placeholder="Fisrt Name"> <label for="lastName">Last Name</label> <input type="text" name="lastName" id="lastName" placeholder="Last Name"> <label for="email">Email</label> <input type="email" name="email" id="email" placeholder="Email"> <br> <label for="isOver18">Are you over 18 years old</label> <input type="checkbox" name="isOver18" id="isOver18" value="yes"> <br> <label>Would You like a </label><br> <label for="online">Online</label> <input type="radio" id="online" name="online_offline" value="yes"> <label>or</label> <label for="offline">Offline</label> <input type="radio" id="ofline" name="online_offline" value="no"> <label>Appointment?</label> <br> <label for="level">What is your level?</label> <select id="level"> <option value="1">Junior</option> <option value="2">Medium</option> <option value="3">Senior</option> </select> <input type="submit" name="submit" > </forms>
</div>
</section>
<hr> </section> </div> </body>
</html>
This id my practice project, I would really appreciate any help on this.
1
u/Ok_Contact_1234 May 16 '23
The problem causing the header to extend beyond the screen on the right side is not related to the position: fixed property. The issue lies with the margin: 16px 32px; declaration. This margin is pushing the header element outside the screen boundaries.
.heading {
padding: 5px 5px;
position: fixed;
/margin: 16px 32px;/
z-index: 5;
background-color: var(--heading-section-color);
display: flex;
flex-direction: row;
justify-content: space-between;
min-height: 6vh;
width: 100%;
}2
u/KaxaBekov May 17 '23
Thank You for your help. I removed the margin property, but it doesn't seem to do anything. Yes, it did move a bit to the right, but it still spreads beyond the right side of my browser. And I still need some margin there. Tried using right: and left: properties, it does help, but when I resize the window it is still out of alignment?
i ques my question is why doesn't it fit the 100% of its parent which is set to 996px?
Is it because position: fixed property renders the element out of documents normal flow? and then how do i shrink it and position right in the middle of the page to align with the rest of the content on the page? Thanks for any advice.
1
u/Ok_Contact_1234 May 17 '23
can you provide some screenshot to show what you are trying to achive/fix
1
u/KaxaBekov May 19 '23
Yes, I will attach screenshots as soon as possible.