Side widget placement

I am having trouble with positioning my sidebar to the right side of my content while keeping it within the same 'box'. Here's what I'm facing:

In the image, you can see that the sidebar is on the right side, but it's not contained in the 'content' box as I would like it to be positioned almost directly below my menu. Can someone please assist me? Below is a snippet of my code (please ignore the Danish comments, they are just notes):

  body {
    background: #98c8d7;
    width: 1000px;
    margin: auto;
    font-family: "Trebuchet ms", Verdana, sans-serif;
  }
  #header {
    background: #fff url(banner.jpg) no-repeat;
    margin: 10px 0 10px 0;
    padding: 8em 2em 1em 2em;
    text-align: center;
    border-radius: 15px;
    opacity: 0.8;
    border: 1px dotted #000
  }
  /*This formats the menu */
  ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  li {
    float: left;
  }
  a:link,
  a:visited {
    display: block;
    width: 312.5px;
    font-weight: bold;
    color: #000;
    background-color: #51a7c2;
    text-align: center;
    padding: 4px;
    text-decoration: none;
    text-transform: uppercase;
    border: 1px solid #91cfca;
    opacity: 0.8;
  }
  a:hover,
  a:active {
    background-color: #98c8d7;
  }
  #content {
    background: #b4cdd9;
    color: #000;
    padding: 1em 1em 1em 1em;
    top right bottom left
  }
  #tekst {
    background: #98c8d7;
    color: #000;
    opacity: 0.8;
    margin: 5px 0 5px 0;
    padding: 0.5em 1em 1em 1em;
    text-align: left;
  }
  #sidebar {
    background: #b4cdd9;
    color: #000;
    width: 320px;
    position: relative;
    float: right;
    margin: 5px 0 5px 0;
    padding: 0.5em 1em 1em 1em;
    text-align: left;
    border-style: outset;
    border-width: 3px;
    border-color: black;
  }
  a {
    color: #0060B6;
    text-decoration: none;
  }
  a:hover {
    color: #00A0C6;
    text-decoration: none;
    cursor: pointer;
  }
<!doctype html>

<head>
  <!-- Title -->
  <title>IT-help for the elderly</title>
  <meta charset="utf-8">

  <link href="CSS sheet.css" rel="stylesheet" type="text/css" />

</head>

<body>

  <!-- This div contains your content, i.e., your main text -->
  <div id="content">

    <!-- Header. Contains banner -->
    <div id="header">
    </div>

    <!-- Menu -->
    <ul>
      <li><a href="home.html">Home</a>
      </li>
      <li><a href="prices.html">Prices</a>
      </li>
      <li><a href="contact.html">Contact</a>
      </li>
    </ul>


    <!-- Your main text goes here -->
    <div id="tekst">
      <h1>Heading 1</h1>

      <p>Here you can write about what you offer, why, how, to whom, and other information.</p>

      <h2>Subheading 1</h2>
      <p>Here you can maybe write a bit about yourself and your qualifications?</p>
      <div id="sidebar">
        <h3>Leon Laksø</h3>
        <p>So-and-so-many years in service, certified blah blah, all sorts of other stuff. Maybe include a picture where you look friendly?</p>
        <p>Maybe a mail link could go here?</p>
      </div>
    </div>


  </div>


</body>

</html>

Answer №1

There is a simple solution available to rearrange your html layout by shifting the sidebar as the first child of the div with the id #tekst:

body {
  background: #98c8d7;
  width: 1000px;
  margin: auto;
  font-family: "Trebuchet ms", Verdana, sans-serif;
}
#header {
  background: #fff url(banner.jpg) no-repeat;
  margin: 10px 0 10px 0;
  padding: 8em 2em 1em 2em;
  text-align: center;
  border-radius: 15px;
  opacity: 0.8;
  border: 1px dotted #000
}
/*This styles the menu */

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
li {
  float: left;
}
a:link,
a:visited {
  display: block;
  width: 312.5px;
  font-weight: bold;
  color: #000;
  background-color: #51a7c2;
  text-align: center;
  padding: 4px;
  text-decoration: none;
  text-transform: uppercase;
  border: 1px solid #91cfca;
  opacity: 0.8;
}
a:hover,
a:active {
  background-color: #98c8d7;
}
#content {
  background: #b4cdd9;
  color: #000;
  padding: 1em 1em 1em 1em;
  top right bottom left
}
#tekst {
  background: #98c8d7;
  color: #000;
  opacity: 0.8;
  margin: 5px 0 5px 0;
  padding: 0.5em 1em 1em 1em;
  text-align: left;
}
#sidebar {
  background: #b4cdd9;
  color: #000;
  width: 320px;
  position: relative;
  float: right;
  margin: 5px 0 5px 0;
  padding: 0.5em 1em 1em 1em;
  text-align: left;
  border-style: outset;
  border-width: 3px;
  border-color: black;
}
a {
  color: #0060B6;
  text-decoration: none;
}
a:hover {
  color: #00A0C6;
  text-decoration: none;
  cursor: pointer;
}
<body>
  <!-- This div contains your content, which is your main text -->
  <div id="content">
    <!--Header. Contains banner-->
    <div id="header"></div>
    <!-- Menu -->
    <ul>
      <li><a href="home.html">Home</a>
      </li>
      <li><a href="price.html">Price</a>
      </li>
      <li><a href="contact.html">Contact</a>
      </li>
    </ul>
    <!-- Your main text goes here-->
    <div id="tekst">
      <div id="sidebar">
        <!-- move it here -->

        <h3>Leon Laksø</h3>

        <p>Years in service, certified blah blah, all sorts of other stuff here. Maybe a picture where you look friendly?</p>
        <p>Mail link could be here?</p>
      </div>
      <h1>Heading 1</h1>

      <p>Here you can write about what you offer, why, how, to whom, and other information</p>
      <!-- Heading two. There are several types of headings. H1 denotes a certain type, H2 a smaller type etc. You can use H1 multiple times -->

      <h2>Subheading 1</h2>

      <p>Here you can maybe write a bit about yourself and your qualifications?</p>

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

Answer №2

Switching the order of your #tekskt and #sidebar is the key adjustment to make here. I've also added some margin for better visual appeal.

Check out the Live Demo to see it in action! :)

This will result in the following appearance:

body {
  background: #98c8d7;
  width: 1000px;
  margin: auto;
  font-family: "Trebuchet ms", Verdana, sans-serif;
}
#header {
  background: #fff url(banner.jpg) no-repeat;
  margin: 10px 0 10px 0;
  padding: 8em 2em 1em 2em;
  text-align: center;
  border-radius: 15px;
  opacity: 0.8;
  border: 1px dotted #000
}
/*This formats the menu*/

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
li {
  float: left;
}
a:link,
a:visited {
  display: block;
  width: 312.5px;
  font-weight: bold;
  color: #000;
  background-color: #51a7c2;
  text-align: center;
  padding: 4px;
  text-decoration: none;
  text-transform: uppercase;
  border: 1px solid #91cfca;
  opacity: 0.8;
}
a:hover,
a:active {
  background-color: #98c8d7;
}
#content {
  background: #b4cdd9;
  color: #000;
  padding: 1em 1em 1em 1em;
  position: absolute;
}
#tekst {
  background: #98c8d7;
  color: #000;
  opacity: 0.8;
  margin: 5px 0 5px 0;
  padding: 0.5em 1em 1em 1em;
  text-align: left;
  position: relative;
}
#sidebar {
  background: #b4cdd9;
  color: #000;
  width: 320px;
  position: relative;
  float: right;
  z-index: 5;
  margin: 5px 0 5px 0;
  padding: 0.5em 1em 1em 1em;
  text-align: left;
  border-style: outset;
  border-width: 3px;
  border-color: black;
  margin: 1em;
}
a {
  color: #0060B6;
  text-decoration: none;
}
a:hover {
  color: #00A0C6;
  text-decoration: none;
  cursor: pointer;
}
<!-- This div contains your content, which is your body text -->
<div id="content">
  <!--Header. Contains banner-->
  <div id="header"></div>
  <!-- Menu -->
  <ul>
    <li><a href="home.html">Home</a>

    </li>
    <li><a href="prices.html">Prices</a>

    </li>
    <li><a href="contact.html">Contact</a>

    </li>
  </ul>
  <!-- Here comes your body text -->
  <div id="sidebar">

    <h3>Your Name Here</h3>

    <p>Number of years in service, certified bla bla, more info goes here. Maybe include a friendly picture?</p>
    <p>Could put an email link here as well.</p>
  </div>
  <div id="tekst">

    <h1>Headline 1</h1>

    <p>Write about what you offer, why, how, for whom, and other information here.</p>
    <!-- Sub heading. There are different types of headings. H1 denotes one type, H2 another smaller type, etc. You can use H1 multiple times if needed.-->

    <h2>Subheading 1</h2>

    <p>You could write a bit about yourself and your qualifications here.</p>
  </div>
</div>

Answer №3

Which web browser do you currently use? The website works smoothly for me on Firefox 33 and Chrome 38.

Check out this JSFiddle link

If you're experiencing issues, try clearing your float.

#tekst {
    background:#98c8d7;
    color:#000;
    opacity: 0.8;
    margin:5px 0 5px 0;
    padding:0.5em 1em 1em 1em;
    text-align:left;
    overflow: hidden; //*clears float*//
}

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

What is the best way to place a dropdown menu in front of buttons?

Here is an example snippet of HTML code that showcases a SweetAlert2 date picker popup for a button titled "Click me!": <!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf ...

Tips for shuffling the sequence of EJS variables

I am currently working on creating a quiz that consists of multiple choice questions. In order to display the Question, Correct Answer, and 3 other wrong options, I am utilizing EJS variables. The format will be similar to the following example: Question: ...

Angular Material Password Confirmation

Currently, I am working on implementing user authentication using Angular Material. Specifically, I am focusing on displaying the appropriate error message when the confirmed password does not match the initially entered password. Below is the snippet of ...

Contrast the text within two div elements using jQuery and modify the color of any identical words

i have a pair of div's with sentences inside first div: i keep an expensive pen in my pocket. second div i own an expensive watch. given the above two divs, I aim to compare the sentences and identify the common words present in both. ...

Angular 2 Typeface Delivery to the Server

I'm experiencing an issue with the font when trying to access it from the server. It works fine on localhost, but on the server with a different directory structure, it fails to load properly. The same problem occurs with the logo as well. @font-face ...

Troubleshooting problem with the responsive dropdown menu in Bootstrap for mobile

I'm in need of some assistance with the mobile menu on my website. Whenever the STORE menu is clicked on the mobile version, it doesn't expand as expected, instead, it closes the general menu. Here is the link to the webpage. Any help would be gr ...

Arranging Bootstrap 4 columns in a vertical stack

My HTML code is as follows: <html> <head> <title>Title</title> <meta charset="utf-8"> <meta name="description" content="description"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <li ...

Creating a Duplicate of an iframe with jQuery

Hey there, I have a dilemma with two divs. One is for displaying content, and the other is a video player that I want to pause and resume on scroll using jQuery. My goal is to pause the video in the "myplayer" div on scroll and have it resume playing from ...

"Printed documents fail to display underlined text using Bootstrap styling

Why do the codes show underlines on the webpage but not in the browser's print? This code is from the printOrder.blade.php file: <!DOCTYPE html> <html dir="ltr" lang="en"> <head> <meta charset="UTF-8&qu ...

Troubleshooting Display Issue with Nested Div Selection in jQuery Tooltips

I have a long list of data consisting of 30-50 rows, each row needing its own distinct tooltip. Creating unique IDs for each row would require unnecessary JavaScript code. My goal is to utilize jQuery to retrieve the tooltip from the nested <DIV> wit ...

Having Trouble with Cascading Style Sheets (CSS) for Docked Menu

Click here for the code snippet It seems like everything should be functioning correctly... right? The CSS provided in the sample is pretty straightforward: command,a {float:left;border:1px solid blue;} And the HTML code is just as simple: <menu> ...

When applying the `display:block` and `width:100%` attributes to an HTML table cell, it may

My issue lies in the usage of DISPLAY:BLOCK for the td cells with a class of column. Despite applying it appropriately, the logo and CALL US td cells do not stack vertically when resized to mobile size. While they are supposed to take up 100% width, they ...

Sass can be used to create custom color classes for Bootstrap 5.3 that offer

I am currently using a Bootstrap 5.3 theme and I would like to give users the option to change the main color theme from the default blue to something like purple or orange. My idea is to create additional CSS files named "orange-as-primary.css", "purple- ...

Using Angular expressions, you can dynamically add strings to HTML based on conditions

I currently have the following piece of code: <div>{{animalType}}</div> This outputs dog. Is there a way to conditionally add an 's' if the value of animalType is anything other than dog? I attempted the following, but it did not ...

What could be causing my THREE.js Documentation Box to malfunction?

I am a newcomer trying to get the hang of THREE.js. I delved into the THREE.js Documentation and attempted to implement the code, but when I loaded my HTML page, it appeared blank. I am at a loss for what to do next. I utilized Visual Studio Code for codin ...

Increase the identifier of my input text when a table row is duplicated through Javascript

I have a table with only one row that contains various elements like textboxes and buttons. I want to clone the table row using the append() function when a button is clicked. However, I am facing an issue - how can I increment the id of the textboxes and ...

Is there a service in widget form that can convert HTML (URL) to PDF?

We are looking for a way to streamline the process of installing a .Net PDF creator on our server. Is there an application that can be integrated into a website and enables users to generate a PDF from a given URL or any other URL? We are open to both free ...

Sending JavaScript variables to an external CSS file

I've been searching for a solution without much luck. I must admit, my CSS skills are pretty basic. Currently, I am using Muxy.io to manage notifications for my livestreams. The platform allows customization of notifications through HTML and CSS file ...

Reset the child JSP page to its original appearance

Displayed below is a JSP page: <div id="tabs-7" style="width: 100%;"> <form:form id="deviceForm" name="" modelAttribute="" enctype="multipart/form-data"> <div class="inputWidgetContainer"> <div class="inputWidget"> <table> ...

Minimize ring size through mesmerizing smoke effects

I came across this stunning ring with a captivating smoke animation, but I am struggling to comprehend its design fully. My goal is to resize the ring to about 80px and maintain only a single color throughout. However, my attempts to simply reduce the siz ...