Home > OS >  How to fix HTML/CSS text from not going under other text
How to fix HTML/CSS text from not going under other text

Time:10-24

I'm attempting to make the social logos on the same line as the "APKHub" text. I have tried aligning it properly and messed with positionings but nothing has been working. I am unsure why It is like this and I run into this issue a lot and haven't really found a fix. All the code is below and an image aswell.

<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">
  <script src="https://kit.fontawesome.com/dd13dde450.js" crossorigin="anonymous"></script>
  <!-- Fonts -->
  <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&display=swap" rel="stylesheet">
  <!--  -->
  <title>APKHub - Free APK Downloads</title>
</head>
<body>
  <div >
      <h1>APKHub</h1>
      <div >
          <i ></i>
          <i ></i>
          <i ></i>
      </div>
  </div>
</body>
<style>
  body {
      margin: 0;
      padding: 0;
      background-color: #141523;
  }
  .navbar {
      border-radius: 5px;
      padding: 10px;
      background-color: #1d1e31;
  }

  .navbar h1 {
      margin-left: 5px;
      font-family: 'Roboto', sans-serif;
      color: white;
  }
  .links {
      text-align:right;
  }
  .links i {
      font-size: 30px;
  }
</style>
</html>```

CodePudding user response:

just add to .navbar

display: flex; - Places elements in flexbox form

justify-content: space-between; - Positions the elements horizontally with space between them

align-items: center; - Places the elements vertically in a balanced way

<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">
  <script src="https://kit.fontawesome.com/dd13dde450.js" crossorigin="anonymous"></script>
  <!-- Fonts -->
  <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&display=swap" rel="stylesheet">
  <!--  -->
  <title>APKHub - Free APK Downloads</title>
</head>
<body>
  <div >
      <h1>APKHub</h1>
      <div >
          <i ></i>
          <i ></i>
          <i ></i>
      </div>
  </div>
</body>
<style>
  body {
      margin: 0;
      padding: 0;
      background-color: #141523;
  }
  .navbar {
      border-radius: 5px;
      padding: 10px;
      background-color: #1d1e31;
      display: flex;
      justify-content: space-between;
      align-items: center;
  }

  .navbar h1 {
      margin-left: 5px;
      font-family: 'Roboto', sans-serif;
      color: white;
  }
  .links {
      text-align:right;
  }
  .links i {
      font-size: 30px;
  }
</style>
</html>

CodePudding user response:

You might want to take a look at flexbox. There are many ways you can use flexboxes, but I've tried achieve what you described here:

<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">
  <script src="https://kit.fontawesome.com/dd13dde450.js" crossorigin="anonymous"></script>
  <!-- Fonts -->
  <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&display=swap" rel="stylesheet">
  <!--  -->
  <title>APKHub - Free APK Downloads</title>
</head>
<body>
  <div >
      <h1>APKHub</h1>
      <div >
          <i ></i>
          <i ></i>
          <i ></i>
      </div>
  </div>
</body>
<style>
  body {
      margin: 0;
      padding: 0;
      background-color: #141523;
  }
  .navbar {
      border-radius: 5px;
      padding: 10px;
      background-color: #1d1e31;
      display: flex;
      flex-direction: row;
      align-items: center;
      column-gap: 20px;
  }

  .navbar h1 {
      margin-left: 5px;
      font-family: 'Roboto', sans-serif;
      color: white;
  }
  .links i {
      font-size: 30px;
  }
</style>
</html>

display: flex; Makes the navbar a flex container.

flex-direction: row; Makes the children elements in the container line up from left to right.

align-items: center; Makes all the items line up on the middle of the axis opposite to what you put in flex direction.

column-gap: 20px; Creates a 20px gap between each flex item.

CodePudding user response:

As for me - nearly ideal solution for headers based on flex :

body {
      margin: 0;
      padding: 0;
      background-color: #141523;
  }
  .navbar {
      border-radius: 5px;
      padding: 10px;
      background-color: #1d1e31;
      display:flex;
      align-items:center; /* vertical alignment */
      gap: 10px;  /* some spaces between all elements */
  }

  .navbar h1 {
      margin-left: 5px;
      margin-right: auto; /* force to 'push' avarything on the right */
      font-family: 'Roboto', sans-serif;
      color: white;
  }

  .navbar  i {
      font-size: 30px;
  }
<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">
  <script src="https://kit.fontawesome.com/dd13dde450.js" crossorigin="anonymous"></script>
  <!-- Fonts -->
  <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&display=swap" rel="stylesheet">
  <!--  -->
  <title>APKHub - Free APK Downloads</title>
</head>
<body>
  <div >
      <h1>APKHub</h1>
      <i ></i>
      <i ></i>
      <i ></i>
  </div>
</body>
</html>

It is also can be achieved with display:inline for header and .links and some additional styles to .links ... but i don't want to mess with it (:

  • Related