Problem with layout design (utilizing float properties)

I'm curious why the paragraph content gets sandwiched between two floated divs. I'd like the paragraph content to appear below the header. Also, why aren't the line breaks showing in the paragraph?

Check out this JS Fiddle link for reference: http://jsfiddle.net/yf3nyfk1/

HTML:

<body>
<div id="header-container">
    <div id="header-wrap">
        <div class="left logo logoimg">
            <img src="http://i.imgur.com/dtMBhKq.png"/>
        </div>
        <ul class="nav">
            <li class="contact">CONTACT</li>
            <li class="about">ABOUT</li>
            <li class="portfolio">PORTFOLIO</li>
        </ul>
    </div>
</div>
<div>
<p>
Lorem ipsum...
</p>
</div>
</body>

CSS:

body {
background: #000000;
margin: 0;
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
color: #FFFFFF;  
text-align: center;
}

h1 {
font-size: 24px;
color: #FF9000;
}

img {
max-width: 100%;
}

.left {
float: left;
}

ul{
padding: 0px 0px 0px;
}

.right.nav {
float: right;
}

/******************************************************************************/
/* Menus */
/******************************************************************************/
#header-container{
margin: auto;
padding: 80px 0px 0px;
max-width: 1160px;
width: 100%;
}

#header-wrap{
padding: 0px 40px 0px;
}

.logo{
max-width: 440px;
width: 100%;
}

ul{
list-style-type:none;
display: inline-block;
}

.nav{
float:right;
list-style-type:none;
overflow: hidden;   
}

.nav li{
float:right;
overflow: hidden;
}

.portfolio{
color: #00bff3;
border: 1px solid #00bff3;
padding: 8px 4px 8px;
margin-left: 0px;
width: 87px;
text-align: center;
}

.about{
color: #00bff3;
border: 1px solid #00bff3;
padding: 8px 4px 8px;
margin-left: 10px;
width: 60px;
text-align: center; 
}

.contact{
color: #00bff3;
border: 1px solid #00bff3;
padding: 8px 4px 8px;
margin-left: 10px;
width: 76px;
text-align: center;
}

.orangebutton{
color: #FF9000;
border: 1px solid #FF9000;
margin: 0px 5px 0px;
}

/******************************************************************************/
/* Media Queries */
/******************************************************************************/
@media only screen and (max-width: 867px) {
#header-wrap{
padding: 10px;

}

.right{
float: none;
}

.nav{
float: none;
}

.left {
float: none;
}
.logo{
margin:auto;

}
}

Answer №1

To fix the layout, make sure to clear any floats:

p {
    clear:both;    
}

Updated fiddle link here.

For more information on clear, check out MDN.

Regarding the second query, HTML disregards extra spaces and line breaks, condensing them into a single space. For new lines, use break elements like <br> or properly close paragraph tags with </p>.

Another option is adjusting whitespace handling by setting whitespace: pre for the p elements in your CSS, but it's usually unnecessary. Simply ensure paragraphs are closed correctly for proper formatting.

Answer №2

To move the p to a new line and clear the floating, add clear:both style like this:

<p style='clear:both'>
    Lorem ipsum...
</p>

http://example.com/abcd123

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

Update the content according to the size of the screen

I'm currently working on a project where I need to redirect pages based on screen sizes. I have separate index files for the mobile and web versions of the website. In the web version's index file, I've added the following script: <scri ...

Java: Issue with JLabel Text Alignment

At the bottom of my panel, I have a JLabel that provides text instructions to the user. When some of the text exceeded the screen width, I used tags to fix this issue. However, after implementing the code shown below, the text is no longer centered an ...

What is the proper way to apply a background color to the entire body using CSS?

I'm facing an issue with getting the background color to cover the entire body of my webpage. Currently, it only captures a certain size and when there is scrolling on the window, two shades of colors appear. I want the background color to span the en ...

Navigating websites: Clicking buttons and analyzing content

When looking to navigate a website's directory by utilizing buttons on the page or calling the associated functions directly, what language or environment is most suitable for this task? After experimenting with Python, Java, Selenium, and JavaScript, ...

Bootstrap 4 - The Mystery of 'col-sm-auto' Taking Precedence Over 'col-md-4'

I am currently learning Bootstrap and have encountered a challenge that I can't seem to figure out. Let's take a look at a snippet of the code: <button className=" col-md-4 col-sm-auto btn btn-info ...

Creating a blog "post" model in Ruby on Rails with CSS that can behave in two distinct ways

I am in the process of creating a blog using Ruby on Rails. The posts on my blog are generated from the Posts model, and I want them to exhibit two different behaviors. Currently, I have configured it so that a new post is automatically created every day. ...

Received undefined response from Axios.get() request

While working with the code below, I encountered an issue. The axios get request from await axios.get('/products/api') is functioning properly and I can see the data in the console. However, for await axios.get('/users/api'), 'Unde ...

Customizing styles in ZK based on theme

I am currently working on a ZK application that has been styled using CSS, specifically the colors from the Sapphire theme. My goal is to have environment-dependent themes - Sapphire for production and Breeze for stage. While I have successfully implemente ...

Can an element contain two different classes at the same time?

Apologies if the title was unclear. I am trying to customize the color of my font awesome social media icons individually. Although I have successfully changed the color for all of them, that is not the desired outcome. Here is the icon: <i class=& ...

Implementing MVC3 Razor Stylesheet within a designated section

I am currently working with MVC3 using Razor. I have set up my website with a standard structure, including a small backend section. Within this backend area, I would like to create a folder specifically for storing "content" such as stylesheets and JavaSc ...

Having several contact forms embedded within a single webpage

I am currently in the process of developing a prototype website and my objective is to have multiple forms on a single page. My goal is to have a form for each service, where users can click on the service and fill out a form to request a quote. The first ...

Persistent column menu in ag-grid

Is there a way to include a menu for each row within a sticky column in Ag-grid? I couldn't find any information about this feature in the official documentation, so I'm unsure if it's even possible. I've attempted several methods, but ...

Ways to animate a main element independently of its counterpart's animation

I want to create an animation for a parent element without affecting the child's animation. My HTML & CSS structure is set up as follows: .parent{ background-image: url('https://pm1.narvii.com/6195/421ddbf8c9a2fb1715ef833f869164dc1be ...

What is the best way to expand and collapse a mat-expansion-panel using a button click

Is it possible to expand a specific mat-expansion-panel by clicking an external button? I've attempted linking to the ID of the panel, but haven't had any luck... <mat-expansion-panel id="panel1"> ... </> ... <button (click)="doc ...

jQuery - accessing a different class within the object

Let me explain the scenario: I have a website that will delve into 4 different subjects. Initially, I have 4 divs each representing the title of those subjects. For instance, <div><p> Physics </p></div> <div><p> Chem ...

Is there a way to exclude the Unicode character from the first menu item while still utilizing it in the other items on my menu?

I have been working on customizing my menu by using the unicode character \25C6 to represent a black solid diamond as a spacer between labels. After searching for solutions on Stack Overflow, I attempted to implement the suggested method using the bef ...

Design a dynamic table using JavaScript

After spending hours working on my first JavaScript code, following the instructions in my textbook, I still can't get the table to display on my webpage. The id="eventList" is already included in my HTML and I've shortened the arrays. Here' ...

Browsing with PHP/HTML on Safari from Mac Os 10.6.5 seems to run at a sluggish pace

This is the program: <?php require_once 'swift-mailer/lib/swift_required.php'; $name = $_POST['name']; $email = $_POST['email']; $form_subject = $_POST['form_subject']; $form_message = $_POST['form_message ...

I am trying to figure out how to extract the filename from a form using PHP, but unfortunately, the $_FILES["filename"]["name"] method doesn't appear to be working. Can anyone help me with this issue

Having an issue with a form below that is supposed to extract some details into a mySQL database. Unfortunately, every time I try to retrieve the file in the form, it returns null. Unsure of the reason behind this, so any assistance would be much appreciat ...

Unable to display Boostrap modal upon clicking href link

Can someone help me troubleshoot why my pop modal is not displaying after a user clicks on a specific link on my webpage? I have attempted the following: <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></s ...