I'm working on using CSS to design a layout similar to the one shown in the image below, experimenting with flexbox to achieve the

https://i.sstatic.net/4kNAd.png

I am currently facing an issue with the layout of my navigation bar, as it is displaying in a column instead of a row like the format shown in the image. I have tried using flexbox and setting the display to inline-block individually for each element, but I am not sure if this is the most efficient way to achieve the desired format. I also attempted using grid layout with a 4x3 structure, but struggled to make the main section fill up the entire row with only 3 sections. Any advice on how to fix this or suggestions for a better approach would be greatly appreciated.

body {
  background-color: white;
  font-family: 'Markazi Text', 'serif';
  text-align: center;
  display: flex;
  flex-flow: column wrap;
  justify-content: stretch;
}

header>img {
  width: 25%;
}

nav>ul {
  list-style: none;
  background-color: grey;
  flex-flow: row wrap;
}

nav>li {
  padding: 5px;
  flex-basis: auto;
}

main article {}

.foot {}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Little Lemon</title>
  <link href="styles.css" rel="stylesheet">
</head>

<body>
  <header>
    <img src="Images/Asset <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="daebee9aeea2f4aab4bd">[email protected]</a>" alt="Little Lemon Logo">
  </header>
  <nav>
    <ul class name="uList">
      <li class name="list"><a href="index.html">Home</a></li>
      <li class name="list"><a href="menu.html">Menu</a></li>
      <li class name="list"><a href="book.html">Book</a></li>
      <li class name="list"><a href="about.html">About</a></li>
    </ul>
  </nav>
  <main>
    <h1>Main</h1>
    <section class="article">section1</section>
    <section class="article">section2</section>
    <section class="article">section3</section>
  </main>
  <footer>
    <h1 class="foot">footer1</h1>
    <h1 class="foot">footer2</h1>
  </footer>
</body>

</html>

Answer №1

To start off, I'd like to share some valuable resources that can assist you in understanding the Flexbox concept:

  • Visit Flexbox docs on MDN.
  • Learn about basic concepts of flexbox from MDN.
  • Explore CSS flexible box layout on MDN.
  • Check out "A Complete Guide to Flexbox" on CSS-Tricks.

Now, let me demonstrate a simple example for achieving your desired design which you can modify and experiment with.

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

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  padding: 8px 20px;
  border: 2px solid red;
}

.logo-wrapper {
  text-align: center;
  margin-bottom: 20px;
  border: 2px solid red;
}

.logo-wrapper .logo {
  max-width: 100%;
  max-height: 50px;
  vertical-align: middle;
  object-fit: cover;
}

.navbar {
  display: flex;
  list-style: none;
  margin-bottom: 15px;
  border: 2px solid red;
}

.navbar .nav-item {
  flex: 1 0 auto;
  text-align: center;
} 

<main-page {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding: 6px 15px;
  margin-bottom: 20px;
  border: 2px dashed red;
}
...
</pre>
<pre><code><header>
... (HTML code)
</footer>

The borders serve as visual aids to illustrate the workings of flexbox and its components, outlining each section for clarity.

This example is meant to be a starting point for you to enhance and develop further according to your needs.

Note that this snippet may not address all scenarios, especially regarding responsiveness, often crucial in web development.

Lastly, I suggest exploring various CSS libraries and frameworks like bootstrap, tailwind, etc., to observe how they utilize flexbox utilities, providing a deeper insight into the functionality of flexbox.

Answer №2

Check out this code and let me know if it works for you. I believe I have gotten it right and it should be helpful to you. Thank you.

body {
  background-color: white;
  font-family: 'Markazi Text', 'serif';
  text-align: center;
}

header img {
  width: 25%;
  border: 2px solid black;
  margin: 20px auto;
}

nav ul {
  list-style: none;
  background-color: grey;
  display: grid;
  grid-template-columns: repeat(4, 300px);
  width: 80%;
  margin: 20px auto;
}

nav li a {
  text-decoration: none;
}

nav li {
  padding: 20px;
}

main {
  border: 2px solid black;
  margin: auto;
  width: 70%;
}

section {
  display: flex;
  width: 70%;
  margin: auto;
  gap: 50px;
}

section div {
  display: flex;
  border: 2px solid black;
  height: 150px;
  margin: 20px auto;
  width: 33%;
}

footer {
  display: flex;
  margin: auto;
  width: 80%;
  gap: 10px;
}

.foot {
  border: 2px solid black;
  margin: auto;
  width: 80%;
}
<header>
  <img src="Images/Asset <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4c5c0b4c08cda849a93">[email protected]</a>" alt="Little Lemon Logo">
</header>
<nav>
  <ul class name="uList">
    <li class name="list"><a href="index.html">Home</a></li>
    <li class name="list"><a href="menu.html">Menu</a></li>
    <li class name="list"><a href="book.html">Book</a></li>
    <li class name="list"><a href="about.html">About</a></li>
  </ul>
</nav>
<main>
  <h1>Main</h1>
</main>
<section>
  <div class="article">Section1</div>
  <div class="article">Section2</div>
  <div class="article">Section3</div>
</section>
<footer>
  <div class="foot">
    <h1>footer1</h1>
  </div>
  <div class="foot">
    <h1>footer2</h1>
  </div>
</footer>

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

Unable to retrieve the value of ng-model using $scope

Having some trouble getting the ng-model value when clicking a button that triggers a function to add each ng-model value to an object. Interestingly, when trying to get the value of $scope.shipNameFirst, it shows up as undefined in the second example. I& ...

What is the most effective way to transfer an array from one PHP file to a different JavaScript file?

Utilizing AJAX to send a request to another php page and retrieve the result of a query, I originally used xmlhttprequest to pass the php logic along with the query information. However, I wanted to separate the presentation logic from the actual code logi ...

What method can I use to ensure that the sidebar stays fixed at a particular div as the user continues to scroll down the

Is there a way to automatically fix the sidebar once the user scrolls down and hits the top of the .Section2? Currently, I have to manually enter a threshold number which can be problematic due to varying positions across browsers and systems. Fiddle htt ...

Activate vertical scrolling in JavaScript when an image is clicked

I currently have a collection of button images with different hover effects specified like this: <img src="home.PNG" onmouseover="this.src='homemo.PNG'" onmouseout="this.src='home.PNG'" /> My goal is to make them scroll down to ...

Utilizing a jQuery plugin for input file validation

This code is functioning properly, however the file field is not being validated. All input fields are successfully validated by this plugin except for the file type field. I believe there may be something missing in my implementation, so please help me de ...

Encountering a blank webpage displaying a warning that reads, "The use of 'event.returnValue' is outdated

Although this issue has been discussed before and was previously considered a bug, I am currently using jQuery v1.11.0, which should have resolved it. The problem I am encountering is that when my page loads, there is supposed to be a slide-in effect (as a ...

creating a table displaying data in a horizontal format sourced from ajax/json transformation

I am currently working on a piece of code that retrieves a list of IDs from local storage and compares them to IDs in a JSON file. If there is a match, the corresponding data is displayed in a table. However, I am facing an issue with my table layout as i ...

HTML div ID displaying incorrectly

My main div on the page has the attribute align="center", but it does not seem to align in the center. If you'd like to see the page for reference, click here. This is the CSS: #page{ background-color: #4C1B1B; width:85%; height:500px; ...

What is the best way to ensure that text highlighting appears consistent on all browsers?

I am facing an issue with the appearance of text highlighting between Chrome and Firefox browsers. Is there a way to ensure consistency in the appearance across all browsers? a { text-decoration: none; font-weight: 900; font-size: 4vw !impo ...

What could be causing the issue with this flexbox footer not functioning properly on a mobile device?

Currently, I am honing my skills in using flexbox to create footers. Although the footer layout I have designed looks great on a desktop screen, it unfortunately doesn't display correctly on mobile devices. You can view the footer layout I have been ...

Box without a border wrapping around it

I can't seem to figure out why the border I applied to a child div is not completely enclosing the element. I created two boxes using div tags and added a border to one of them. #box { height: 500px; width: 500px; background-c ...

Retrieve JSON data from Form Submission

While I am not a front end developer, I have been trying my hand at it recently. I hope that the community here can assist me with an issue I am facing. I have a form that is supposed to send files to a server-side API like shown below: <form id="uploa ...

A step-by-step guide on deleting an element within a div using jQuery

I am attempting to delete an HTML element using JQuery like this $('#' + divId + ' .settings_class').remove('.print_settings'); This code does not result in an error or remove the specified html element, however, the selecto ...

Challenges faced with Vuetify's vertical and non-linear stepper components

I've been struggling to grasp the concept of Vuetify's stepper feature. Despite my efforts, I haven't been successful in combining different steppers from their page that each have elements I need but lack others. One example is this one on ...

Creating a Javascript function to turn lights off using CSS manipulation, similar to the feature found

Is there a way to use JavaScript to obscure all elements on a page except for one specific HTML element? This web application is optimized for Chrome, so CSS3 can also be utilized. ...

Slicknav is failing to appear on the screen, although it is being

After spending hours trying to implement a slicknav menu into my school project, I'm stuck and seeking guidance. Despite having some coding experience, I can't seem to find the solution to my problem. Any help, insight, or tips on fixing or impro ...

What is the solution to prevent background-attachment:fixed; from distorting the image?

Looking to create a scrolling background image that doesn't stretch? Typically, using background-attachment: fixed; works, but it's causing the image to stretch and lose positioning capabilities. If you want to see the issue in action, check out ...

Calculate the combined total of two inputted values instantly

Is there a way to add two separate numerical inputs together in real-time and display the sum in a third variable? Here's a clearer explanation: First Variable: 100 (input) Second Variable: 150 (input) Sum: 250 (calculated, not input) Any suggesti ...

What is the best way to eliminate the final character from a series of repeated Xs and following strings

Data consists of [one][two][three]. I want to exclude the last set of brackets and have a result like [one][two]. How can this be achieved using jQuery? ...

Aligning multiple items to the right using Flexbox

While it's common knowledge how to align one item to the right in flexbox, what about aligning multiple items, like the last two elements, to the right and the rest to the left? Take a look at this example where I want elements with the class .r to be ...