What is the best way to arrange my crimson blocks to sit next to each other?

Is there a way to align the red boxes side by side with some space in between them for separation, and how can I ensure that the signin/signup button appears against the blue background of the header?

I attempted using float but encountered issues.

The desired outcome is for the red boxes to be arranged horizontally with spacing between them, and for the signin/signup button to be clearly visible against the blue background of the header.

header {
    background-color: Blue;
    color: yellow;
    margin-top: -21px;
    margin-left: -10px;
    border-bottom-left-radius: 25px;
    border-bottom-right-radius: 25px;
}
nav ul {
    list-style: none;
    position: relative;
    float: right;
}
/* red box */
#a {
    width: 100px;
    height: 100px;
    background: red;
    float: left;
    padding-right: .6em;
    margin: 1em 0;

}
/* red box */
#b {
    width: 100px;
    height: 100px;
    background: red;
    float: ;
    padding-right: .6em;
    margin: 1em 0;
}
/* red box */
#c {
    width: 100px;
    height: 100px;
    background: red;
    float: right;
    padding-right: .6em;
    margin: 1em 0;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>ABC</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <header>
        <h1>ABC</h1>
        <!-- signin/signup -->
        <nav>
            <ul>
                <li><button type="button" name="signin/signup">signin/signup</button></li>
            </ul>
        </nav>
    </header>
    <body>
        <!-- Video  -->
        <video>
            <source src="Welcome.mp4" type="video/mp4">
        </video>
        <!-- 3 informational red boxes -->
        <div class="">
            <ul>
                <li id="a"></li>
                <li id="b"></li>
                <li id="c"></li>
            </ul>
        </div>
    </body>
</html>

Answer №1

To accomplish this layout, you can utilize the combination of display: flex; and justify-content: space-between; for both the header and the ul containing the red boxes. This will evenly distribute the child elements horizontally within these containers. Additionally, using align-items: center will align the child elements vertically in the header.

header {
    background-color: Blue;
    color: yellow;
    margin-top: -21px;
    margin-left: -10px;
    border-bottom-left-radius: 25px;
    border-bottom-right-radius: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
nav ul {
    list-style: none;
    position: relative;
    
}
.x ul {
    display: flex;
    justify-content: space-between;
    list-style: none;
    }
/* red box */
#a {
    width: 100px;
    height: 100px;
    background: red;
    padding-right: .6em;
    margin: 1em 0;

}
/* red box */
#b {
    width: 100px;
    height: 100px;
    background: red;
    padding-right: .6em;
    margin: 1em 0;
}
/* red box */
#c {
    width: 100px;
    height: 100px;
    background: red;
    padding-right: .6em;
    margin: 1em 0;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>ABC</title>
        <link rel="stylesheet" type="text/css" href="style.css">
    </head>
    <header>
        <h1>ABC</h1>
        <!-- signin/signup -->
        <nav>
            <ul>
                <li><button type="button" name="signin/signup">signin/signup</button></li>
            </ul>
        </nav>
    </header>
    <body>
        <!-- Video  -->
        <video>
            <source src="Welcome.mp4" type="video/mp4">
        </video>
        <!-- 3 informational red boxes -->
        <div class="x">
            <ul>
                <li id="a"></li>
                <li id="b"></li>
                <li id="c"></li>
            </ul>
        </div>
    </body>
</html>

Answer №2

Give this code a try, I've made some slight adjustments to your original code.

body {
  margin: 0;
  padding: 0;
}

header {
  display: inline-block;
  width: 100%;
  height: auto;
  background-color: Blue;
  color: yellow;
  border-bottom-left-radius: 25px;
  border-bottom-right-radius: 25px;
}

div ul {
  width: 100%;
  display: inline-block;
}

header h1 {
  float: left;
}

header nav {
  float: right;
}

div ul{
  list-style: none;
  float: right;
}


div ul li{
      display: inline-block;
      width: 100px;
      height: 100px;
      background: red;
      float: left;
      padding-right: .6em;
      margin: 1em 1em;
}

Answer №3

To display the boxes side-by-side, make sure to add display: inline-block; to each box and remove the floats.

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>ABC</title>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>

  <body>
    <header>
    <h1>ABC</h1>
    <!-- signin/signup -->
    <nav>
      <ul>
        <li><button type="button" name="signin/signup">signin/signup</button></li>
      </ul>
    </nav>
  </header>
    <!-- Video  -->
    <video>
      <source src="Welcome.mp4" type="video/mp4">
    </video>
    <!-- 3 informational red boxes -->
    <div class="boxes">
      <ul>
        <li id="a"></li>
        <li id="b"></li>
        <li id="c"></li>
      </ul>
    </div>

  </body>
</html>

CSS

header {
  background-color: Blue;
  color: yellow;
  margin-top: -21px ;
  margin-left: -10px;
  border-bottom-left-radius: 25px;
  border-bottom-right-radius: 25px;
}

nav ul{
  list-style: none;
  position: relative;
}

.boxes ul li {
  display: inline-block;
}

/* red box */
#a{
  width: 100px;
  height: 100px;
  background: red;
  padding-right: .6em;
  margin: 1em 0;

}
/* red box */
#b{
  width: 100px;
  height: 100px;
  background: red;
  padding-right: .6em;
  margin: 1em 0;
}
/* red box */
#c{
  width: 100px;
  height: 100px;
  background: red;
  padding-right: .6em;
  margin: 1em 0;
}

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

The capacity to rotate div containers, adjust their dimensions, and engage with the content within

I'm attempting to design small clickable div boxes that flip 180° when clicked to reveal interactive content. This includes the ability to click links, copy text, or manipulate the content with additional buttons. Although I've successfully ach ...

Ways to establish communication between an iframe and its parent website

I have a website embedded in an iframe that is not on the same domain. Both websites belong to me, and I would like to establish communication between the iframe and the parent site. Is this achievable? ...

Adding a gradient to enhance an SVG chart

Hey there! I'm currently experimenting with Plotly to create some awesome charts, and I've been trying to figure out how to give my area-charts a gradient instead of the usual fill with opacity. This is how I typically build my graph: Plotly.ne ...

Utilizing the content of an HTML element within Ruby embedded code - a comprehensive guide

Below is the code snippet in question: <% @groups.each do |group| %> <tr> <td id="groupid"><%= group.id %></td> <td><a href="#dialog" name="modal"><%= group.title %></a></td> </tr> &l ...

PHP: Issues with displaying data from a SELECT * FROM query in tables

My goal is to style tables pulled from my database so that the columns in the rows align with the column names for better readability. I attempted to use PHP to achieve this by creating a table outside a while loop to display the names and then starting t ...

Java: Issue with JLabel Text Alignment

At the bottom of my panel, I have a JLabel that provides text instructions to the user. When some of the text exceeded the screen width, I used tags to fix this issue. However, after implementing the code shown below, the text is no longer centered an ...

Web server decides on "Multiple Options" while utilizing %3F instead of "?" in the URL

I have been using the Lazarus-IDE for a project and encountered an issue with one of its components that doesn't accept "?" in the URL for online help info. I attempted to encode "?" as "%3F" in the URL, thinking it was the correct encoding, but both ...

Customizing error messages to display validation errors instead of default text errors in the Django UserCreationForm

I'm encountering an issue with the registration form on my website. The form itself is straightforward, but I'm facing a problem where if a username is already taken or if the two password fields don't match, Django doesn't respond afte ...

Strange HTML pop-up keeps appearing every time I use styles in my code or insert anything with CSS

Recently, I created an OctoberCMS backend setup through my cPanel (I also have one on my localhost). Now, I am trying to add a background image but every time I attempt to do so, a strange HTML popup appears that I can't seem to figure out. Here is th ...

Unable to retrieve the 'href' on different pages

Why am I unable to retrieve the "href" from other pages, but still can on the first page? Is there something wrong with it? Will changing the Xpath allow me to get all "href"s from every page? !pip install selenium from selenium import webdriver import t ...

Modifying the color of the highlighted selection in a dropdown select box

Is it possible to change the blue highlight on this dropdown to gray? Check out this demo of a select box I am aiming to alter the highlight color to gray, can someone help me achieve this? select { border: 0; color: #EEE; background: transparen ...

Issue regarding custom CSS implementation in Angular project

Being a French speaker, I apologize in advance for any mistakes I might make. I am also fairly new to Angular, so if you could provide detailed explanations in your responses, it would be greatly appreciated. Thank you. I am trying to import a custom CSS ...

Sliding Navigation Panel

Currently, I am attempting to implement a sidebar push navigation that mimics the one showcased here. My HTML structure includes content within a center element div. The code snippet is as follows: <div id="mySidenav" class="sidenav"> <a href="j ...

Using a class variable to access canvas methods in Javascript

As someone new to Javascript, I am facing a bit of confusion when it comes to classes and objects. Recently, I refactored some code into a working class but the process did not go as smoothly as I had hoped. Despite searching through Stackoverflow, Google ...

Dropdown trigger changing image with AJAX

When a color is selected from one dropdown menu, it triggers a change in another dropdown menu and the image displayed. The ID for the dropdown affected by the color selection is "style_code". <script> function getState(val) { $.ajax({ ...

Incorporate titles for items in the jquery caroufredsel plugin

I am currently using the second example of the caroufredsel plugin, which can be found on this page . I am attempting to add a caption for each picture. To achieve this, I have used `li` and `lis` in my HTML code: <div class="list_carousel"> &l ...

Having trouble with the PHP code for sending an email using a basic form

This is an example from my HTML page. <form method="POST" action="sm.php"> <p>Login</p><br /> Username: <input type="text" size="10" maxlength="50" name="un"> <br /> Password: <input type="text" size="10 ...

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; ...

Streamline Access to Zimbra Server Automatically

Currently, I am creating a webpage with a login feature at www.newpage.com. Here is the code snippet for reference: <form name="login"> Username<input type="text" name="userid"/> Password<input type="password" name="pswrd"/> <input ty ...

Submit information from an HTML form to a PHP script and then send the response back to the client using AJAX,

Looking to run a PHP script using AJAX or JavaScript from an HTML form and then receive the results on the HTML page. This is what my changepsw.php file looks like: <?php // PHP script for changing a password via the API. $system = $_POST['syst ...