DaLegacy
DaLegacy

Reputation: 133

Trouble with aligning elements

I came across this issue where I cannot get mine top-box to organize the elements correctly. I've tried everything that I know off and cannot get it to work. I need to have my text 100% in middle and logo just to left but every time I try to do that the text moves to right and its offset. And the Navigation bar to be under the logo and text and that is centered like 100% of time every time I try.

I have a main div as a container, this top-box is a child.

<div class="top-box">
        <div class="logo">
          <a href="#">
            <img src="Assets/Images/WebsiteLogo.png" alt="">
          </a>
        </div>

        <div class="webname">
          <a href="#">
            <h1>Universal Web Designs</h1>
          </a>
        </div>

        <div class="navigationbar">
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Designs</a></li>
            <li><a href="#">About Me</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div>
      </div>

Some CSS not all

.top-box {
  display: flex;
  width: 90%;
  padding: 0;
  margin: 0.5rem 0 0 0;
  border-top-left-radius: 25px;
  border-top-right-radius: 25px;
  background: rgba(0, 0, 0, 0.75);
  border-top: solid white 1px;
  border-right: solid white 1px;
  border-left: solid white 1px;
}

.logo {
  margin: 0;
  padding: 0;
  border: solid 1px red;
  /* background: rgba(255, 255, 255, 1); */
  /* border-radius: 5rem; */
}

.logo img {
  width: 5rem;
  margin: 0;
  /* background: rgba(255, 255, 255, 1); */
  /* border-radius: 5rem; */
}

.webname {
}

.webname a {
  text-decoration: none;
}

.webname h1 {
  padding: 0;
  margin: 0;
  font-size: 3.5rem;
  color: rgba(26, 184, 212, 1);
  text-shadow: 4px 2px 10px gray; 
  border: solid 1px red;
}

.webname h1:hover {
  color: gray;
  text-shadow: 4px 2px 10px rgb(26, 184, 212);
}

.navigationbar {
  width: 100%;
  text-align: center;
  padding: 0;
  margin: 0.2rem 0 0 0;
  border: solid 1px red;
  /* border-top: solid rgba(255, 255, 255, 0.1) 1px; */
}

.navigationbar ul {
  list-style-type: none;
}

.navigationbar li{
  display: inline;
  text-transform: uppercase;
  padding: 0;
  margin: 0 2rem;
}

.navigationbar a {
  text-decoration: none;
  font-size: 1.2rem;
  color: white;
  text-shadow: 2px rgb(26, 184, 212);
}

.navigationbar a:hover {
  color: #dc3545;
  text-decoration: underline;
}

Thanks

Upvotes: 1

Views: 84

Answers (1)

Bert W
Bert W

Reputation: 556

Solution to you question with CSS grid:

.top-box {
  width: 90%;
  padding: 0;
  margin: 0.5rem 0 0 0;
  border-top-left-radius: 25px;
  border-top-right-radius: 25px;
  background: rgba(0, 0, 0, 0.75);
  border-top: solid white 1px;
  border-right: solid white 1px;
  border-left: solid white 1px;
  
}

.grid {
   display: grid;
   grid-template-columns: 1fr 555px 1fr;
}

.logo {
  margin: 0;
  padding: 0;
  border: solid 1px red;
  /* background: rgba(255, 255, 255, 1); */
  /* border-radius: 5rem; */
}

.logo img {
  width: 5rem;
  margin: 0;
  /* background: rgba(255, 255, 255, 1); */
  /* border-radius: 5rem; */
}

.webname {
  margin: 0 auto;
}

.webname a {
  text-decoration: none;
}

.webname h1 {
  padding: 0;
  margin: 0;
  font-size: 3.5rem;
  color: rgba(26, 184, 212, 1);
  text-shadow: 4px 2px 10px gray; 
/*   border: solid 1px red; */
}

.webname h1:hover {
  color: gray;
  text-shadow: 4px 2px 10px rgb(26, 184, 212);
}

.navigationbar {
  width: 100%;
  text-align: center;
  padding: 0;
  margin: 0.2rem 0 0 0;
  border: solid 1px red;
  /* border-top: solid rgba(255, 255, 255, 0.1) 1px; */
}

.navigationbar ul {
  list-style-type: none;
}

.navigationbar li{
  display: inline;
  text-transform: uppercase;
  padding: 0;
  margin: 0 2rem;
}

.navigationbar a {
  text-decoration: none;
  font-size: 1.2rem;
  color: white;
  text-shadow: 2px rgb(26, 184, 212);
}

.navigationbar a:hover {
  color: #dc3545;
  text-decoration: underline;
}
.logo {
  width: 40px;
  height:40px;
  margin-left: auto;
  margin-right: 10px;
  align-self: center;
}
<div class="top-box">
    <div class="grid">
        <div class="logo">
          <a href="#">
            <img src="Assets/Images/WebsiteLogo.png" alt="">
          </a>
        </div>

        <div class="webname">
          <a href="#">
            <h1>Universal Web Designs</h1>
          </a>
        </div>
  </div>
  
        <div class="navigationbar">
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Designs</a></li>
            <li><a href="#">About Me</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </div>
      </div>

Upvotes: 1

Related Questions