The sidebar on the right side of the screen is content to relax beneath my

The positioning of my sidebar is currently below the content on the left side of the page, but I want it to sit beside the content on the right side. I've tried various solutions from similar questions without success. Here is an example of how I would like the layout to appear: View sample format.

CSS:

#header {
background-color:#ffffff;
color:white;
text-align:center;
padding:5px;
}
#navbar {
background-color:#ffffff;
color:#000000
text-align:left;
padding:5px;
}
#section {
background-color:#ffffff;
width:500px;
float:left;
padding:10px; 
}
#sidebar {
line-height:30px;
background-color:#14004d;
height:300px;
width:200px;
float:right;
padding:5px; 
}
#footer {
background-color:#14004d;
color:#ffffff;
clear:both;
text-align:center;
padding:5px; 
}

HTML:

<body bgcolor="#ffffff">

<div id="header">
<h1><center>header image here</center></h1>

<div id="navbar">
<p style="color:#14004d">
Home&emsp;&emsp;&emsp; Services&emsp;&emsp;&emsp;     Portfolio&emsp;&emsp;&emsp; Testimonials
</p>
</div>

<div id="section">
text text text text text text text text text text text text text text text
</div>

<div id="sidebar">
<p style="color:#ffffff">
contact info will be listed here.</p>
</div>


<div id="footer">
Copyright © Cassidy v. Ros Online Marketing Solutions 
</div>

</body>

https://jsfiddle.net/3sxn3yaf/

Answer №1

It is recommended to utilize percentage widths along with the box-sizing style.

#section {
  /* ... */
  width: 70%;
  box-sizing: border-box;
  /* ... */
}
#sidebar {
  /* ... */
  width: 30%;
  box-sizing: border-box;
  /* ... */
}

#header {
  background-color: #ffffff;
  color: white;
  text-align: center;
  padding: 5px;
}
#navbar {
  background-color: #ffffff;
  color: #000000 text-align: left;
  padding: 5px;
}
#section {
  background-color: #ffffff;
  width: 70%;
  box-sizing: border-box;
  float: left;
  padding: 10px;
}
#sidebar {
  line-height: 30px;
  background-color: #14004d;
  height: 300px;
  width: 30%;
  box-sizing: border-box;
  float: right;
  padding: 5px;
}
#footer {
  background-color: #14004d;
  color: #ffffff;
  clear: both;
  text-align: center;
  padding: 5px;
}
<body bgcolor="#ffffff">

  <div id="header">
    <h1><center>header image here</center></h1>
  </div>

  <div id="navbar">
    <p style="color:#14004d">
      Home&emsp;&emsp;&emsp; Services&emsp;&emsp;&emsp; Portfolio&emsp;&emsp;&emsp; Testimonials
    </p>
  </div>

  <div id="section">
    text text text text text text text text text text text text text text text
  </div>

  <div id="sidebar">
    <p style="color:#ffffff">
      contact info will be listed here.</p>
  </div>


  <div id="footer">
    Copyright © Cassidy v. Ros Online Marketing Solutions
  </div>

</body>

Answer №2

To optimize the layout of your webpage, consider placing your sidebar block above your content block. This way, it can prioritize rendering the floating view before displaying the main content element.

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 create a slideshow using an IFrame?

Currently seeking a solution for an iframe slideshow that can smoothly transition between multiple HTML iframes. I have a total of 5 iframes that need to rotate automatically and continuously. Any suggestions on how to build a lively and dynamic iframe sl ...

What causes the cancel button to add spaces and create a line break in the textarea field?

Whenever I click the "cancel" button, the textarea inexplicably receives 26 spaces before any existing text and a carriage return after it. This issue occurs when the cancel button is styled in the traditional HTML manner: <button type="reset" name="re ...

Tips for adding text dynamically to images on a carousel

The carousel I am using is Elastislide which can be found at http://tympanus.net/Development/Elastislide/index.html. Currently, it displays results inside the carousel after a search, but I am struggling to dynamically add text in order to clarify to use ...

Disable the time selection feature in the text input field

Despite seeing the same question asked before for this issue, I am looking for a solution that does not involve replacing the textbox with the same ID. When Timepicker is selected in the dropdown menu timepicker, it should activate in the textbox (which i ...

Using HTML to load an image is not possible, as it can only be done using CSS

I am currently dealing with a CSS issue in my project. Here is the code snippet from my stylesheet: .Img{ background: url('../assets/Trump.png'); } Now, let's take a look at the corresponding HTML code: <div class="Img"> However, ...

Bootstrap CSS: arranging columns for mobile devices

UPDATE: Having implemented the solution provided in the accepted answer below, I find myself back at square one with the original layout before any adjustments were made. The issue still remains unresolved. Any advice on how to achieve the desired design o ...

JavaScript Button with the Ability to Input Text in a TextArea?

For instance, imagine a scenario where you click on a button and it then displays various options for you to select from. Whatever option you pick will be automatically inserted into the text area. ...

the pop-up modal function is malfunctioning

I can't get my pop up to work properly. When I click the button, the screen dims as if a pop up is going to appear, but nothing shows up. Can someone please assist me with this issue? Here is the HTML file: <!DOCTYPE html> <html lang="en"&g ...

Black and white emoji display on Windows 7 using Chrome and Edge browsers

To enhance the visual appeal of my website, I incorporate emojis using Emoji Unicode from https://www.w3schools.com/charsets/ref_emoji.asp. It has come to my notice that on Android, Mac, and iPhone devices, users see colored emoticons while those on Window ...

Adjust the text color when hovering with the style tag

When it comes to customizing the color of a link on hover, CSS makes it simple with code like this: .myId:hover{ color:green; } But what if you're using inline styles? Is there a way to achieve the same effect without just plain HTML and CSS? & ...

How do I convert the object value/data to lowercase in JavaScript using underscore for an HTML5 document?

I am working with an array of objects (arr) where each object consists of 3 properties (Department, Categories, ProductTypes). The values for these properties are a mix of upper and lower case. To perform a comparison between arr and a search filter (alrea ...

The background color property of the CSS class "ui-layout-north

Currently working with primefaces 4.3 and incorporating it into my main UI. My goal is to modify the background color of the north unit to red, as currently only the top 80% of the unit is affected. .ui-layout-north .ui-layout-unit-content { backgro ...

What is the most effective method for displaying two external web pages next to each other?

Looking for a solution to display an English Wikipedia article on the left side of the page alongside its Spanish version on the right side. Wondering if it's possible using HTML, JavaScript, AJAX, etc. I am aware that I could use iframes, but I woul ...

Error Message Design in ASP.NET

I am currently developing a website using .net, which is a new technology for me. Here is the snippet of code I am working with... <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="V1" Display="Dynamic" ...

Is it feasible to utilize VAST for delivering HLS streams? Can m3u8 files be incorporated into VAST tags for delivery?

We are integrating a video player that supports VAST pre-roll, mid-roll, and post-roll video ads. I'm wondering if it's feasible to include m3u8 files in VAST tags? I've reviewed the vast specification and examples, but haven't come ac ...

Forwarding the geographic coordinates directly to the system's database

I have a unique script that retrieves the precise latitude and longitude position. It then automatically sends this data to a database without the need for user input. <script> function getPosition(position) { var latitude = position.coor ...

Sending HTML content to viewChild in Angular 5

I'm struggling to figure out how to pass HTML to a ViewChild in order for it to be added to its own component's HTML. I've been searching for a solution with no luck so far. As a newcomer to Angular, many of the explanations I find online ar ...

jQuery: Revealing or concealing several divs upon selection alteration

When I populate a form, I want to display or hide multiple divs based on the OPTION selected in a DROPDOWN. Currently, my code works but the issue is that one div can be hidden or shown by multiple OPTIONS. As a result, these divs keep toggling between hi ...

Activate the Twitter Bootstrap Lightbox when the page is loaded

Is there a way to make my twitter bootstrap lightbox automatically trigger when the HTML page loads? Currently, I have this script in my 'main.js' file: function lightbox(){ $('#myLightbox').lightbox(); }; I heard that I can us ...

Is it possible for a Vue data property to have a value that is determined by another Vue data property object?

Within my HTML form, I have implemented the flatPickr (calendar picker) component which generates an input field. I am currently exploring how to dynamically change the class of the input field if the error class function returns true. Below is the flatPi ...