Issues with arranging DIV elements using CSS

I have organized a few DIVs within a parent DIV. I am trying to make them align horizontally, but despite my efforts, they remain stacked vertically.

Here is the code snippet:

<style>

#entrycontainer {
    height: 100px;
    width: 500px;
}
#entry {
    height: 100px;
    width: 200px;
}
</style>

      <div id="entrycontainer" >

          <div id="entry" >
          <h1>PHP File Upload/Browser</h1>
          <img src="img/projectimg/fileupimg.png" />
          <p>PHP MySQL CSS</p>
          </div>

          <div id="entry"  >
          <h1>PHP File Upload/Browser</h1>
          <img src="img/projectimg/fileupimg.png" />
          <p>PHP MySQL CSS</p>
          </div>

    </div>

Answer №1

To enhance your entry class, you should include float:left;. The code should be updated to replace #entry with .entry and modify them to reference a class. It is important to use a class whenever multiple elements on the same page are styled similarly.

<style type="text/css>

#entrycontainer {
    height:100px;
    width:500px;
}
.entry {
    float: left;
    height:100px;
    width:200px;
}
</style>

      <div id="entrycontainer">

          <div class="entry">
          <h1>PHP File Upload/Browser</h1>
          <img src="img/projectimg/fileupimg.png" />
          <p>PHP MySQL CSS</p>
          </div>

          <div class="entry">
          <h1>PHP File Upload/Browser</h1>
          <img src="img/projectimg/fileupimg.png" />
          <p>PHP MySQL CSS</p>
          </div>

    </div>

Answer №2

Having two elements sharing the same id is not valid. The purpose of an id is to uniquely identify a single element. If you need to group elements, it's best to use the class attribute, which can be applied to multiple elements.

To resolve this issue, consider applying the CSS property float: left to the elements. Since div elements are typically block-level elements, they will not naturally stay inline. Additionally, include an overflow: auto statement in the parent element to manage the floated elements effectively.

Check out the demonstration here: http://jsfiddle.net/g9bgV/1/

Answer №3

Avoid having two divs with the same ID, as it is not recommended. Additionally, keep in mind that divs are block elements by default, so they will display on separate lines unless styled otherwise.

To address this, update your CSS code to resemble the following:

.entry {
    height:100px;
    width:200px;
    float:left;
}

Next, modify your HTML code as shown below:

<div id="1" class="entry">
    <h1>PHP File Upload/Browser</h1>
    <img src="img/projectimg/fileupimg.png" />
    <p>PHP MySQL CSS</p>
</div>

<div id="2" class="entry">
    <h1>PHP File Upload/Browser</h1>
    <img src="img/projectimg/fileupimg.png" />
    <p>PHP MySQL CSS</p>
</div>

By making these changes, you should be on the right path towards achieving your desired layout.

Answer №4

  1. Ensure that all internal divs are floated.
  2. Using a class is necessary as an id should be distinct on each page.

    .box{ float: right; width: 250px; height: 150px; }

Answer №5

Division elements, or divs, are classified as block-level elements which results in them being positioned below preceding content unlike inline elements such as spans.

  • One option is to apply float:left; to both blocks
  • Alternatively, you can utilize display:table on the container, and display:table-cell on the inner blocks

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

Changing the height of tablerows in Material UI v5: A step-by-step guide

I am attempting to adjust the height of the rows in this material-ui code example. import * as React from "react"; import { styled } from "@mui/material/styles"; import Table from "@mui/material/Table"; import ...

Sending a value to a text box using json data transmission

I am having trouble accessing data from a js file and fetching the value to an html text box. Despite trying, I'm unable to get the desired result. Below are the contents of samle.js file and jsonhtml.html file: { "var1": "1", "var2": "2" } <scri ...

The Bootstrap Navbar appears hidden beneath other elements on mobile devices

While using bootstrap to style my header contents, I encountered a strange issue. The navbar that appears after clicking on the hamburger menu is displaying behind all the components. Even though I've set the z-index to the maximum value, it still doe ...

Is there a way to remove the entire row if I dismiss a bootstrap alert?

Hey there! I'm having a little issue with an alert in a row-fluid. Curious to see? Check out my fiddle. So, when I click the "x" button to dismiss the alert, the row is still visible. Any idea how I can make the entire row disappear when I dismiss it? ...

Effortlessly move and release Internet Explorer

Encountering drag and drop issues in Internet Explorer and Safari, while functioning correctly in Firefox 15 (untested on other versions). Dragging and dropping items between dropzones works in Safari, but sorting does not. In Internet Explorer, nothing wo ...

Organizing Pictures in a Gridded Design

My dilemma lies in displaying a set of thumbnail images within a div. The width of the div can vary depending on the screen size. Each image is fixed at 150px * 150px with a padding of 5px. I aim to arrange these thumbnails in a grid layout while ensuring ...

The styles for the React calendar are not being properly applied to the calendar component due to CSS overriding

Having trouble overriding the default Calendar.css file in NextJS while creating a calendar component. Even after adding my own custom styles, they aren't being applied. Deleting the css file contents doesn't change the format either. Only when c ...

Issue with hiding div using jQuery's length option

I'm currently using Drupal 7.0 along with the Galleria Javascript Image Gallery in fullscreen theme. My theme includes two navigation buttons, and here is the CSS code for them: .galleria-image-nav { height: 159px; opacity: 0.8; position: fixed ...

Why is Python BeautifulSoup's findAll function not returning all the elements in the web page

I am attempting to retrieve information from the following URL . Displayed below is the code I have developed. import requests from bs4 import BeautifulSoup url_str = 'https://99airdrops.com/page/1/' page = requests.get(url_str, headers={&apo ...

Retrieve information from a sensor within an Express server and display it on the user interface

Looking for suggestions on resolving a challenge: I have a Node.js module that retrieves data from a sensor, and I am interested in incorporating a UI element to showcase the sensor data (either in real-time or pseudo-realtime). Is there a way to establ ...

Ways to make a div grow to occupy the leftover width without resorting to the overflow: hidden technique

<div id="container" style="width:100%;"> <div id="left1" style="float:left; width:100px;">float left</div> <div id="left2" style="float:left; width:100px;">float left</div> <div id="remaining">Remaining width&l ...

What could be causing the Bootstrap ProgressBar to not show up?

Having an issue with the ProgressBar component from react-bootstrap: <ProgressBar now={dynamicValue} /> The value dynamicValue changes for each component. However, I am unable to get the progressBar to display in my case. ...

The animated image gracefully glides down the webpage accompanied by an h3

How can I align an image and h3 tag side by side without the image sliding down? <img src="..." alt="..." /><h3>Shopping Cart</h3> I need them to be next to each other but the image keeps moving down. Any suggestions on how to fix this? ...

Ensure that a DIV element stretches beyond the limits of its container

I am having an issue with a div that should overlap everything else as it functions as a menu. Despite trying various positioning tricks, the desired effect is not achieved. The div is only shown when hovering over a certain element. Here is the structure ...

Master the Art of Animating Letters in the DOM by Navigating Through Any Array of Characters

I am attempting to implement a typewriter effect animation where a new message is displayed and animated as I type into an input box. Initially, I tried using a global char variable to iterate through each element of the array. However, whenever I passed ...

In a designated paragraph, set the display of all <span> elements to none using JavaScript

I have a long paragraph with over 10,000 lines of text and I need a way to quickly remove all the lines without hiding the entire paragraph. Specifically, I want to hide each line individually by changing the span style from "display:block" to "display:non ...

The download attribute in HTML5 is functioning properly, however it is causing a redirection to

Is it possible to use the HTML5 download attribute with a URL without being redirected to a new page? Here is the code I am currently using: exportToPdf: function(e) { var link = document.createElement('a'); link.href = 'https://filegener ...

Tips on overriding the outline:none property in CSS

Is there a way to overwrite the 'outline: none' property in CSS? I have a parent class that has this property set, but I want to remove it in the child class. ...

I'm curious if there is a method in c3 js that allows for displaying additional x-axis values when zooming in

Is it possible to dynamically increase the x-axis culling values with the c3.js data visualization tool when zooming in? This functionality is provided by d3.js. How can we implement this feature using c3.js? ...

Step-by-step guide on redirecting a page from a Django form

I'm in the process of developing a dictionary application that allows users to input a word through a form. The issue I'm facing is that when a user enters a word and hits submit, the form disappears leaving only the submit button and the search ...