How to keep a div stationary at the top using CSS

Here is the issue at hand:

`http://jsfiddle.net/5gju85un/3/`

I am trying to prevent div #3 from moving higher while keeping it floated left. Any suggestions on how I can achieve this?

UPDATE

The divs are generated dynamically in my original code through a loop, so creating two parent divs is not an option.

UPDATE

Below is the entire code snippet (I am creating a custom template for use in WordPress)

HTML/PHP

if ( $loop->have_posts() ) {
        while ( $loop->have_posts() ) : $loop->the_post()?>
                        <div class="produkt ramka">
                            <div class="produkt_obraz">
                                <?php woocommerce_show_product_images();?>
                            </div>
                            <div class="produkt_nazwa">
                                <h3 class="produkt_litery"><?php woocommerce_template_single_title();?></h3>
                            </div>
                            <div class="produkt_cena">
                                <?php woocommerce_template_single_price();?>
                            </div>
                            <div class="produkt_line">
                            </div>
                            <div class="produkt_opis">
                                <?php the_content();?>
                            </div>
                            <div class="produkt_koszyk">
                                <?php woocommerce_template_loop_add_to_cart()?>
                            </div>
                        </div>    

        <?php endwhile;
    }

CSS

.produkt
{
    display: inline-block;
    height:auto;
    min-height:120px;
    width:49.50%;
    margin-bottom:5px;
    background-color:#252525;
    overflow:hidden;
}
.produkt:nth-child(2n+1)
{
    float:left;
}
.produkt:nth-child(2n)
{
    float:right;
}

The code in the provided jsfiddle is based on the CSS shown above

Answer №1

see demo here

<div class="container first">box1</div>
<div class="container second">box2</div>
<div style="clear:both"></div>
<div class="container third">box3</div>
<div class="container fourth">box4</div>
<div class="container fifth">box5</div>
<div class="container sixth">box6</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

Stylish UTF-8 text in Internet Explorer

I've been encountering a persistent issue that I can't seem to resolve - in Internet Explorer, UTF-8 characters appear bold. Take a look at this code snippet: .section.about-houses .tabs-block .tab-content p { margin: 0 0 30px 0; line-hei ...

Using XSLT with JavaScript

I am currently working with a set of XML files that are linked to XSLT files for rendering as HTML on a web browser. Some of these XML files contain links that would typically trigger an AJAX call to fetch HTML and insert it into a specific DIV element on ...

What are some ways to ensure that text can adapt to the size of a

I am looking to create dynamic text that adjusts based on the size of its parent container. As the parent container's size changes, I want the text to automatically adjust accordingly. Specifically, I want the text in a widget to resize when the widg ...

Caution: session_start(): Unable to initialize session cookie - headers have already been sent by (output initiated at

A warning message is displayed on the login page: "It's working in localhost but not in remote host" Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at on line 8) Warning: sess ...

Populating radio buttons from a MySQL database

I've been trying to implement this code snippet from w3school.com, but I'm struggling to figure out how to dynamically set the buttons using PHP based on the Boolean value stored in a MySQL column. <form> Which color do you prefer?<br& ...

Flexbox functionality with a specific focus on Kindle Fire device compatibility

I'm curious about the support for flexbox on Kindle devices and looking for more information on overall support. It seems that some properties like display:flex and flex-wrap:wrap/nowrap are not supported, at least on older Kindle Fire devices (newer ...

Parse and style particular text within a DIV element

A unique text inside a div: Welcome to the world of coding. This is where creativity meets logic. Lines of code come together beautifully. Creating amazing projects is our goal. Mission: I aim to develop a script that will: Turn all instances of " ...

Tips for aligning text to the right and keeping it in line with another section

I have a code snippet and I'm aiming to align the caption for my "DigDug" game directly below the game itself, perfectly lined up horizontally. The id for the caption is "#DigCaption" and the id for the game is "#DigDug". Could anyone provide guidance ...

JavaScript programming does not rely on using the onclick method to style HTML elements

For a recent project, I was tasked with creating a toggle-style button setup for the challenge on CodePen. To achieve a 3D appearance for the button, I wrote some JavaScript code that utilized the onclick event. var on = true const green = document.getElem ...

The property cannot be set for an undefined element in Jquery UI slider tabs

There seems to be some extra space at the bottom of the slider tabs between the navigators and content. Additionally, I am facing a challenge in making the page responsive as the content size does not adjust when I resize the window. To see the changes, I ...

Angular is having trouble with the toggle menu button in the Bootstrap template

I recently integrated this template into my Angular project, which you can view at [. I copied the entire template code into my home.component.html file; everything seems to be working fine as the CSS is loading correctly and the layout matches the origina ...

Target the last element of a specified type in CSS without selecting any of its sub

I have a main element with nested children, some of which share a common CSS class. My goal is to select the last child of the main element without selecting the last sub-child as well. I have attempted two methods so far: Using :last-child .some-cl ...

Enforce a restriction on the user's input value for the amount field within a React application

I'm looking to limit the user from entering more than 50000 in the input value. How can I achieve this using React? I am currently handling this on the onchange event. onPaymentAmountChanged = (e) => { let inputValue = e.target.value; if (i ...

Displaying a DIV inside an embedded DIV when selecting an option in HTML by utilizing JavaScript

My goal is to create a page where users initiate a questionnaire by clicking START in a web form - this action will open the DIV for the first question. As users answer each question (with yes/no choices), it will either display a specific DIV related to ...

Removing or hiding elements using jQuery

My HTML code includes a select tag, and when the value changes, I want to retrieve data from the database based on this new value. The data is then displayed in a new div. This new div contains a close sign that should hide the div when clicked by the user ...

PHP code snippets do not interfere with one another's styles

header.php: <div class="purple-box"> <!-- Header content --> </div> <style> .purple-box { /* Styles for purple box in the header */ } </style> footer.php: <div class="purple-box"> <!-- Foo ...

How can I load a specific div region using ajax for submitting a form?

I'm not sure if my approach is correct. On my main page, I have some information displayed. When you click a button, the form will load from a separate file: $('#viewport').load('/views/myView.php #targetDiv') This works fine ...

What are the implications of storing data on the browser in the form of a JavaScript array?

Below is the code I have written: var back_arr = [], forward_arr = [], i = 1; $('button').on('click', function(){ var new_value = $('input').val(), old_value = $('.content').html(); i = i + 1; ...

What further steps are necessary beyond simply linking the Bootstrap css and js files in order to fully utilize Bootstrap classes?

While generating dynamic HTML, I've referenced bootstrap CSS and JS along with jQuery to apply a bootstrap class to an h1 element. However, the appearance of the h1 text remains unchanged. The key part of the HTML is being generated by the following c ...

Using jQuery, we can replace all `<span>` elements with `<img>` elements and then verify if the images have been successfully loaded

Similar Inquiry: jQuery check if image is loaded I find myself in a scenario where the following HTML structure is utilized: <div class="image"> <img class="" src="content-images/1.jpg"> <span class="slide" rel="content-images/ ...