Home > Blockchain >  Elements overflowing from line
Elements overflowing from line

Time:11-26

I believe my understanding of positioning is causing me multiple issues:

  1. 'Donate' in the navigation header keeps overflowing and not staying inline. I have experimented with display:inline-block, but it still is not working. I am trying to ensure that the navbar elements are responsive to different-sized pages and stay in the same line.

  2. 'Our work' section will not center in the middle of the page, even when I tried margin:auto

  3. Unable to align the elements in the problem section correctly. I would like row2 to be 10% below row1, so it's like a 2x2 table configurement.

I've been struggling with this for a while, so if anyone has any ideas on how to solve any of these and suggestions moving forward - it would be well appreciated!

*{
  margin:0;
  padding:0;
}

header{
  font-family:'Ubuntu';
  
}

body{
  font-family: 'Montserrat';
  text-align: left;
} 

/* Header */

header{
  position: fixed;
  width:100%;
  height:122px;
  background:#FFFFFF;
  z-index:1;
    
}

.wrapper{
width:90%;
margin:0 auto;
}

.logo{
width:30%;
float: left;
text-align:left;
line-height: 122px;
  }


nav{
float: center;
line-height: 122px;

}

nav a{
font-family:'Ubuntu';
font-weight: 500;
font-size:calc(50px 1vw);
line-height: calc(23px 1vw);
text-decoration: none;
letter-spacing: 4px;
color:#616161;
padding: 20px 20px;

}

.links:hover {
  background:#F3EA65;
}

.CTA{
padding: 15px 100px;
border: none;
background: #F28A31 ;
border-radius: 15px ;
font-family: Ubuntu;
font-style: normal;
font-weight: bold;
line-height: calc(13px 1wv);
font-size: calc(20px 1vw);
color: #FFFFFF;
text-align: center;
letter-spacing: 0.5px;
display: inline-flex;
}

.CTA:hover {
  background-color: #F3EA65;
  color: #FFFFFF;
  cursor: pointer;
} 

/*Our work*/

#ourwork{
background:#fff;
position:absolute;
width: 932px;
height: 92px;
top: 700px;
left: 50%;
padding:10px;
}

/*Problem section */

#problembackground{
position: absolute;
width: 100%;
height: 561px;
top:852px;
background: linear-gradient(90.14deg, #DE5135 -20.57%, #6975A7 88.83%);

}

#problemcontent{
position: relative;
top: 25%;
left:5%;
}

.row1{
position: relative;
display: inline-block;
padding-right:10%
}

.row2{
position: relative;
display: inline-block;
top:10%;
}
<body>
  <header>
    <div class="wrapper">
      <div class="logo">
        <a href="....">
        <img src="Home.png" alt="Logo" width="25%";>
        </a>
      </div>
        <nav>
          <a class="links" href="#">about</a>
          <a class="links" href="#">our team</a>
          <a class="links" href="#">who we help</a>
          <a class="links" href="#">get involved</a>
          <a href="#">
            <button class="CTA">Contact</button>
          </a>
          <a href="#">
            <button class="CTA">Donate</button>
          </a>
        </nav>
    </div>
  </header>
  
 <main>  
 <section>
      <div id="ourwork">
        <h4>OUR WORK</h4><br>
        <p id="largertext">
          Youth Housing Project Association Inc. (YHP) provides supported, unsupervised,<br> medium-term accommodation in Brisbane to young people aged from 16-21 years old<br> who are homeless or at risk of homelessness.  
        </p>
      </div>
    </section>
  
    <section>
      <div id="problembackground">
        <div id="problemcontent">
          <h2 id="the problem">the problem</h2><br>
          <div id="p1" class="row1">
            <h3>1 in 5</h3>
            <p>young Australians report high levels of<br> psychological distress</p>
          </div>
          <div id="p2" class="row1">
            <h3>28 000</h3>
            <p>12 to 24-year olds are homeless on any given<br> night in Australia</p>
          </div>
          <div id="p3" class="row2">
            <h3>1 in 6</h3>
            <p>16 to 24-year olds live below the poverty line</p>
          </div>
          <div id="p4" class="row2">
            <h3>35%</h3>
            <p>of 16 to 24-year olds have experienced<br> domestic violence at home</p>
          </div>
        </div>
      </div>

CodePudding user response:

Here: I removed the floats and used flexbox and grid Quick note: This website is not responsive, so pls open it in the full window not hte mini window. If you want a responsive site, dang man, that's a big request Code:

<body>
    <style>
        *{
  margin:0;
  padding:0;
}

header{
  font-family:'Ubuntu';
  
}

body{
  font-family: 'Montserrat';
  text-align: left;
} 

/* Header */

header{
  position: fixed;
  width:100%;
  height:122px;
  background:#ffffff;
  z-index:1;
    
}

.wrapper{
width:90%;
margin:0 auto;
display: flex;
justify-content: center;
align-items: center;
}


.logo{


text-align:left;
line-height: 100px;
height: fit-content;
display: inline-block;
width: fit-content;
padding: 30px;
margin: 0px;
  }

  .logo image {

  width: 200px;
  height: 200px;

  }


.wrapper a{
font-family:'Ubuntu';
font-weight: 500;
font-size:calc(50px 1vw);
line-height: calc(23px 1vw);
text-decoration: none;
letter-spacing: 4px;
color:#616161;
padding: 20px 20px;

}

.links:hover {
  background:#F3EA65;
}

.CTA{
padding: 15px 100px;
border: none;
background: #F28A31 ;
border-radius: 15px ;
font-family: Ubuntu;
font-style: normal;
font-weight: bold;
line-height: calc(13px 1wv);
font-size: calc(20px 1vw);
color: #FFFFFF;
text-align: center;
letter-spacing: 0.5px;
display: inline-flex;
}

.CTA:hover {
  background-color: #F3EA65;
  color: #FFFFFF;
  cursor: pointer;
} 

/*Our work*/

#ourwork{
background:#fff;
position:absolute;
width: 932px;
height: 92px;
top: 700px;
left: 300px;
padding:10px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#work{
display: flex;
justify-content: center;
align-items: center ;
}

/*Problem section */

#problembackground{
position: absolute;
width: 100%;
height: 561px;
top:852px;
background: linear-gradient(90.14deg, #DE5135 -20.57%, #6975A7 88.83%);

}

#problemcontent{
position: relative;
top: 25%;
left:5%;
}
#the-problem{

margin: auto;
width: 300px;
}

.row1{
position: relative;
display: inline-block;
padding-right:10%;
margin: auto;

}

.row2{
position: relative;
display: inline-block;
top:10%;
margin: auto;
}
.problem{
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    
}

li{
    list-style: none;
}

    </style>
    <header>
        <ul class="wrapper">
        <div class="logo">
            <a href="....">
            <img src="/logo.png" alt="Logo" width="25%";>
            </a>
          </div>
          
          <li>  <a class="links" href="#">about</a> </li>
          <li>  <a class="links" href="#">our team</a> </li>
          <li>  <a class="links" href="#">who we help</a> </li>
          <li>  <a class="links" href="#">get involved</a> </li>
          <button class="CTA">Contact</button>
        </a>
        <a href="#">
            <button class="CTA">Donate</button>
          </a>
           
      
        </ul>
    </header>
    
   <main>  
   <section id="work">
        <div id="ourwork">
          <h4>OUR WORK</h4><br>
          <p id="largertext">
            Youth Housing Project Association Inc. (YHP) provides supported, unsupervised,<br> medium-term accommodation in Brisbane to young people aged from 16-21 years old<br> who are homeless or at risk of homelessness.  
          </p>
        </div>
      </section>
    
      <section>
        <div id="problembackground">
          <div id="problemcontent">
            <h2 id="the-problem">the problem</h2><br>
            <div class="problem">
            <div id="p1" class="row1">
              <h3>1 in 5</h3>
              <p>young Australians report high levels of<br> psychological distress</p>
            </div>
            <div id="p2" class="row1">
              <h3>28 000</h3>
              <p>12 to 24-year olds are homeless on any given<br> night in Australia</p>
            </div>
            <div id="p3" class="row2">
              <h3>1 in 6</h3>
              <p>16 to 24-year olds live below the poverty line</p>
            </div>
            <div id="p4" class="row2">
              <h3>35%</h3>
              <p>of 16 to 24-year olds have experienced<br> domestic violence at home</p>
            </div>
        </div>
          </div>
        </div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

  1. Regarding this one you simply don't have enough space at certain window widths to display them all, so you need to make their sizes responsive. @media queries at certain widths is one option.

  2. "Our work" is absolutely positioned, which messes with things like margin: 0 auto to center things. In general you use position: absolute WAY too often. Honestly you could avoid it all together looking at your page so far. position: absolute is a pain to work with when you come back to your project at a later stage too.

  3. Here your problem is that the third element is still on the same line because you set display: inline-block. You could wrap both rows each in another div (which are display: block by default). Also work with margin-bottom here in my opinion. You are making it way harder with the way you use several position properties.

CodePudding user response:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

header {
  font-family: 'Ubuntu';
}

body {
  font-family: 'Montserrat';
  text-align: left;
  padding-top: 122px;
}


/* Header */

header {
  position: fixed;
  width: 100%;
  height: 122px;
  background: #FFFFFF;
  z-index: 1;
  text-align: center;
  top: 0;
}

.wrapper {
  max-width: 90%;
  margin: 0 auto;
}

.logo {
  width: 200px;
  float: left;
  text-align: left;
  line-height: 122px;
}

nav {
  float: right;
  line-height: 122px;
  width: calc(100% - 200px);
  text-align: right;
}

nav a {
  font-family: 'Ubuntu';
  font-weight: 500;
  font-size: calc(50px 1vw);
  line-height: calc(23px 1vw);
  text-decoration: none;
  letter-spacing: 4px;
  color: #616161;
  padding: 20px 20px;
}

.links:hover {
  background: #F3EA65;
}

.CTA {
  padding: 15px 50px;
  border: none;
  background: #F28A31;
  border-radius: 15px;
  font-family: Ubuntu;
  font-style: normal;
  font-weight: bold;
  line-height: calc(13px 1wv);
  font-size: calc(20px 1vw);
  color: #FFFFFF;
  text-align: center;
  letter-spacing: 0.5px;
  display: inline-flex;
}

.CTA:hover {
  background-color: #F3EA65;
  color: #FFFFFF;
  cursor: pointer;
}

main,
section {
  float: left;
  width: 100%;
}


/*Our work*/

.ourworksec {
  background: #fff;
  padding: 100px 25px;
}

#ourwork {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  text-align: center;
}


/*Problem section */

h2#theproblem {
  padding: 20px;
}

#problembackground {
  width: 100%;
  float: left;
  padding: 100px 20px;
  background: linear-gradient(90.14deg, #DE5135 -20.57%, #6975A7 88.83%);
}

#problemcontent {
  position: relative;
}

.row1 {
  position: relative;
  display: inline-block;
  padding: 20px;
  float: left;
  width: 50%;
}

.row2 {
  position: relative;
  float: left;
  margin-top: 50px;
  padding: 20px;
  width: 50%;
}

@media only screen and (max-width: 1200px) {
  .logo {
    width: 80px;
  }
  nav {
    width: calc(100% - 80px);
  }
  nav a {
    padding: 15px 10px;
  }
  .CTA {
    padding: 15px 30px;
  }
}
<header>
  <div class="wrapper">
    <div class="logo">
      <a href="....">
        <img src="Home.png" alt="Logo" width="25%" ;>
      </a>
    </div>
    <nav>
      <a class="links" href="#">about</a>
      <a class="links" href="#">our team</a>
      <a class="links" href="#">who we help</a>
      <a class="links" href="#">get involved</a>
      <a href="#">
        <button class="CTA">Contact</button>
      </a>
      <a href="#">
        <button class="CTA">Donate</button>
      </a>
    </nav>
  </div>
</header>

<main>
  <section class="ourworksec">
    <div id="ourwork">
      <h4>OUR WORK</h4><br>
      <p id="largertext">
        Youth Housing Project Association Inc. (YHP) provides supported, unsupervised,<br> medium-term accommodation in Brisbane to young people aged from 16-21 years old<br> who are homeless or at risk of homelessness.
      </p>
    </div>
  </section>

  <section>
    <div id="problembackground">
      <div id="problemcontent">
        <h2 id="theproblem">the problem</h2><br>
        <div id="p1" class="row1">
          <h3>1 in 5</h3>
          <p>young Australians report high levels of<br> psychological distress</p>
        </div>
        <div id="p2" class="row1">
          <h3>28 000</h3>
          <p>12 to 24-year olds are homeless on any given<br> night in Australia</p>
        </div>
        <div id="p3" class="row2">
          <h3>1 in 6</h3>
          <p>16 to 24-year olds live below the poverty line</p>
        </div>
        <div id="p4" class="row2">
          <h3>35%</h3>
          <p>of 16 to 24-year olds have experienced<br> domestic violence at home</p>
        </div>
      </div>
    </div>
  </section>
</main>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related