2

I am trying to left align some text and center align another set of text.

This is a snippet of my HTML:

    <div class="header-inner">

        <div class="logo">
            <a href="">Puremedia.</a>
        </div>

        <nav id="nav-wrap">
            <ul id="nav" class="nav">
                <li class="current"><a href="">Home.</a></li>
                <li><a href="">Stores.</a></li>
                <li><a href="">Solutions.</a></li>
                <li><a href="">About Us.</a></li>
                <li><a href="">Volunteer With Us.</a></li>
            </ul>

        </nav> <!-- /nav-wrap -->

    </div> <!-- /header-inner -->

This is a snippet of my CSS:

/* g. Header Styles
/* =================================================================== */
header {
    height: 72px;
    width: 100%;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 990;
    background: #0e1015;
    text-align: center;
}
header .logo {
    display: inline-block;
    vertical-align: middle;
}
header .logo a {
    margin: 0 20px 0 0;
    width: 126px;
    height: 12px;
    font-family: "raleway-SemiBold", sans-serif;
    text-decoration: none;
    color: white;
    font-size: 17px;
}



/* navigation
--------------------------------------------------------------------- */
/* nav-wrap */
#nav-wrap {
    font: 11px "raleway-heavy", sans-serif;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: inline-block;
}

ul#nav li {
    position: relative;
    list-style: none;
    height: 72px;
    display: inline-block;
}

ul#nav li a {
    display: inline-block;
    padding: 17px 12px;
    line-height: 38px;
    text-decoration: none;
    color: #c0cdd1;
}
ul#nav li a:hover {
    color: white;
}
ul#nav li a:active {
    background-color: transparent !important;
}
ul#nav li.current a {
    background: #209907;
    color: white;
}

My full code can be found here: https://embed.plnkr.co/plunk/guJBhxkzAK4fTTasEEQX

Currently, the Change ASEAN and the NAV bar items are all center aligned. However, what I am trying to do is to have the Change ASEAN all the way to the left and the NAV bar items in the center. How do I do this?

For Now my header looks like this: enter image description here

I want it to look like this: enter image description here

I achieved this by doing a manual positioning using padding. However, I am not sure if the alignment would still look like this when people with smaller/larger screens open the website. Therefore, I was thinking of using text-align or float. However, it seems that I can only text-align/float the logo and NAV bar as a whole. Meaning center everything or left justify everything. Is there a way to left justify the logo and center the NAV bar?

Community
  • 1
  • 1
Ruven Guna
  • 414
  • 7
  • 25
  • I think you should have a look at flexbox for layouts, unless you want to support some browsers before 2012. https://caniuse.com/#feat=flexbox – Tom Sep 30 '19 at 08:29

2 Answers2

2

Updated your header .logo css with below will give you desire result.

header .logo {
    float: left;
    line-height: 72px;
    margin: 15px;
}

/* Body
---------------------------------------------------------------------- */

body {
  background: #0e1015;
  font: 15px/30px "merriweather-regular", serif;
  font-weight: normal;
  color: #0e1015;
}


/* Typography
--------------------------------------------------------------------- */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "raleway-bold", sans-serif;
  color: #252525;
  font-style: normal;
  text-rendering: optimizeLegibility;
  margin: 18px 0 15px;
}

h1 a,
h2 a,
h3 a,
h4 a,
h5 a,
h6 a {
  font-weight: inherit;
}

h1 {
  font-size: 30px;
  line-height: 36px;
  margin-top: 0;
  letter-spacing: -1px;
}

h2 {
  font-size: 24px;
  line-height: 30px;
}

h3 {
  font-size: 20px;
  line-height: 30px;
}

h4 {
  font-size: 17px;
  line-height: 30px;
}

h5 {
  font-size: 14px;
  line-height: 30px;
  margin-top: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

h6 {
  font-size: 13px;
  line-height: 30px;
  margin-top: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

p {
  margin: 15px 0 15px 0;
}

p img {
  margin: 0;
}

p.lead {
  font: 17px/33px "merriweather-light", serif;
  color: #707273;
}

strong,
b {
  font: 15px/30px "merriweather-bold", serif;
  font-weight: normal;
}

small {
  font-size: 11px;
  line-height: inherit;
}


/* Lists
--------------------------------------------------------------------- */

ul {
  margin-top: 15px;
  margin-bottom: 15px;
}

ul {
  list-style: disc;
  margin-left: 17px;
}


/* 
/* g. Header Styles
/* =================================================================== */

header {
  height: 72px;
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 990;
  background: #0e1015;
  text-align: center;
}

header .logo {
  float: left;
  line-height: 72px;
  margin: 15px;
}

header .logo a {
  margin: 0 20px 0 0;
  width: 126px;
  height: 12px;
  font-family: "raleway-SemiBold", sans-serif;
  text-decoration: none;
  color: white;
  font-size: 17px;
}


/* navigation
--------------------------------------------------------------------- */


/* nav-wrap */

#nav-wrap {
  font: 11px "raleway-heavy", sans-serif;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  display: inline-block;
}

ul#nav li {
  position: relative;
  list-style: none;
  height: 72px;
  display: inline-block;
}

ul#nav li a {
  display: inline-block;
  padding: 17px 12px;
  line-height: 38px;
  text-decoration: none;
  color: #c0cdd1;
}

ul#nav li a:hover {
  color: white;
}

ul#nav li a:active {
  background-color: transparent !important;
}

ul#nav li.current a {
  background: #209907;
  color: white;
}


/* 
/* i. Footer Styles
/* =================================================================== */

footer {
  padding-top: 36px;
  padding-bottom: 42px;
  font-size: 13px;
  line-height: 24px;
  position: relative;
  color: #3C4142;
}

footer a,
footer a:visited {
  color: #a43b0a;
}

footer a:hover,
footer a:focus {
  color: white;
}

footer h3 {
  font: 13px/24px "raleway-bold", sans-serif;
  margin-bottom: 0;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1px;
}

footer p {
  margin: 12px 0;
}

footer .footer-about {
  padding-right: 60px;
}

footer .right-cols .columns {
  width: 50%;
  word-wrap: break-word;
}

footer ul {
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

footer ul li {
  margin: 0;
  padding-left: 0;
  line-height: 24px;
}

footer ul li a,
footer ul li a:visited {
  color: #3C4142;
}

footer .copyright {
  margin: 0;
  padding: 24px 18px 6px 18px;
  clear: both;
}


/* back to top */

footer #go-top {
  position: fixed;
  bottom: 0;
  right: 30px;
  z-index: 900;
  display: none;
}

footer #go-top a {
  display: block;
  padding: 12px 30px;
  background: #d44d0d;
  color: white;
  text-align: center;
  font: 12px/24px "raleway-heavy", sans-serif;
  text-transform: uppercase;
  letter-spacing: 2px;
  -moz-transition: all 0.2s ease-in-out;
  -o-transition: all 0.2s ease-in-out;
  -webkit-transition: all 0.2s ease-in-out;
  -ms-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
}

footer #go-top a span {
  margin-right: 10px;
}

footer #go-top a:hover {
  background: #faec09;
  color: #252525;
}
<body class="homepage">


  <!-- Header
   =================================================== -->
  <header id="main-header">

    <div class="header-inner">

      <div class="logo">
        <a href="">Change ASEAN.</a>
      </div>

      <nav id="nav-wrap">
        <ul id="nav" class="nav">
          <li class="current"><a href="">Home.</a></li>
          <li><a href="">Stores.</a></li>
          <li><a href="">Solutions.</a></li>
          <li><a href="">About Us.</a></li>
          <li><a href="">Volunteer With Us.</a></li>
        </ul>

      </nav>
      <!-- /nav-wrap -->

    </div>
    <!-- /header-inner -->

  </header>


  <!-- Footer
   ================================================== -->
  <footer></footer>
  <!-- /footer -->

</body>
Sumit Patel
  • 4,530
  • 1
  • 10
  • 28
  • We're currently in 2019, why still use floats for layouts? – Tom Sep 30 '19 at 08:21
  • @Tom you are right we can use flex and grid and all but depend on his requirement and what he code so far float was good option for him. – Sumit Patel Sep 30 '19 at 08:38
0

Use a float: left on the logo and then add an @media query for smaller screens that sets float: none or display: none to prevent clipping?

MiK
  • 918
  • 4
  • 16