How come my div won't align next to the image? It keeps appearing behind the image instead

I need help figuring out why I am unable to float a div box next to an image. Despite successful attempts with text, the div seems to be getting stuck behind the image instead of appearing beside it.

http://jsfiddle.net/n8ZDQ/1/ (observe how the red div is mostly hidden behind the image)

HTML:

<img src="http://stignatiusyardley.org/pictures/NFP/NFP%20family%20image.jpg" style="float:left;width:370px;height:246px;" />

CSS:

#optin {
width:466px;
border:1px solid #CCCCCC;
height:166px;
background-color:red;

}​

Answer №1

The designated div is not currently floating! Experiment with including float: left in the styling of #optin.

Answer №2

By default, the DIV is a block-level element. If you want it to display as inline or inline-block, you'll need to set it to either display: inline-block or float: left to achieve the desired effect.

Answer №3

Make the necessary adjustments to the css property of #optin in order for it to float.

#optin {
    width:466px;
    border:1px solid #CCCCCC;
    height:166px;
    background-color:red;
    float: left;
}​

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

Issue with :hover pseudo-class in IE8

If you're unsure about my explanation, check out the video for a visual demonstration. Pay close attention to the cursor movements while I attempt to optimize my website for IE8. Hopefully there is a solution to this issue. Thank you in advance! http ...

How can I achieve a stylish alternating bottom-border effect for my website navigation menu?

Is there a way for me to achieve this navigation style? https://i.sstatic.net/LSNHL.png Here is the code I am working with currently. https://gist.github.com/anonymous/9c239f1b541aa26d461b I'm facing difficulty replicating the line style. Any sugges ...

Incomplete test on position fixed in Modernizr

Although Modernizr is a valuable tool, the example test for position: fixed has some shortcomings: iOS 4 and below return true, even though they do not actually support position: fixed Opera on Windows returns false, despite its support for position: fix ...

What is the best way to extract the text "TSV SCHOTT Mainz" from HTML using Python?

https://i.sstatic.net/2KDgz.png Hello, I'm struggling to locate the text "TSV SCHOTT Mainz" in the HTML code because I am unsure of which part to target. I have attempted the following: import requests from bs4 import BeautifulSoup # URL of the Bo ...

What is causing my mobile version not to resize and adjust to fit the screen properly?

Currently utilizing Bootstrap 4 along with the viewport meta tag, %meta{:content => "width=device-width, initial-scale=1, shrink-to-fit=no", :name => "viewport"}/ Even after hiding all images with .hidden-xs-up, the display on Chrome mobile appear ...

Creating variable-width DIVs to simulate TABLE column behavior using CSS

I've been struggling for hours trying to recreate the same functionality as an old HTML table layout using DIVs. Inside a parent DIV, I have a simple three-column setup: Column-1 contains text and should be as narrow as possible without wrapping (m ...

Arrange two divs next to each other on the page: the div on the right can be scrolled through, while the div on the

I am attempting to create a layout similar to this https://i.sstatic.net/Y1FCp.png My goal is to: Have two main divs positioned side by side inside a wrapper div Ensure the wrapper expands to fill 100% of the browser size The left div (banner) should b ...

Issues arise when attempting to manipulate the DOM with ng-view in AngularJS

Apologies for not providing the code due to its length. I have a simple application with a single module, controller, and ng-view/routProvider. In my controller, when I use console.log(angular.element('div').length), it correctly shows that ther ...

Using an image as the background for a three.js scene may cause it to appear distorted

I am struggling with setting an image as a background for my scene without it becoming blurry. I have attempted to use the following code: textureLoader.load("images/background/space.png", function(t) { scene.background = t; }); The problem arises when ...

Centralized Title / Side-aligned Menu

Good day, I am in need of assistance with a menu layout for my website. My goal is to have the title centered with the menu flexed out to the sides, but I'm encountering some issues. The colors included are just for testing purposes and will be update ...

React's useState function does not update the FileReader

I've been working on extracting values from an XML file using the code below. However, I'm encountering an issue where the console always outputs 'undefined'. Can anyone help me identify where I might be going wrong? This is my JavaSc ...

Searching for matching strings in jQuery and eliminating the parent div element

Here's an HTML snippet: <div id="keywords"> <div id="container0"> <span id="term010"> this</span> <span id="term111"> is</span> <span id="term212"> a</span> <span ...

What's the best way to perfectly align table text in the center both horizontally and vertically?

Despite encountering similar or potentially identical questions, I have attempted the suggested solutions without success. My aim is to design a table that centers text both vertically and horizontally, ideally using flex. However, the structure of the ta ...

Is the footer consistently at the bottom of the page, expanding the container alongside it?

Looking to ensure that my footer remains at the bottom of the site, with the container expanding when there isn't enough content to fill the browsing window. Additionally, as new data is added to the menu or information block, the container should str ...

Exploring the functions of Safari input types: search, reset, and normalize

Is there a proper way to reset the appearance of a search input so that it resembles a text field in Safari? screenshot I'm experiencing an issue with Safari where there is unwanted padding on the left side of the search input that I can't seem ...

The flex box container has an overflowing issue despite the implementation of overflow:hidden and setting a min-width of

Struggling to make my flex box container fit in the div Despite setting min-width: 0 and overflow: hidden as a last resort the flex box simply won't shrink when the width changes Check out what happens when the width is adjusted: https://js ...

Web scripting using Python

I am new to Python and have been practicing in the IDLE interface. Now, I am interested in configuring Python with MAMP so that I can start building simple web applications - incorporating Python within HTML, or vice versa. (I am assuming HTML is compatibl ...

Help me figure out how to independently toggle submenus on my navbar by utilizing the Vue.js composition API

I am currently working on developing a navbar using the Vue.js composition API. My primary objective is to toggle the submenus when a user clicks on them. However, since I am iterating through an object to display the submenus, I am faced with the challeng ...

Gradually appear with jQuery while maintaining current position

Exploring Display Options In my current setup, I have text that initially has a display:none property, and jQuery is applied to fadeIn() the content. The challenge lies in the fact that since the text is centered, as each word appears, the positioning on ...

Issue with overlapping sticky dropdown and sticky navigation in Bootstrap 4

My issue revolves around getting the dropdown button menu to display in front of the vertical menu. When I click on the dropdown, the vertical (blue) menu takes precedence. This problem arose suddenly after applying the sticky-top class to both menus. Whil ...