The div element with the id "wrapper" is not functioning properly within the box model

I have defined an ID wrapper in CSS:

#wrapper {
    position: relative;
    background: yellow;
    -webkit-box-shadow:  0px 0px 6px 0px rgba(0, 0, 0, 0.2);
    box-shadow:  0px 0px 6px 0px rgba(0, 0, 0, 0.2);
    width: 960px;
    padding: 40px 35px 35px 35px;
    margin: 0px auto;
}

And a class called box in CSS:

.box {
    float: left;
    width: 170px;
    height: 190px;
    margin: 10px;
    border: 3px solid #8AC007; 
    border-radius: 5px;
    right: auto; 

In my HTML code:

<div id="wrapper"><div class="box">
    <a href="#"><p>This is box 1</p></a>    
</div> </div>

The issue I am facing is that the box appears outside the wrapper. What could be the solution to fix this problem?

Answer №1

Get rid of the float:left property in the box css

.box {
    width: 170px;
    height: 190px;
    margin: 10px;
    border: 3px solid #8AC007;
    border-radius: 5px;
    right: auto;
}

Answer №2

You can solve the float clearance issue by adding overflow: auto to the wrapper element.

Answer №3

It's always a good idea to include a clearing element after using floats, especially for older versions of IE that tend to behave unpredictably without them.

<div id="wrapper">
    <div class="box">
        <a href="#"><p>This is box 1</p></a>    
    </div>
    <div class='clr'></div>
</div>

Here's some additional CSS code to help with clearing floats:

.clr {
    clear:both;
    height:0px;
}

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

Trigger the click event on a specific class selector to extract the corresponding ID

I have an HTML Table with each row: <table> <tr><td><a href='#' id='1' class='delete'>delete</a></td></tr> <tr><td><a href='#' id='2' class='de ...

Explore bar with search button

I'm facing an issue with the code I have for searching on my website. Currently, when a user fills in their search word and presses enter, it executes the command. However, I would like to only run the search script when the user clicks a button inste ...

Issues with clearRect() function in HTML5 canvas

Recently, I developed a function with the goal of redrawing a square line block that covers the entire page whenever the window size is adjusted. For reference, you can view my code at http://jsfiddle.net/9hVnZ/ However, I encountered an issue: bgCtx.cl ...

What is the process of transforming a String into a Function prototype in JavaScript?

Recently, I encountered a JavaScript object containing key-value pairs with functions as values: var serial = { open: function(a, b) { // do something.. }, close: function (a,b) { // do something } } Due to certain requirements, I had ...

Retrieve the values of the rows that have been selected in the Kartik GridView located within a modal, and then transfer

I am attempting to extract data from a Bootstrap modal (which contains a table of Kartik GridView) and pass the selected value to the parent form (an action create form). Can anyone provide guidance on how to achieve this? The modal form includes fields su ...

What is the reason behind the continual change in the background image on this website?

Can you explain the functionality of this background image? You can find the website here: ...

Verify the occurrence of a search result and if it appears more than once, only show it once using JavaScript

Hello all. Currently, I am developing an online users script using NodeJS and SocketIO. The functionality works fine, however, I am encountering an issue where if a user connects from multiple browsers, windows, or devices, it displays duplicate results li ...

Is it possible to slide-toggle and alter the background color of a div when clicked?

Imagine having several div's on a webpage all with the ID of "Toggle". Each div contains two other smaller divs. "Headline" which is always visible. "Comment" which appears/disappears when the headline is clicked (initially hidden). How could I ac ...

Using jQuery to Drag: Creating a draggable effect on a div element

I recently posted a question, but I feel like I need to rephrase it to make it more general. Basically, I have an element that can be moved around and resized using jQuery. I used CSS to attach another div to the right of this element. Initially, when you ...

Detect when a user's mouse is hovering over an iframe and escape the iframe accordingly

When the iframe window is visible, there are no issues. However, if the iframe window is set to 0px X 0px in order to hide it while still loading, consider redirecting the iframe or not displaying it at all. In case something is loaded within an iframe or ...

javascript: window.open()

I am currently using VB.NET 2005 and I have a requirement to launch a new browser window using Process.Start(). The challenge is that I need to specify the size of the browser window, for example, height:300 and width:500. Process.Start("firefox.exe", "ab ...

Intersecting Hyperlink Elements Creating a Hover Effect

I've encountered a perplexing CSS display issue and I'm at a loss for alternative solutions besides simply widening the width of the parent div. Allow me to explain the layout: <div> <ul> <li> <a href="javascrip ...

Child Theme setup in progress! Beware of the error message: "Unable to access file: file_get_contents9(). The specified stream does not exist."

I am currently in the process of developing a child theme based on my existing theme (Tesseract 2). I have carefully followed the guidelines outlined here, but unfortunately, I keep encountering the following error: Warning: file_get_contents(/home/fletch ...

JavaScript parameter not found

I am currently working on a block type plugin for Moodle and encountering some difficulties with my JS code. Due to my limited knowledge in JS and JSON, I am having trouble identifying the issue at hand. My code includes a function that adds a custom actio ...

Add an asterisk before each line of comment when working in a TypeScript file using the VS Code IDE

Within my VS Code workspace, I am using the Typescript language and would like to format my comments across multiple lines with a specific style (look out for the star character) /** *@desc any text * any text */ However, when I attempt to write a comm ...

What is required to create a basic application that can function offline while featuring an HTML/CSS user interface?

Newbie inquiry: I am interested in creating a small application that can run offline on a desktop computer. The amount of data to be saved is minimal, so I have the option to use a file or some type of database. However, my main question is: What languag ...

Is there a way for me to obtain the client ID and redirect URL after a user logs in to Instagram via my website?

My goal is for users to be able to easily import their images into my website. After reviewing their documentation, I found that they authenticate a user by providing a response code through the following URL: However, this URL only provides me with a co ...

Exploring the Power of Pengines in Combining Prolog with Javascript

I'm currently working on an artificial intelligence project that utilizes Prolog, and I'm looking to publish it online. I came across pengines (http://pengines.swi-prolog.org/docs/documentation.html, http://www.swi-prolog.org/pldoc/doc_for?object ...

Remove hidden data upon moving cursor over table rows after a delay

Hey there! I'm in need of a little assistance, so I hope you can lend me a hand. Here's the scenario: Within my category table, there are numerous rows, each containing a hidden textbox with an empty value and a unique ID. As users navigate t ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...