Is there a way to position the main and aside elements next to each other?

Can anyone help me with positioning my main class next to the aside class instead of below it? I'm having trouble figuring it out.

Here is the code snippet:

aside {
  height: 100vh;
  width: 350px;
  justify-content: space-between;
  flex-direction: column;
}

aside ul {
  padding-top: 30%;
  list-style-type: none;
  text-align: center;
}

aside a {
  text-decoration: none;
  display: inline-block;
  font-size: 23px;
  color: $color5;
  margin: 40px;
  font-family: $font1;
  font-weight: lighter;
}

aside a:hover {
  color: $color1;
}
<aside>
  <ul>
    <li><a href="#PersonalInformation">Personal Information</a></li>
    <li class="second"><a href="#SecurityandLogin">Security and Login</a></li>
    <li><a href="Logout">Logout</a></li>
  </ul>

</aside>
<main>
  <h4>To keep you safe and secure</h4>
</main>

Answer №1

When faced with such situations, it is advisable to utilize flexbox or CSS grid, as shown below:

.container {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 1rem;
}
aside {
  min-height: 100vh;
  justify-content: space-between;
  flex-direction: column;
  border-right: 1px solid red;
}

aside ul {
  padding-top: 30%;
  list-style-type: none;
  text-align: center;
}
aside a {
  text-decoration: none;
  display: inline-block;
  font-size: 23px;
  color: $color5;
  margin: 40px;
  font-family: $font1;
  font-weight: lighter;
}

aside a:hover {
  color: $color1;
}

   
<div class="container">
  <aside>
    <ul>
      <li><a href="#PersonalInformation">Personal Information</a></li>
      <li class="second"><a href="#SecurityandLogin">Security and Login</a></li>
      <li><a href="Logout">Logout</a></li>
    </ul>

  </aside>
  <main>
    <h4>To keep you safe and secure</h4>
  </main>
</div>

Answer №2

To achieve the desired layout, consider using either float left for positioning or wrapping 'aside' and 'main' within a div with display flex. Feel free to reach out if you require further assistance.

Answer №3

To achieve this layout, you have a few options:

  1. Set both elements to display: inline-block;
  2. Utilize the grid property in the parent class.
  3. Make the parent class a flex container with display: flex; and flex-direction: row;

Here is an example using (inline-block):

aside,
main {
  display: inline-block;
  vertical-align: middle;
  border: 1px solid blue;
}

aside {
  height: 100vh;
  width: 350px;
  justify-content: space-between;
  flex-direction: column;
}

aside ul {
  padding-top: 30%;
  list-style-type: none;
  text-align: center;
}

aside a {
  text-decoration: none;
  display: inline-block;
  font-size: 23px;
  color: $color5;
  margin: 40px;
  font-family: $font1;
  font-weight: lighter;
}

aside a:hover {
  color: $color1;
}
<div>
  <aside>
    <ul>
      <li><a href="#PersonalInformation">Personal Information</a></li>
      <li class="second"><a href="#SecurityandLogin">Security and Login</a></li>
      <li><a href="Logout">Logout</a></li>
    </ul>

  </aside>
  <main>
    <h4>To keep you safe and secure</h4>
  </main>
</div>

And here's an example utilizing (flex):

div {
  display: flex;
  flex-direction: row;
  align-items: center;
}
main, aside {
  border: 1px solid blue;
}

aside {
  height: 100vh;
  width: 350px;
  justify-content: space-between;
  flex-direction: column;
}

aside ul {
  padding-top: 30%;
  list-style-type: none;
  text-align: center;
}

aside a {
  text-decoration: none;
  display: inline-block;
  font-size: 23px;
  color: $color5;
  margin: 40px;
  font-family: $font1;
  font-weight: lighter;
}

aside a:hover {
  color: $color1;
}
<div>
  <aside>
    <ul>
      <li><a href="#PersonalInformation">Personal Information</a></li>
      <li class="second"><a href="#SecurityandLogin">Security and Login</a></li>
      <li><a href="Logout">Logout</a></li>
    </ul>

  </aside>
  <main>
    <h4>To keep you safe and secure</h4>
  </main>
</div>

Lastly, here's an example using (grid):

div {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 1rem;
}

aside,
main {
  border: 1px solid blue;
}

aside {
  height: 100vh;
  width: 350px;
  justify-content: space-between;
  flex-direction: column;
}

aside ul {
  padding-top: 30%;
  list-style-type: none;
  text-align: center;
}

aside a {
  text-decoration: none;
  display: inline-block;
  font-size: 23px;
  color: $color5;
  margin: 40px;
  font-family: $font1;
  font-weight: lighter;
}

aside a:hover {
  color: $color1;
}
<div>
  <aside>
    <ul>
      <li><a href="#PersonalInformation">Personal Information</a></li>
      <li class="second"><a href="#SecurityandLogin">Security and Login</a></li>
      <li><a href="Logout">Logout</a></li>
    </ul>

  </aside>
  <main>
    <h4>To keep you safe and secure</h4>
  </main>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Numbers formatted with a separator for every thousand units

After utilizing this counter to count up to a specific number, I noticed an issue: (function($) { $.fn.countTo = function(options) { // Merging default plugin settings with custom options options = $.extend({}, $.fn.countTo.defaults ...

Creating nested columns in a bootstrap grid system can enhance the structure and organization of your

I am currently attempting to use Bootstrap grid to create nested columns, but unfortunately, the layout I am getting is not nested as intended. {% for home in home %} <div class="container"> <div class="row" ...

Using trigonometry and Javascript to determine the necessary padding for an image to rotate without being cut off

Within the known rect (grey) of the outer parent element is an image element (orange) with its overflow hidden. I am trying to determine the necessary padding for the image element (with known width and height) in order to rotate it to a specific angle, s ...

The code functions properly on React Webpack when running on localhost, however, it fails to work once deployed to AWS Amplify

As I work on my React.js app, I encountered an issue with hosting pdf files on Amplify. While everything runs smoothly on localhost/3000, allowing me to access and view the pdf files as desired either in a new tab or embedded with html, the same cannot be ...

Why do I have to press the button twice for it to actually work?

I am new to programming and I want to create something that has 3 buttons to control the display of 3 hidden images respectively. When I click the first button, the image appears immediately, but I have to click it twice to show the second image. Can anyon ...

Incorporating a .jar file into HTML (for remote controlling a Raspberry Pi)

In my current project, we are working on remotely controlling a toy car using two Raspberry Pis (one in the car, one in the remote control). The setup is operational at this point, allowing the remote control to drive the car using a touch display. We hav ...

Numerous intersecting lines on display within Google Maps

Currently, I am working on displaying multiple flight routes on Google Maps. I have implemented polylines with geodesic to achieve this functionality successfully. However, a challenge arises when more than two flights intersect the same route, causing o ...

Potential issue: Firefox causes distortion in animated stroke-linecap="round" properties

While working on a project on Stack Overflow, I noticed a potential bug in Firefox when animating a line with stroke-linecap="round" and vector-effect="non-scaling-stroke" svg{border:1px solid} path{ animation: draw 1s ease-in; ...

Don't forget to include the "http://" prefix if it's missing from

Hi there! I need some help with a simple code snippet. <a href="'.$aProfileInfo['Website'].'" target="_self"> <div class="callButton">Website</div> </a> I'm facing an issue where if the user doesn&apos ...

What is the method for inserting a newline into a textarea with an HTTPRequest?

Is it possible to print a newline in a textarea using the HTTPRequest property? Here's the code I have: <script> function sendRequest(str) { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } el ...

Tips for incorporating a CSS class or id into Html.PagedListPager

Currently utilizing a PagedListPager: @Html.PagedListPager((IPagedList)Model, page => Url.Action("InboxWithNoReplyListPaging", new { page = page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "G ...

How can we ensure that an inline-block span inherits the text-decoration property from all of its ancestor elements?

I created an inline-block span inside u and s tags, hoping it would display with both strike-through and underline text decorations, but unfortunately, neither of them appeared. If I set its text-decoration to inherit, it will only inherit the text decora ...

Flask Modal fails to function properly in the absence of table data

I'm currently troubleshooting an issue with my modal on a Flask web app that utilizes a SQLite database. When trying to add new rows to the table using some JavaScript code, everything works perfectly unless the table is empty. In that case, I am unab ...

Button click event not triggering JavaScript execution

I am experimenting with HTML, PHP and JS and have encountered a problem. Here is my code: <html> <head> <title> Dummy Code </title> <script> sendMail(){ <?php $to = '<a href="/cdn-cgi/l/email-protection" class ...

How do you calculate the distance of a 3D model?

I am interested in creating a 3D model of a measuring tape similar to the one shown below: You can view the product image at this link: Link. They use Webgl, but not Three.js. Could someone provide instructions on how to create a measuring tape for a 3D ...

css, asp:listview and the use of the nth-child selector

Striving to enhance my CSS3 skills and move away from using table tags in my ASP.NET project, I am currently working with Visual Studio 2010, .NET 4.0, and VB.Net. Specifically, I am facing an issue with a listview where I am attempting to alternate the ro ...

Is there another alternative for the <v-app> tag in Vuetify that can be used as a replacement?

UPDATE Kudos to Gabriel Tortomano for the solution! I swapped out the root <div> tag with <v-app and tackled the css adjustments that came with <v-app>. It turned out to be easier than expected. Just reset the properties that are automatic ...

What could be the reason my clearInterval is failing to function properly?

<!DOCTYPE html> <html lang="en"> <head> <title>Lab 10</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> </head> <body style="background-color:lightgreen;"> ...

Keep the lock engaged during data input to prevent accidental slashes

Incorporating Symfony2.3.4, PHP5.6.3, Twig, HTML5, jQuery2.2.3, and CSS3. I am looking to implement a feature where the slashes (or separators in general) in an input field remain locked as the user enters numbers corresponding to the day, month, and year ...

Is it possible to create this design using Masonry?

https://i.sstatic.net/NFszG.png I have been attempting to create a grid layout like so: .grid { width: 99%; border: 1px solid #ccc; } .grid a, .grid .grid-sizer { display: inline-block; width: 20%; padding-bottom: 20%; background-size: cover; ...