Need help managing floats with the: after pseudo selector?

Struggling with floats and needing to utilize the :after technique, but it's not cooperating. The floats after the red and blue box need to be cleared. Despite trying everything, the issue persists. Here is the provided code:

<!doctype html>
<html>
<head>
  <title>Floats!</title>

  <style type="text/css">
    /* CSS Reset Styles */
    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}

    /* Apply box layout to all elements */


    *, *:before, *:after {
      -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
    }

@media only screen and (min-width: 768px){
    html, body {
        margin-top: 15%;
      background: #000000;
    }

    .wrapper {
      width: 90%;
      margin: 0 auto;
      padding: 1em;
      background: #3e3d3b;
      color: #fff;
    }

    .box {
      border-width: 4px;
      border-style: solid;
      height: 100px;
      margin-bottom: 1em;
    }

    .red {
      background: #ab331c;
      border-color: #6f2011;
      width: 32%;
      float: right;
      margin-right: 34%;

    }

    .box red:after{
      content: "."; 
      visibility: hidden; 
      display: block; 
      height: 0; 
      clear: both;
    }

    .blue {
      background: #4d6bb6;
      border-color: #243255;
      width: 66%;
    }

    .green {
      background: #6bbf85;
      border-color: #2c4e36;
      width: 32%;
      margin-left: 34%;
    }

    .purple {
      background: #9a74bb;
      border-color: #503d62;
      width: 32%;
      float:right;
      margin-top: -18%;
    }

    .orange {
      background: #c09344;
      border-color: #664e23;
      width: 32%;
      float:left;

    }

    .yellow {
      background: #f0e192;
      border-color: #726a44;
      height: 212px;
      float: right;
      width: 32%;
      margin-top: -17.5%;
    }

    .hotpink {
      background: #d15ecf;
      border-color: #612b60;
      width: 32%;
      float:left;

    }
}



  </style>
</head>
<body>

<div class="wrapper">
  <div class="box hotpink" id="red"></div>
  <div class="box red"></div>

  <!-- <div style="clear: both;"></div> -->

  <div class="box yellow"></div>
  <div class="box blue"></div>

  <!-- <div style="clear: both;"></div> -->

  <div class="box orange"></div> 
  <div class="box green"></div>
  <div class="box purple"></div>
</div>

</body>
</html>

The divs with "clear" works for me, but the :after pseudo selector does not. I don't know if I'm targeting the wrong element or what. So far I've tried (for the red box):

.box.red:after
.box:after
.red:after
.box .red:after
.box red:after

So far nothing has worked. Please help.

EDIT: Link to the http://jsfiddle.net/vQRRU/

Answer №1

It's important to fine-tune the widths and margins, but simply incorporating the CSS property clear: both; to the .blue class will do the trick. If the task involves utilizing :after and :before, I may need to reassess after I enjoy my burrito.

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

Modify the placeholder color for a disabled Input element to match the overall Mui theme design

I am struggling to change the color of the placeholder text in a disabled input field within my app's theme. Despite attempting to target the MuiFormControl, MuiInputBase, and MuiInput components in my theme.tsx file on CodeSandbox, I have not been su ...

IE 9 isn't displaying the Dropdown CSS Navigation

Welcome to my test page. Click here to view the test page. I recently found out that this page is not displaying correctly on Internet Explorer 9. Since I don't have IE 9, I'm using Net Renderer to preview my test page. Below you will find my ...

Is there a way to center the text vertically within an anchor tag?

How do I align text vertically within an anchor tag? Here's a visual representation of the issue: The text "Publisher Search," "Add a New Publisher," and "Edit a Publisher" should be aligned vertically in the "bar." This is the coding structure: & ...

Is there a way to use a media query on a div element to check for the presence of a scroll bar?

A div has been styled with overflow-y: auto, triggering the appearance of a vertical scroll bar when the content exceeds the height of the div. This causes the content to shift horizontally to accommodate the scroll bar, resulting in misalignment with the ...

Insert information into the <div> element

Sorry if this is a repeated question, but I'm struggling to locate the solution. Is there a way to use jQuery to add content within a div, depending on its current class? For instance, adding "CODE" to a div such as: <div "CODE" class="class_one" ...

Showing off the latest products at the top of the list

Typically, when utilizing ngFor, the most recent item is displayed underneath the initial element. For instance, a list containing: [Apple, Orange, Banana] If we use ngFor to display this list: Apple Orange Banana I am interested in learning a method t ...

Role in HTML/CSS

I'm currently facing an issue with getting my footer to stick to the bottom of the page. In Internet Explorer, it appears centered under the rest of the content instead of at the very bottom. When I try to view it in Chrome, it ends up positioned next ...

Performing a simulated click on a dynamically inserted element using pure JavaScript

I am faced with the challenge of programmatically navigating a ReactJS-based website in a looped workflow. The process involves clicking on Element1, dynamically altering the web page to add Element2, then clicking on Element2, and so on until eventually r ...

Would adjusting the font sizes of headings be crossing into grey or black hat SEO territory?

Here's the scenario: In this case, the page title is designated as H3, the article title is labeled as H2, and a certain keyword or important sentence is identified as H1 within the content. These elements have custom CSS classes applied to them, cau ...

Troubleshooting JavaScript's onchange Function Dysfunction

Here is the code snippet I am working with: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <script src="jquery-2.2.1.min.js"></script> <script src="slike.js"></script> ...

Using jquery to remove textbox value when checkbox is unchecked

I have a single datatable created using jQuery. The first column of the table consists of checkboxes, and the last column contains textboxes. Because these elements are generated dynamically, they end up having identical IDs and names as shown below: $ ...

Tips for achieving vertically centralized components with uniform height columns in Bootstrap 4

I tried implementing the solution provided in this question: Bootstrap 4 vertical center - equal height cards However, I am still facing an issue. Despite applying the suggested code: <div class="cycle-des h-100 justify-content-center">Product Cycl ...

Spontaneous Lettering using HTML Tags

Have you ever tried using a random letter as an HTML tag? I was experimenting with it and found that even though 'f' isn't a standard tag, it functions similarly to a span tag in some cases. I know this may be a silly question, but I've ...

Converting HTML content into Java objects

I have a log of messages from a messaging platform saved in HTML format. Each message is displayed as follows: <div class="message"> <div class="message_header"> <span class="user">User Name</span> <span class="meta"&g ...

I am attempting to trigger a mouseup event following a mousedown action

elements[0].onmousedown = function(){ console.log('screen clicked.'); triggerMouseUp(); }; I just need to incorporate a function in my code that simulates mouseup event, even when the user is still holding down the click button. e ...

What is the process of uploading a video and showcasing it on an HTML page?

I have successfully uploaded images and displayed them on an HTML page. Now, I am looking to do the same for videos. Here is my current code: $('#addPhotosBtn').click(function() { $(this).parents().find('#addPhotosInput').click(); }) ...

Bootstrap - Border padding excessively wide

For a project exercise using bootstrap, I'm working on recreating a page that can be found here: https://codepen.io/freeCodeCamp/full/NNvBQW I've hit a roadblock in trying to put a border around the image. Here's the code I have so far: htt ...

How can I dynamically assign a class to an HTML element in Codeigniter?

In my CodeIgniter application, I am utilizing a Bootstrap template that includes a menu as a separate file. This menu is called on all pages and when a menu item has the class="active", it is highlighted to show users their current location. My question is ...

Creating a Dynamic Canvas Rendered to Fit Image Dimensions

I'm struggling with a piece of code that creates an SVG and then displays it on a canvas. Here is the Jsbin Link for reference: https://jsbin.com/lehajubihu/1/edit?html,output <!DOCTYPE html> <html> <head> <meta charset=&qu ...

How to center the navigation text on a WordPress website within the header.php file

Check out my website at I'm looking to center the navigation menu under the image. I've attempted multiple methods but can't seem to figure it out. Here's a snippet from the header.php file: <center><img src="http ...