When a div is floated to the right, it can lead to unexpected outcomes

Here is the code structure in the JSfiddle link below. When I apply float:right to the "Add" text, it creates extra space above the "Quick Links" & "Top 20 Sites" sections.

#home-content {
padding: 5px;
}

#home-content .css-table #row1-col3 .col-body {
padding: 5px 5px;
    /* border: 1px solid #000; */
}

/* Home page Quick Links column */
#home-content .css-table #row1-col1 .col-body > div {
    max-height: 232px;
    overflow: auto;
}

/* Home page MyShortcuts column */
#home-content .css-table #row1-col3 .col-body > div {
    max-height: 215px;
    overflow: auto;
}

.css-table {
display: table;
border-spacing: 9px 5px;
margin-left: auto;
margin-right: auto;
width: 980px;
}

.css-table #row1-col1 {
display: table-cell;
width: 170px;
border: 1px solid #cccccc;
background-color: White;
}

.css-table #row1-col2 {
display: table-cell;
width: 540px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row1-col3 {
display: table-cell;
width: 255px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2 {
display: table-cell;
width: 906px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2-col1 {
display: table-cell;
width: 490px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2-col2 {
display: table-cell;
width: 490px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.col-header {
border-bottom: 1px dotted #cccccc;
position: relative;
height: 24px;
padding: 7px 7px 1px 7px;
font-family: verdana;
font-size: 13px;
background-color:#cccccc;
}

.col-body {
padding: 0px 0px 0px 0px;
border-spacing: 1px 1px;
  font-family: verdana;
font-size:12px;
}

.col-newsfeeds {
padding: 5px 5px 5px 5px;
border-spacing: 1px 1px;
}
<div id="home-content">
  <div class="css-table">
  <div id="row1-col1">
  <div class="col-header">
  Quick Links
</div>
<div class="col-body">
        Test 1
</div>
</div>
<div id="row1-col2">
  <div class="col-header">
Top 20 Sites
</div>
<div class="col-body">
        Test 2
</div>
</div>
<div id="row1-col3">
  <div class="col-header">
  <div style="float:left;">My Shortcuts</div>
<div style="float:right;">Add</div>
</div>
<div class="col-body">
  Item 1<br/>
  Item 2<br/>
  Item 3<br/>
  Item 4<br/>
  Item 5<br/>
  Item 6<br/>
  Item 7<br/>
  Item 8<br/>
  Item 9<br/>
  Item 10<br/>        
</div>
</div>
</div>
<div class="css-table">
<div id="row2-col1">
<div class="col-header">
In the News
</div>
<div class="col-body">
  Test 3
      </div>
</div>
<div id="row2-col2">
<div class="col-header">
Announcements
</div>
<div class="col-body">
    Test 4
</div>
</div>
</div>
</div>

Is there a way to position the "Add" text to the right of the "My Shortcuts" text without impacting the layout of the other sections?

Thank you.

Answer №1

Change the "My Shortcuts" header to display as inline-block instead of using float left

#home-content {
padding: 5px;
}

#home-content .css-table #row1-col3 .col-body {
padding: 5px 5px;
    /* border: 1px solid #000; */
}

/* Home page Quick Links column */
#home-content .css-table #row1-col1 .col-body > div {
    max-height: 232px;
    overflow: auto;
}

/* Home page MyShortcuts column */
#home-content .css-table #row1-col3 .col-body > div {
    max-height: 215px;
    overflow: auto;
}

.css-table {
display: table;
border-spacing: 9px 5px;
margin-left: auto;
margin-right: auto;
width: 980px;
}

.css-table #row1-col1 {
display: table-cell;
width: 170px;
border: 1px solid #cccccc;
background-color: White;
}

.css-table #row1-col2 {
display: table-cell;
width: 540px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row1-col3 {
display: table-cell;
width: 255px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2 {
display: table-cell;
width: 906px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2-col1 {
display: table-cell;
width: 490px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.css-table #row2-col2 {
display: table-cell;
width: 490px;
border: 1px solid #cccccc;
padding: 0;
background-color: White;
}

.col-header {
border-bottom: 1px dotted #cccccc;
position: relative;
height: 24px;
padding: 7px 7px 1px 7px;
font-family: verdana;
font-size: 13px;
background-color:#cccccc;
}

.col-body {
padding: 0px 0px 0px 0px;
border-spacing: 1px 1px;
  font-family: verdana;
font-size:12px;
}

.col-newsfeeds {
padding: 5px 5px 5px 5px;
border-spacing: 1px 1px;
}
<div id="home-content">
  <div class="css-table">
  <div id="row1-col1">
  <div class="col-header">
  Quick Links
</div>
<div class="col-body">
        Test 1
</div>
</div>
<div id="row1-col2">
  <div class="col-header">
Top 20 Sites
</div>
<div class="col-body">
        Test 2
</div>
</div>
<div id="row1-col3">
  <div class="col-header">
  <div style="display:inline-block">My Shortcuts</div>
<div style="float:right;">Add</div>
</div>
<div class="col-body">
  Item 1<br/>
  Item 2<br/>
  Item 3<br/>
  Item 4<br/>
  Item 5<br/>
  Item 6<br/>
  Item 7<br/>
  Item 8<br/>
  Item 9<br/>
  Item 10<br/>        
</div>
</div>
</div>
<div class="css-table">
<div id="row2-col1">
<div class="col-header">
In the News
</div>
<div class="col-body">
  Test 3
      </div>
</div>
<div id="row2-col2">
<div class="col-header">
Announcements
</div>
<div class="col-body">
    Test 4
</div>
</div>
</div>
</div>

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

Ways to rearrange targeted td elements within a table

My current table structure looks like the one shown in this https://i.sstatic.net/NCFH4.png image, but I need to change it to match the structure in this https://i.sstatic.net/7FYXI.png image. I've been searching on SO and other platforms for a solut ...

Tips for achieving seamless expansion and eliminating grid row gaps by utilizing hidden elements in CSS

I'm currently developing a web design that includes a section with both visible and hidden content. I've added a button to smoothly reveal the hidden content using a transition effect. However, I'm encountering a couple of challenges: Even ...

How to use Python and JavaScript to make a WebElement visible in Selenium

I am currently facing an issue with uploading a PNG file using Selenium. The input element necessary for the upload process is visible to the user but not to Selenium. Following the suggestions in the Selenium FAQ, I tried using JavaScriptExecutor as shown ...

loading dynamic content into an appended div in HTML using Angular

Here is the HTML code from my app.component.html file: <button mat-raised-button color="primary" mat-button class="nextButton" (click)="calculatePremium()"> Calculate </button> <div id="calcul ...

Siblings selectors within Internet Explorer slow down significantly when using the :hover pseudo-class

Sample page: http://jsfiddle.net/y2pwqch6/6/ This particular example showcases a CSS selector known as the adjacent sibling selector: .l:hover + .r { color: blue } The issue arises when hovering over any element on the page, causing Internet Explore ...

Show an image in JPEG format using JavaScript within an img tag

Suppose http://example.com/image returns unique image data in response headers and the image itself. Each request to http://example.com/image generates a different image that is not related to the request itself. Besides the image, additional information s ...

Utilizing a lone div for clearing a float

For a long time, my go-to method for clearing floats has been using <div style="clear:both;"></div>. However, I recently began wondering if in HTML as XML, could I simply use <div style="clear:both;" /> since they essentially serve the sa ...

Disappearing event listener issue triggered by arrow button click

As I work on customizing a WordPress plugin called Spider Calendar, I've encountered an issue where the event listener disappears from the inspector's "event listeners" tab after clicking on certain elements like "2016", "2018", or the arrows. De ...

Tips for aligning text to the left within a Bootstrap accordion

I am in the process of developing a static website utilizing the W3schools "Company" theme. The complete code for this website, including CSS, is provided below: <!DOCTYPE html> <html lang="en"> <head> <!-- Theme Made By www.w3schoo ...

Parsing HTML using PHP's Simple HTML DOM Parser

I'm having trouble extracting specific information from HTML code using a DOM parser. <div id="posts"> <div class="post"> <div class="user">me:</div> <div class="post">I am an apple</div> &l ...

How can I ensure my game or website fits perfectly on the screen without any need

I have recently developed a fun Erase-A-Man game that is optimized for mobile devices. However, I am facing an issue where users need to scroll to view all the letters on their screens. My goal is to make the game fit perfectly on all phone screen sizes so ...

How can I adjust the number of columns displayed per page on a Bootstrap Studio website?

Currently, I am utilizing Bootstrap studio to design a website featuring multiple cards on each page. Initially, I incorporated cards from the sb-admin-2 template and everything was proceeding smoothly. In my bootstrap studio interface, the three-column ca ...

What are some methods for creating a Venn Diagram that includes data within each section using SVG, CSS, or Canvas?

I am attempting to replicate this visual representation using pure SVG, CSS, or Canvas drawing. So far, I have successfully created three circles that overlap and placed a label in the center of each one. However, I'm facing challenges when it comes t ...

Step-by-step guide on applying a universal CSS class to every component within an application

I am in the process of building a multilingual react application and I am looking for a solution to dynamically apply certain CSS styles to most components based on the chosen language. I am seeking something akin to direction-rtl and direction-ltr, whic ...

Create a PDF on-the-fly by leveraging Vuejs to dynamically pull data and design elements

Is it possible to create a form that captures name, expiry date, and picture, and upon submission generates a PDF document with the provided details? The PDF should be based on a design created by me and have the input data displayed in a specific location ...

Issues persisting with the fixed header functionality in Bootstrap table

I implemented a table using bootstrap-table in my project. Everything seems to be working fine except for the scroll bar within the tbody. For some reason, the scroll bar is not appearing. Can anyone point out what I might be missing? I believe that if th ...

How come jQuery is retaining the original DOM element classes even after I have modified them using jQuery?

Here is the code snippet I am working on: $(".drop-down-arrow-open i").click(function(){ console.log("The click function for .drop-down-arrow-open is triggered even when it is closed"); let thisParent = $(this).closest(".projects-container").find(".need ...

Switch back JSON in php script

After receiving a JSON object with an unspecified number of key/value pairs, I need to send it from my $.ajax function to a PHP script. The PHP script must then revert the JSON object and send it back to jQuery. {"First name": "John", "Contact": "2323",.. ...

Trouble with CSS Class Showing Up Only When Hovered

My goal is to make the .panel-text element visible only when a user hovers over the panel. I attempted to use the overlay CSS class, but I encountered issues where the text either wouldn't show at all or would always be displayed. Here is what I have ...

Deselect the checkbox if you are checking a different checkbox

Struggling with my code, it's hit or miss. Feeling defeated. Seeking assistance to uncheck a checkbox when another checkbox is checked. Check out the code below: JavaScript: $("#1 #checkAll").change(function() { if ($("#1 #checkAll").is(' ...