HTML element that does not contain any image attributes

Currently facing two issues, with the second one dependent on the resolution of the first. Everything was functioning correctly and looking fine until I came in to work on it today, only to find that the page is now broken. Interestingly enough, I am using the same browser at both locations.

The main problem seems to be related to the background of a specific div not extending to the bottom as expected, unlike the other divs on the page which are set to auto height. Here's an image for reference: https://i.sstatic.net/Y3iXu.png

<div class="items">
        <h2><a name="friday"><a href="#">Friday catch of the day:</a></a></h2> 

        <img src="images/catch.png" align="right" alt="Sage-rubbed Double-cut Pork Chop" />

        <p><span class="title">Alaskan Halibut with a Rich Loire Valley Beurre Blanc Sauce</span> - served with mashed purple Peruvian potatoes and haricot verts.</p>

        <p><span class="title">Recommended pairing:</span> '98 Passi Emilio Vineyards Sauvignon Blanc</p>

    </div>

CSS

.items {
        margin: 20px;
        height: auto;
        width: 910px;
        background-color: rgba(0, 0, 0, .7);
        padding: 10px;  
        z-index: 1;
    }
    .items img {
        float: left;
        margin-right: 10px;
        float: right;
        border-radius: 6px;
        width: auto;
        padding: 8px;
        background-color: #FFFFFF;
    }
    .items p {
        font-family: 'PT Sans';
        font-size: 16px;    
    }
    .items a {
        color: #FFFFFF;
        text-decoration: none;      
    }

Answer №1

.items img {
    float: left;   <---- Are you sure about floating left?
    margin-right: 10px;
    float: right;   <---- Why are you also floating right?
    border-radius: 6px;
    width: auto;
    padding: 8px;
    background-color: #FFFFFF;
}

You seem to be conflicted between floating right and left. You should choose one direction. Additionally, don't forget to clear your floats for the normal flow to resume properly.

Answer №2

To achieve a scrollable effect, insert the overflow: auto property into the items class.

.items {
    margin: 20px;
    height: auto;
    width: 910px;
    background-color: rgba(0, 0, 0, .7);
    padding: 10px;  
    z-index: 1;
    overflow: auto;
}

Answer №3

To resolve this issue, you can insert an empty div element with the style rule clear: both.

Here's how you would implement it in your HTML:

<div class="content">
    ...    
    <div class="clearfix"></div>
</div>

And here is the corresponding CSS code:

.clearfix {
    clear: both;
}

You can also view a live demo on JSFiddle.

Answer №4

Feel free to bookmark this code snippet for reference in your next project. Remember to include the .clearfix class in the parent container to properly clear any floating child elements. Happy coding!

.clearfix{*zoom:1;}
.clearfix:before,.clearfix:after{display:table;content:"";line-height:0;}
.clearfix:after{clear:both;}

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

Steps to insert a large image into a div while maintaining the size ratio

https://i.sstatic.net/WvBbF.png I'm struggling to add a logo to the right corner of this div The logo size is too big and it doesn't adjust properly to the existing div height and width Below is the code I've tried, but the image is ruini ...

Using a JavaScript script in my HTML alongside Vue.js is not possible

Hello there! I recently created a Node.js server and now I'm trying to display an HTML file that contains a Vue script which loads data using another method written in a separate JS file. However, when I attempt to load my HTML file in the browser, ...

Animating text so it moves to a random spot within a circular div

I hope everyone is doing well. For my assignment, I need to animate an image to a circular div container at a random location. Currently, I have already completed this task. You can view my work here: jsfiddle.net/f4p6b/137 However, the issue I am faci ...

Creating text input without borders using HTML and CSS

I have managed to create text inputs without borders using HTML and CSS, but I am facing an issue. Whenever I click on the input field, a yellow border appears instead of the one I removed. It seems like this is coming from the default stylesheets, and I&a ...

Engaging with JSON data inputs

Need help! I'm attempting to fetch JSON data using AJAX and load it into a select control. However, the process seems to get stuck at "Downloading the recipes....". Any insights on what might be causing this issue? (Tried a few fixes but nothing has w ...

Why isn't jQuery working properly for showing/hiding elements?

I am attempting to create a functionality where the string remove field can be toggled to show or hide using a single button, depending on its current state. Initially, it should be hidden (using the hidden HTML attribute), and upon clicking the button, it ...

Easy selector for choosing jquery css backgrounds

Here is a simple background selector that I created. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <hea ...

How can you efficiently showcase multiple fetch functions on a single page by utilizing loops in PHP?

I am attempting to showcase the countries from each continent on a single page using buttons for each continent. When a user clicks on a button, I want the countries of the selected continent to be displayed. However, I am encountering an issue where only ...

Navigate to the specified text in the dropdown menu based on the ul li selection

Is it possible to achieve a functionality similar to that of a select box, where typing a keyword that matches an option in the select box will automatically move the pointer to that option? I am looking to implement a similar feature in my HTML code: < ...

Dynamic CSS manipulation with jQuery: Generate and access styles on the fly

I am working on an application where I am utilizing jQuery along with maphilight for highlighting image map segments. In addition to this functionality, I want to dynamically highlight specific HTML elements based on mouseover/mouseout events for the image ...

Unattractive mobile modal

Hey there, This is how my .modal CSS code appears: .modal { position: fixed; top: 10%; left: 50%; z-index: 1050; width: 560px; margin-left: -280px; background-color: #fff; border: 1px solid #999; border: 1px solid rgba ...

Can anyone help with displaying a PNG image in Vue/Node/Express? I am struggling to show the image that I sent from a Node.js server to a Vue app client

In my Node/Express application, I've set up a route like this: app.get('/get-image', function(req, res) { ... res.sendFile(path.join(__dirname, '..', account.profileImg)); }) Now in my client-side Vue app, I'm tryi ...

Add bullet points to the events listed in fullcalendar

Currently, I am implementing the 'fullcalendar' plugin from jquery in order to display events for a specific month. I am interested in adding bullets to the events, however, my online search did not yield any relevant results. Although I am awar ...

The code functions correctly on JSfiddle, however it is not executing properly on my website

When I tried to implement the code from this jsfiddle link: http://jsfiddle.net/mppcb/1/ on my website (), it didn't work as expected: Here is the HTML code snippet: <form id="myform" novalidate="novalidate"> <input type="text" name="fi ...

Using the loop function within HTML in JavaScript with React

I'm trying to loop over my SliderComponent function with different inputs within the HTML to generate multiple components, but I can't seem to get it to work. I came across a solution online that involves building a string and returning it as HTM ...

execute a different function once the animation has finished running with the .bind

When attempting to detect the completion of a CSS animation in order to remove a class, I encountered an issue where using .bind causes the animation end event to trigger even for the other function. You can view the complete code here. How can I ensure ...

Executing a JavaScript function using document.write()

When I try to click on the SWF part1 links within the document.write() function in order to call the openswf function, nothing happens. Here is my code: <html> <a href="#" onclick="Popup();">show popup</a> <script> functio ...

Beneath the footer lies a blank space in white

Visit our site for information on various towns. However, we are facing an issue with the CSS when it comes to new or less populated towns like this one, where the footer is not aligning properly and leaving a large white gap below. We attempted to implem ...

What could be causing my wrapper div to not clear properly?

Something seems off with my wrapper div as it's not completely wrapping the children divs vertically. I made sure to clear both of the contained divs but it doesn't seem to be working properly. Any insight on why this might be happening? Check o ...

Tips for launching different web browsers via hyperlinks?

My app has a link that I want mobile users from apps like LinkedIn to open in a browser such as Safari. I attempted this: <a href="safari-https://meed.audiencevideo.com">May open on Safari</a>' However, when I click the link, it opens i ...