Paragraphs that seem to float effortlessly on the

My div has a specific size and contains an image along with two paragraphs.

All elements are set to float left.

div {
  width: 400px;
  height: 400px;
}
img {
  float: left;
  width: 100px;
  height: 100px;
}
.one {
  float: left;
}
.two {
  float: left;
}
<div>
  <img src="http://img.timeinc.net/time/daily/2010/1001/360_br10q_0208.jpg" alt="">
  <p class="one">one</p>
  <p class="two">two</p>
</div>

Demo

I'm trying to have the paragraphs stacked on top of each other while still maintaining the left alignment. Is this possible? If so, how can I achieve it?

Answer №1

To achieve a layout where images and paragraphs stack one below the other, you can remove the CSS property float:left; from the classes .one, .two, and img. Since DIV tags are block elements, they naturally flow down the page without the need for floating which would display them side by side.

Alternatively,

If the intention is to structure the code as shown below, you can place the elements inside a div and remove the float property. By nesting them within a div, they will adhere to the natural block flow with display:block;.

div{
  width: 400px;
  height: 400px;
}
img{
  float:left;
  width: 100px;
  height: 100px;
}
.para{

}
.one{
}
.two{
}
<div>
<img src="http://img.timeinc.net/time/daily/2010/1001/360_br10q_0208.jpg" alt="">
<div class="para">


  <p class="one">one</p>
  <p class="two">two</p>
  </div>d
</div>

Answer №2

Check out this example on jsFiddle

div {
  width: 115px;
  float: left;
}
img {
  width: 100px;
  height: 100px;
}
<div>
  <img src="http://img.timeinc.net/time/daily/2010/1001/360_br10q_0208.jpg" alt="">
</div>
<div>
  <p>one</p>
  <p>two</p>
</div>

To achieve the desired layout, you can float the two parent containers. However, floating the paragraphs is not necessary!

I hope this example provides you with some inspiration for your project.

Answer №3

Use the clear: left property for elements with classes .one and .two:

div {
  width: 400px;
  height: 400px;
}
img {
  float: left;
  width: 100px;
  height: 100px;
}
.one {
  float: left;
  clear: left;
}
.two {
  float: left;
  clear: left;
}
<div>
  <img src="http://img.timeinc.net/time/daily/2010/1001/360_br10q_0208.jpg" alt="">
  <p class="one">one</p>
  <p class="two">two</p>
</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

Creating an interactive TABLE with twitching animations in a straightforward HTML and JavaScript project

Currently, I am tackling a JavaScript challenge involving placing eight queens on a chessboard in such a way that they do not attack each other. However, there seems to be an issue - whenever I place a queen in an unoccupied column, that particular column ...

What is the method for determining if a key on the keyboard is currently being pressed?

I am in need of a function that mimics a crouch button for my character. The character should only crouch while the down arrow key is being held, not just pressed once. How can I achieve this functionality? Below is my attempted code, which unfortunately ...

Using Bootstrap cdn in my React JS project caused conflicts with my custom CSS styles

I recently created a webpage in ReactJS and styled it using CSS. In order to enhance the styling of one component, I integrated Bootstrap by adding the latest CDN link to my "index.html" file. However, I noticed that the Bootstrap styles were overriding ...

How to make text transition between colors using CSS or jQuery

I'm looking to make a text blink with alternating colors: For instance: blinking a text with white, green, white, green, white, green I am open to either using jQuery or CSS. ...

Having issues with jQuery not functioning on this specific web page across all browsers. The reason behind this puzzling dilemma remains elusive to me

I am experiencing issues with the functionality of my website. The buttons with + signs are meant to be drop-down toggles, and the mini-tabs below them should work as tabs. Additionally, the sample images at the bottom are not loading properly when clicked ...

Angular Bootstrap div width not displaying fully on iPad device

My layout includes 2 columns in a single row, which is functioning properly on most devices. However, when viewed on an iPad, the layout does not span the full width of the screen. Here is a snippet of my code: <div class="row"> ...

Is it feasible to combine border-radius with a gradient border-image?

I'm trying to style an input field with a rounded border using the border-radius property, and also add a gradient to that border. Despite successfully creating both the gradient and rounded corners separately, I am unable to make them work together. ...

No matter how much effort I put in, combining CSS with Bootstrap seems to be an impossible task

I have been working on my website using Bootstrap libraries and I am trying to customize certain aspects of the parent layout such as the background color and jumbotron color. However, no matter what I try, I cannot seem to make it work. Can anyone help ...

Styling Browser Alerts

Is it possible to style a contact form popup to look more like a modal, with a centered display and dark transparent background that fades when clicked? Currently, my contact form triggers a browser alert/popup using this script: http://jsfiddle.net/xf4C ...

Navigate a Bootstrap 4 drop-down menu by scrolling rather than having it drop down

I recently designed a Navbar with dropdown menus, but I have encountered an issue where the dropdown menus do not overlay the content as intended. Instead, they create a scroll-down menu and display the contents within it. I would appreciate it if someone ...

Identical identification with matching attributes

I have successfully integrated Popeye slider to display images. However, whenever I need to create a new slider show, I find myself duplicating all the CSS content to another ID. For example: #ppy1 .ppy-extcaption { width: 240px; displ ...

Position the image to the left of the input box and align the text to the right

I have positioned the image to the left of the input box, but the text is overlapping the image. How can I prevent this overlap? While the image is correctly aligned on the left, I need the input text to be aligned on the right side of the image without ...

Can I substitute custom tags for the traditional <p> tag?

My HTML with CSS has an issue where a custom HTML tag is not displaying the text while my CSS picks up another tag. Interestingly, replacing <title>Layout Controls</title> with <p>Layout Controls</p> resolves the problem and shows t ...

The Angular 5 animations enter transition successfully performs (void => state) but encounters issues with the leave transition (state => void)

Currently tackling a challenge in Angular 5 where I am trying to build a custom carousel image browser from scratch. The goal is to allow users to navigate through images by clicking or swiping to view the next or previous image. The animations for the :e ...

What's causing the excessive amount of white space in my image?

Whenever I include a picture of myself on the page, it creates excessive white space at the bottom. I'm not sure why this happens, but removing the image eliminates the white space. I've attempted adjusting the margins and padding, as well as se ...

`ASP.NET utilized for displaying several pictures on a website`

My goal is to retrieve images from a database and showcase them on a webpage. I am looking to incorporate a "show more images" button in case there are too many images to display at once. Additionally, I would like for the additional images to load autom ...

Header navigation issue: sub menu fails to display

I've been trying to troubleshoot this issue, but nothing seems to quite fit my situation. My header contains an empty space (referred to as "void" in my case) and a menu directly beneath it. When scrolling down, the header moves up and the menu rema ...

Not all records are compatible with PHP Echo when placed within a paragraph

Looking for some assistance with a simple form set up; <div class="formholder"> <form action="column1.php" method="post"> <input type="text" placeholder="URL:" name="url" required=""><br> <input type="t ...

Adjust the background hue while scrolling (scrolling feature not functioning properly)

Seeking assistance with changing the background color of a component based on user scrolling behavior. I have attempted to achieve this using the following code snippet: const [mainColor, setMainColor] = useState('red') const listenScrollEve ...

How to make Angular2 page fill the entire screen height

I'm trying to make a div take up the full screen in an angular2 template Here's what I've attempted so far: <div class="auth-container"> </div> In the CSS file: .auth-container{ height: 100%; //also tried with min-height ...