Play around with the height of the content

Can two divs be added one after another without using the position property in CSS?

Here is an example of HTML code:

<div class="content1">
    Lorem Ipsum is simply dummy text
</div>
<div class="content2">
    Lorem Ipsum is simply dummy text
</div>

And the corresponding CSS code:

.content1{
    width: 100%;
    height: 400px;
    border: 1px solid black;
}
.content2{
    width: 100%;
    height: 300px;
    border: 1px solid red;
}

Answer №1

You're forgetting to properly close your <div> tags.

Make sure to use </div> to close a <div> block, like this:

<div class="content1">
  Lorem Ipsum is simply dummy text
</div> <!-- Updated -->
<div class="content2">
  Lorem Ipsum is simply dummy text
</div> <!-- Updated -->

Answer №2

Ensure to properly close your <div> elements

.container1 {
  width: 100%;
  height: 400px;
  border: 1px solid black;
  
}
.container2 {
  width: 100%;
  height: 300px;
  border: 1px solid red;
}
<div class="container1">
  Lorem Ipsum is simply dummy text
</div>
<div class="container2">
  Lorem Ipsum is simply dummy text
</div>

Answer №3

Be sure to properly close all your div elements

<div class="section1">Lorem Ipsum is just placeholder text</div>
<div class="section2">Lorem Ipsum is merely dummy text</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

Finding the location of an "Apply" button on an Angular HTML page

There is an issue with the positioning of the apply button in the filter bar. Sometimes it displays in the next row instead of alongside the other filters. How can I determine the exact position of this apply button within the HTML page? <div class=&quo ...

Use jQuery to switch back and forth between two different sets of classes

I am attempting to switch between two different sets of classes using jQuery. My goal is to change from one custom icon to a font-awesome icon upon clicking an element. While I have been successful in changing a single class, I am facing challenges when tr ...

What is the best way to alter the background-color of an element that is contained within a GatsbyJS component, depending on the specific page where the component is being utilized?

As a first-time GatsbyJS website builder, I am working on creating reusable components for my site. One of these components is the footer, and I have already structured it. Now, I have a dilemma - I want to change the color of a specific <div> within ...

Is it necessary for me to develop a component to display my Navigation Menu?

After designing a Navigation menu component for desktop mode, I also created a separate side drawer component to handle variations in screen size. However, a friend of mine advised that a side drawer menu component may not be necessary. According to them ...

Creating checkboxes in an HTML table based on the output of a query

I'm currently working on creating a dynamic table that displays query results, and I have come across this code snippet that successfully generates the table. However, I would like to add an extra column to each row that contains checkboxes. Is there ...

What's the best way to stack two input fields vertically and combine them into a single unit?

My goal is to have two inputs placed inside a container, one above the other with no space in between and without separate borders for each input. I am using Bootstrap, but so far my attempts with vertical alignment have been unsuccessful. Here is the code ...

How can I trim a value using one-way data binding in Angular?

Is there a way to trim values in Angular using one-way data binding? Can this be done directly in the component.html file rather than in typescript? I tried the following but it didn't work: <P>{{country.trim()}}</P> Thanks ...

Discover the secret to applying a gradient shade to the "border" element when it reaches full capacity with Vue's innovative Custom CSS package

Utilizing the package https://www.npmjs.com/package/vue-css-donut-chart#usage-with-all-the-available-props to create a "border" effect around images based on progress has presented a challenge. Specifically, achieving a gradient color for the border when i ...

Various monitor and screen resolutions will result in distinct layouts

I'm having an issue with the logo on my website. It's supposed to be centered between the navbar menus, but it keeps moving when I switch monitors or resolutions. Check out the logo position here. Is there something wrong with my code? How do I ...

Transfer an image to the top of a cell

I'm trying to position the image at the top of the cell, but I've hit a roadblock. Here's a preview of the web photo: https://i.sstatic.net/U3XK9.png Here is my CSS code: #animes { width: 130px; height: 100px; display: block; padd ...

Clicking on rows within a table using jQuery

My table's content is being generated through an AJAX success response. HTML code <table class="table table-hover" id="table_content"></table> AJAX code $.ajax({ dataType: "json", type : "POST", url: "/configura ...

What is the best way to place a square inside a rectangle?

I've been experimenting with fitting a square into a rectangle using max-width, max-height, and aspect-ratio. However, I encountered an issue where it only works in portrait mode, but fails in landscape mode. Here is how Firefox renders it: https://i ...

Modify the colors of the chartist fill and stroke using JavaScript

Struggling to dynamically set colors in a chartist graph using JavaScript. How can custom colors be applied through JS? The attempted method below is not successfully changing the color for the showArea in the chartist graph. <!doctype html> <htm ...

JavaScript and jQuery validation issues persisting

Here is the HTML code I am using: <script src="js/validate.js"></script> <label>FIRST NAME:</label> <td> <input type="text" class="firstname" id="firstname" onKeyUp="firstname()" /> </td> <td> <label id=" ...

Incorporating an external script within a Next.js application

I've been having trouble incorporating an external JavaScript source into my Next.js application and I keep encountering the following error: Failed to execute 'write' on 'Document': It isn't possible to write into a documen ...

Utilizing jQuery to parse JSON data and extract specific values from the arrays

My goal is to extract values from a JSON file that are not in the same object, but share the same name I have an array called wallsListShShow which contains two sub-arrays: wall1 and wall2. While I am able to read the names of wall1 and wall2, I am having ...

Is there a way to locate classes containing underscores within them using Selenium?

Having trouble scraping a webpage with a class name containing an underscore, specifically this element: <span class="s-item__time-left">30m</span> == $0 I attempted to locate it by class name: time = driver.find_elements_class_name("s-item_ ...

CSS: Create a form with two input fields where the left field is adjustable in width and the right field fills up

------------- -------------------------------------------------- | some unique text | | some more original content, varying length | ------------- -------------------------------------------------- |<---------------------- 100% width ------------------ ...

Connecting with a php anchor and hash symbol in a website URL

Looking to include a PHP anchor along with a hash anchor in an HTML link. <?php echo '<a href="test.php?page='.$i.'#hash">'.$i.'</a>'; ?> The PHP code successfully echoes the link, but upon clicking it, th ...

Webstorm encounters difficulties compiling Sass

While attempting to utilize Sass in the Webstorm IDE, I noticed that it is defaulting to Ruby 1.8 (OS Default) instead of my preferred RVM Ruby Version (1.9.x). To address this issue, I tried setting the path for Sass in the Watcher-Configuration: PATH=$ ...