Having Trouble Getting a New Line with CSS - Why Won't Display: Block Work?

I'm currently facing an issue where I want a div to occupy a full line and force the next div onto a new line. This is typically achieved by using display:block in the CSS for the first div, or so I believe. However, this approach doesn't seem to be working for me. I'm not sure what I might be overlooking. To clarify, the div I want to span a full line is the flags-right div class. At the moment, it's displaying on the same line as the left-aligned photo. Below is my HTML code:

<div class="flags-right">
    <div class="red-circle"></div>
    <div class="blue-circle"></div>
    <div class="yellow-circle"></div>
</div>
<div class="photo"><img [src]="rkPhoto" alt="photo" /></div>

Here is the corresponding CSS:

.flags-right {
  float: right;
  display: block
}

.photo {
  float: left;
  height: 4.563rem;
  width: 4.688rem;
  margin-right: 0.75rem;
}

.red-circle {
  width: 20px;
  height: 20px;
  float: left;
  margin-right: 4px;
  background: #f9646a;
  -moz-border-radius: 50px;
  -webkit-border-radius: 50px;
  border-radius: 50px;
}
.blue-circle {
  width: 20px;
  height: 20px;
  float: left;
  margin-right: 4px;
  position: relative;
  background: #54a6f4;
  -moz-border-radius: 50px;
  -webkit-border-radius: 50px;
  border-radius: 50px;
}
.yellow-circle {
  width: 20px;
  height: 20px;
  float: left;
  margin-right: 4px;
  position: relative;
  background: #fcff26;
  -moz-border-radius: 50px;
  -webkit-border-radius: 50px;
  border-radius: 50px;
}

Furthermore, here's the CSS for the container element:

.col-1-4 {
  background: @containerBgColor;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  color: @flagText;
  float: left;
  padding: 10px;
  text-align: left;
  margin-bottom: 8px;
  margin-right: 8px;
  width: 24%;
}

Answer №1

Include:

clear:both;

If you are utilizing floats, setting "display:block" will not automatically position a div on a separate line (since display:block is the default for a div). The use of clear is necessary to indicate that it should begin below any preceding floats.

Answer №2

Make sure to verify that display:flex is applied to the parent ul element. If it is, set flex-direction:column for a vertical arrangement.

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

Discovering the reason behind a DOM element's visual alteration upon hovering: Where to start?

Visit this page, then click on the next button to navigate to the time slots section. As you hover over any time slot, you will notice a change in appearance. Despite inspecting Chrome's developer tools, I was unable to locate a style with a hover dec ...

Ensuring consistency in aligning float elements

I've been struggling to create a concept design for my internship project. I aim to have a page with six clickable elements (images). When one is clicked, the others should disappear and the active one moves to the top. I managed to achieve this using ...

Utilizing Radio buttons to Align Labels in Bootstrap 4

I'm experimenting with a Bootstrap 4 form and trying to get inline radio buttons with labels. It was working fine with Bootstrap 3, but I'm facing issues with Bootstrap 4 and its custom-radio styling. Desired Output: Gender : ( ) Male ( ) Female ...

What is the best way to assign the "active" class to a navigation list item using JavaScript within Bootstrap 4?

Update: just to clarify, I'm working on activating the navbar button based on the current page. I have a navigation bar set up and I am trying to dynamically add an "active" class to the li element when you are on that specific page. However, for som ...

The resize function fails to trigger when it is required

Struggling to get this code working properly. If the window width is greater than 800, I want 6 images with a red background. If the window width is less than 800, I want 4 images with a blue background. I need this functionality to work both on r ...

Validating HTML forms using Javascript without displaying innerHTML feedback

Hey, I'm just diving into web development and I'm struggling to figure out why my innerHTML content isn't displaying on the page. Can anyone offer some assistance? I'm trying to display error messages if certain fields are left empty, b ...

`Changing the iframe content dynamically with next and previous buttons: a step-by-step guide`

function displayPDF(fileSlNo){ var data = { pageMode: "PDF_DISPLAY", fileSlno: fileSlNo }; var d = $.param(data); var request = $ .ajax({ type: "GET", url:"folderNavigation.do?"+d, dataType : "TEXT", success: functio ...

Embedding HTML code in JavaScript

I am in the process of developing a karaoke-style website where I aim to incorporate HTML elements along with text. My intention is to introduce a break tag that will display certain lyrics on a separate page. You can access the codepen for this project h ...

What's the best way to center align my tag vertically in this scenario?

I am struggling to center my text vertically in this scenario. Here is the structure I have: <section id='container'> <div id='title'> <h1>Title here.</h1> </div> </section> This ...

Discovering additional element information while utilizing the 'Sortable' feature

My Current Objective: In my setup, I have a 'calendar' comprising 5 columns, each column containing 5 separate divs known as timeslots. The main purpose here is to show appointments in these specific timeslots and utilize JQuery's Sortable ...

What is causing the text below the SVG path to appear thicker?

I am encountering an interesting issue with my SVG green marker. The text inside appears bolder than the same text with the same attributes when it is standalone. https://i.sstatic.net/NYmXX.png Upon further inspection, I noticed that the text within the ...

Easily move elements using a jQuery click animation

Having trouble animating a div's top position by -130px to move it off screen? Can't figure out why it's not working? I'm fairly new to jQuery/Javascript. I have a button/hyperlink with the ID #NavShrink. When clicked, I want the div # ...

How to retrieve the time duration in minutes between a start and end time in JavaScript to

I have conducted a thorough search on Stack Overflow and other platforms but could not find an answer to my specific question. While I did come across posts related to this topic, they did not address the issue I am facing. Problem: My challenge involves ...

The location layer on my Google Maps is not appearing

For a school project, I am working on developing a mobile-first website prototype that includes Google Maps integration. I have successfully added a ground overlay using this image, but I am facing issues with enabling the "my location layer". When I tried ...

The JQuery carousel displays jittery movements

The issue arises when the carousel shifts or jumps during transitions, and I'm at a loss for what might be causing it. $(".timer").css("display"); $(".timer:gt(5)").css("display", "none"); function move_first() { //console.debug("animate"); $ ...

Unlocking two features with just a single tap

I am currently working on a website for a kiosk, where the site transitions like a photoslide between each section. To achieve this effect, I have added a layover/mask on the initial page. The layover/mask is removed using a mouse click function. This is ...

Website not displaying properly on Chrome for Mac operating system

Recently, I started using my Macbook for web development and noticed that the websites I create appear differently and glitched compared to Windows. You can see examples below. Does anyone know why this is happening and how to resolve it? View on Mac Vie ...

Transform the page into a Matrix-inspired design

I decided to transform the appearance of my web pages into a stylish The Matrix theme on Google Chrome, specifically for improved readability in night mode. To achieve this goal, I embarked on the journey of developing a custom Google Chrome extension. The ...

How can jQuery determine if multiple selectors are disabled and return true?

I am currently working on a form in which all fields are disabled except for the "textarea" field. The goal is to enable the "valid" button when the user types anything into the textarea while keeping all other inputs disabled. I initially attempted using ...

Tips for keeping your button fixed in place

I am encountering an issue where my button moves below the select dropdown list when I try to make a selection. Is there a way to keep the button in place even when the dropdown list from the select box is visible? For reference, here is the current outp ...