Positioning two divs side by side, with two more below in the following row

I am attempting to align multiple div elements with a width relative to the screen size.

However, when I try to float them next to each other, they shift to the right and display under each other. I have experimented with applying display: inline-block; and float: left; to the div elements, but that doesn't seem to solve the issue.

My intended layout

Current layout behavior

#navbarselector {
      float: left;
      width: 75%;
      height: 8%;
      z-index: 1;
      background-color: #B4ADA5;
    }

    #ButtonOpt {
      float: left;
      width: 23%;
      height: 8%;
      margin-left: 2%;
      z-index: 3;
      background-color: #B4ADA5;
    }

    /* More CSS code goes here... */
    
<div class="container">
        <div class="nav nav-tabs" id="navbarselector" role="tablist">
          <a ...></a>
          <a ...></a>
          <a ...></a>
          <a ...></a>
          <a ...></a>
          <a ...></a>
          <a ...></a>
          <a ...></a>
        </div>
        <div id="ButtonOpt">
          <div class="dropdown">
            <button ...></button>
            <div id="myDropdown" class="dropdown-menu"></div>
          </div>
          <div class="tab-content">
            <div class="tab-pane active" id="tabs-1" role="tabpanel">
              <div class="tab-pane" id="view-2"></div>
              <div class="tab-pane" id="cmcVGVL"></div>
            </div>

            <!-- More tab content here... -->

          </div>
        </div>
      </div>

Answer №1

If you're in need of a CSS grid implementation, look no further. Check out this resource for a quick and easy solution.

// HTML
<div class='container'>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

// CSS
.container{
  display: grid;
  grid-template-column: 70% 30%;
}

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 display:block-inline feature seems to be malfunctioning

Even though I've specified the width of columns as 25%, the boxes are still not aligning in a single line: ...

Looking for a solution to a problem with your vertical CSS/jQuery dropdown menu

My web app features a vertical CSS menu that is working correctly except for one minor issue. When I mouse out on all elements with the class a.menutoggle, the last dropdown menu remains open. I am struggling to find a solution to hide it. Can someone plea ...

Retrieve data from a JSON object within an HTML document

How do I display only the value 100 in the following div? <div> {{uploadProgress | async | json}} </div> The current displayed value is: [ { "filename": "Mailman-Linux.jpg", "progress": 100 } ] Here is my .ts file interface: interface IU ...

ng-Pattern in AngularJS

Enter a number as your username in the field below: <fieldset class="col-sm-12 col-xs-12 text-center"> <label for="username">Username</label> <input type="text" id="username" ng-pattern="/^[0-9]*$/" ...

Tips for creating a responsive graphic using Bootstrap CSS

I am currently trying to determine how to create individual graphics that can be directly loaded via CSS and made responsive. When I resize the screen, the graphics also adjust accordingly. However, on smaller displays such as mobile phones, the graphics ...

Troubleshooting issue: Bootstrap not loading with custom CSS on Flask platform

Recently, I started learning Flask and created a basic web application. Utilizing Bootstrap 5 for my project, I encountered an issue where my custom CSS fails to work when the Bootstrap stylesheet is loaded (removing it resolves the problem). My folder st ...

Bootstrap 3 offset doesn't respond to dimensions

Even though I have set an offset for a medium-sized screen, the offset still appears in large screens. Here is a snippet of my HTML code. How can I resolve this issue? <div class="col-lg-6 col-sm-12"> <div class="row"> <div class="co ...

The attempt to transfer the image to the newly established file was unsuccessful

Whenever I try to upload an image to a file named 'uploads' within the same directory as my PHP files, I keep encountering an error message indicating an 'Undefined index'. Can someone explain what this error means and provide a solutio ...

Sticky Sidebar Attached to Parent Container with Smooth Sliding Effect

Is it possible to have my sidebar push the content across when opened, while keeping the fixed navigation relative to its parent element instead of the viewport? The sidebar works fine in Firefox but breaks out of the parent in Chrome. Link to JSFiddle & ...

Updating all the direct components within the corresponding category with jQuery

Here is the HTML content I am working with: <li class="info"> info<li> <li class="other"> info<li> <li class="other"> info<li> <li class="Error"> error<li> <li class="other"> error<li> < ...

Tips for gently scrolling instead of quickly scrolling all at once

As a novice in HTML, I have a question about navigation to an ID targeted by an anchor tag. For example: When I execute this code, it quickly jumps to the specified ID but I would like to incorporate animations. Is there a way to achieve this? ...

Unable to set DIV width to 100% and show a scrollbar

I am facing an issue with the width of a DIV element on my webpage. Despite setting it to 100% width, it only takes up the visible window's width and not the full page width, especially when a horizontal scroll bar is displayed. Below is the HTML cod ...

Clicking two times changes the background

I am facing an issue with three boxes on my website. Each box is associated with a corresponding div. When I click on any box, the div displays and the background color turns red. However, when I click on the same box again, the div disappears but the back ...

I am unable to display the content even after setting `display: block` using the `.show()`

Hello there, I have attached my javascript and html code. While in debug mode, I can see that the CSS property 'display: none' changes to 'display: block', but for some reason, the popupEventForm does not open up. Any suggestions on why ...

Add the class "form-group-row" to the "form-horizontal" element

Check out the code snippet here: http://www.bootply.com/h0E7YjPU4n. Is there a way to adjust spacing between input fields while keeping them the same height? Any tips on making input fields uniform in length? ...

In PHP/HTML, if the URL is domain.co.uk/?debug, then the following action will

Apologies for what may seem like a basic question, but I've been searching for a clear answer with no luck! My goal is simple - when someone goes to , I want to show extra details, like the code version or any other notes I include. Once again, sorr ...

Is there a way to dynamically assign the background color of a webpage based on the exact width and height of the user's screen?

I have customized the CSS of my website by setting the height to 800px and width to 1050px. Additionally, I have chosen a blue background-color for the body tag. It is important that the entire application adheres to these dimensions. However, when viewe ...

Configuring the interactive background for a textbox

How can I set a background image for a textbox that is clickable? I tried using a div tag with position:absolute positioned above the textbox, and included the image within it. However, the issue is that the image appears above the text. I attempted to a ...

Capturing an image of an HTML5 canvas that includes an image object: tips and tricks

After creating a canvas and adding various objects like images, clipart, and text to it, I encountered an issue. When capturing a snapshot of the canvas with only text using the method `canvas.toDataURL()`, the snap is correct. However, when I include an i ...

How to retrieve Checkbox label text using Selenium and C#

Trying to extract the text value of a checkbox label. Check out this HTML code snippet <div id="content" class="large-12 columns"> <div class="example"> <h3>Checkboxes</h3> <form id='checkboxes'> &l ...