Issues arising from the alignment of css in html documents

Can anyone assist with my issue? I am trying to add a header to my webpage, but I'm facing a problem where the order of div declarations determines their placement on the page. The first declared div appears on top, and the second one appears below, regardless of the position set. Here is the CSS code:

css;

    body 
{
    background-color:#CCC;
}

#pageHeader{
    position:relative;
    width:900px;
    height:94px;
    background-color:White;
    margin:0 auto;

}

    #nhsLogo
{
        position:relative;
        margin-left:40px;
}


    #openingHours
{
        position:relative;
        margin-left:500px;
        top:0px;

}

Here is the HTML code:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Template.master.cs" Inherits="Template.Template" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link type="text/css" rel="stylesheet" href="css/bootstrap.css" />
    <link type="text/css" rel="stylesheet" href="css/normalize.css" />     
    <link type="text/css" rel="stylesheet" href="css/default.css" />  
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <div id="pageHeader">  

      <div id="openingHours">
    <p style="color:Green; font-size:18px; font-style:oblique;">0876 890756</p>
    <p style="color:Purple; font-size:18px; font-style:oblique;">Opening hours</p> <p></p>
    </div>

    <div id="nhsLogo">
    <p><img src="img/high.png" alt="GPlus logo" /></p>   
    </div>



    </div>


    <form id="form1" runat="server">



    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>

    <script type="text/javascript"  src='<%# ResolveUrl ("~/Js/jquery-1.2.3.min.js") %>'></script>

    <script type="text/javascript" src="js/bootstrap.min.js"></script> 

</body>
</html>

Answer №1

If you want to display two divs side by side, one way to achieve this is by using the "float" CSS property:

float:left;

For more information on how float works, you can visit this page.

Alternatively, you can also utilize absolute positioning.

Start by giving your body the css rule: position:relative;

Then for any child elements of the body that you wish to position, apply the following css rules:

position:absolute;
top: 10px; //adjust this value for vertical positioning
left: 10px; //adjust this value for horizontal positioning

More information on CSS positioning is available at this link.

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

Header spanning the entire width with varying ends

Hello everyone, I'm currently working on a website and struggling to create a header similar to the image shown above. I want the header to span the full width of the page. Can anyone provide guidance on achieving this using HTML5/CSS3 without relyin ...

Setting up the default path that appears in the URL

Looking to simplify the URL path on your website? When developing webpages, you may have addresses like: www.example.com/index.html www.example.com/about_us.html www.example.com/en/index.html Is there a way to make these URLs more concise, such as: www ...

Tips for creating a CSS triangle background on a div without relying on borders or images

I have experience creating triangles using CSS borders and images, but this time I want to achieve it using background color. Here is the image of the desired outcome: https://i.stack.imgur.com/qP3yt.jpg If anyone can assist me with this, it would be gre ...

Revamping legacy code into an Ember component

Recently I started learning Ember and I'm really enjoying it! However, I'm facing some difficulties, especially when it comes to working with components. Currently, I'm trying to convert some old code into a Component in Ember but I'm ...

Having difficulty retrieving text from textarea with jquery

I'm experiencing an issue with my jquery script where the top two buttons are showing 'undefined' instead of performing the same action as the buttons below them. Could someone please pinpoint where I went wrong? I want the two buttons at t ...

placing a dropdown menu below the search bar

Let's say I have a container with an input search field. My goal is to position a select dropdown right below the search input, ensuring that the dropdown has the same width as the search input (similar to autocomplete functionality). Here's what ...

Is anyone interested in incorporating Bootstrap 4.1.2 into their project and utilizing the npm package manager for easy integration?

I am trying to integrate Bootstrap 4.1.2 into my project using npm as a package manager. Can someone assist with this? ** note: I prefer to have Bootstrap locally rather than using BootstrapCDN as shown below: <link rel="stylesheet" href="//maxcdn.boo ...

Knockout text binding does not automatically update the width

Recently, I encountered a bug in an ongoing project where the user name was appearing within another element until hovered over with a cursor. Upon further investigation, I discovered that this issue stemmed from the project's usage of Knockout.js. I ...

How to create a bottom border in several TD elements using a combination of CSS and jQuery

Check out my Website: Search Page I have written some CSS that functions well when searching by Name, but not by Specialty: .displayresult { display: block; } #fname, #lname, #splabel, #addlabel, #pnlabel { border-width: 4px; border-bottom-st ...

Floating unordered list items in a gallery display

I am dealing with a Gallery view where I am using the UL LI elements with float left to create a gallery-like layout with multiple lines based on the content. However, I am encountering an issue where after the first line, the layout seems to malfunction i ...

What causes socket.emit to duplicate after a dynamic update with jQuery trigger?

Is there a way to dynamically update the content of a div called "display-holder" in client-side code while ensuring that the socket.emit function fires only once? I have tried using off() and unbind() functions, but they do not seem to work in preventing ...

Ways to customize the color of a ReactSelect component?

Hey there! I'm currently utilizing the React select component, with the following import statement: import ReactSelect, {ValueType} from 'react-select'; Here is what my component currently looks like: https://i.stack.imgur.com/yTmW4.png Th ...

Plugin for jQuery that paginates text when it overflows

Looking for a solution here. I have a fixed width and height div that needs to contain text. If the text exceeds the size of the div, I want it to paginate with dots at the bottom of the page indicating each page, similar to slideshow functionality. Are t ...

Take a breather with a break in a div's outline

I'm looking to add a break on the right border of my div which already has an outline around it. Here's a visual example of how I want it to look like: (how I want it to look like) Here is my HTML code: <div class="carouseldiv w-75 mx-au ...

Enabling the use of dot or full stop in JavaScript keycode for numeric input

I am facing a challenge with a method that is supposed to allow all numeric values, including the '.' symbol. Below is the code for my method. While it successfully allows numeric values, it seems to have an issue with keyCode == 190. function I ...

Retrieve information from a MySQL database and integrate it into a different application

This php script is used to generate a table with a "book" button next to each row. The goal is to extract the values of "phase" and "site" from the specific row where the "book" button is clicked, and transfer them to another form (in "restricted.php") fo ...

How can I create dynamic tabs using Tailwind CSS?

I am looking to create an animated tab using React and Tailwind CSS. Here is the code I have so far: import React from 'react' import clsx from 'clsx' export const Modal = () => { const [theme, setTheme] = React.useState<' ...

When multiple checkboxes are selected, corresponding form fields should dynamically appear based on the checkboxes selected. I attempted to achieve this functionality using the select option method

Require checkboxes instead of a selection option and have multiple checkbox options. Depending on the checked checkboxes, different form fields should appear. A submit button is needed. I have included some CSS code, but a more detailed CSS code is requir ...

What is the best way to eliminate the gap between these two div elements?

There's a gap between two divs in my HTML that I can't seem to remove. Here are the relevant CSS styles: #tab-2-content { display: grid; grid-template-rows: 1fr 2fr; width: 70%; margin: 0 auto; grid-gap: 0; } ... (CSS code continues) ...

Illuminate the rows in a table generated from a parsed text file using PHP

I am facing an issue with my PHP logic for selecting and highlighting rows in a table based on dropdown selection. I have a group of text files that are parsed into a table, and I need to highlight rows that match selections from 5 dropdowns created from t ...