Stacking issue - elements not properly aligned

Is there a way to move my H1 text below the blue category button instead of beside it? Thank you in advance!

http://jsfiddle.net/TDBzN/

<div id="article" class="animated2 fadeInLeftBig">
<div class="article-close"></div>
    <div class="category">#Category</div>
    <h1>This is the H1</h1>
    <p class="intro">Lorem ips um dolor sit amet, consectetur adipiscing elit. Nam sit amet diam nisl. Aliquam quis est eu elit facilisis aliquam. Pellentesque porta nunc diam <a class="various" href="#">Inline</a></p>
</div>

CSS:

#article {
    /* opacity controlled via fadeInLeftBig */
    position: absolute;
    width: 600px;
    left: 230px;
    top: 0;
    height:100%;
    background-color: #fff;
    opacity:0.9;
    padding: 30px 50px 50px 50px;
    z-index: 1000;
    box-shadow:-2px 0 5px 0 rgba(0, 0, 0, 0.5); 
}
#article .intro{
    font-family: 'Open Sans', sans-serif;
    font-weight:600;
    }

#article h1 {
    font-size: 33px;
    color:#555;
    font-style:italic;
}
#article h2 {
    color:#555;
    margin-bottom:5px;
}
#article p {
    font-style: normal;
    font-weight: 300;
    /* color: #555; */
    color: #555;
    font-size: 15px;
    line-height: 22px;
    padding: 10px 0;
    margin-top: -10px;
    text-align:justify;

    }
#article a {
    color: #F15034;
    text-decoration: none;
    font-weight: bold;
}
#article a:hover {
    border-bottom: 2px solid #F15034;
}

.category {
    float: left;
    text-align: center;
    font-size: 12px;
    color: white;
    padding: 8px 18px;
    margin: 18px 0 0 0px;
    text-decoration: none;
    -webkit-transition: background 0.3s ease;
    -moz-transition: background 0.3s ease;
    -ms-transition: background 0.3s ease;
    -o-transition: background 0.3s ease;
    transition: background 0.3s ease;
    background: rgba(71, 186, 255, 0.8);
}

Answer №1

It is recommended to add clear: both; to the h1 tag. Another option would be to include a separate clear:both; <div>, although it is not necessary in this case.

DEMO: http://jsfiddle.net/TDBzN/6/;

h1 
{
    clear:both;
}

To insert a clear:both; div, place it between the h1 element and the floated element, such as .category.

<div style="clear: both;"></div>

This method is useful for adding a clearing element only where needed, without directly affecting the element itself.

Answer №2

Make sure to add clear:left to your heading for proper alignment

#article h1 {
    font-size: 33px;
    color:#555;
    font-style:italic;
    clear:left;
}

For a visual example, visit http://jsfiddle.net/TDBzN/2/

Answer №3

VIEW DEMO

Make changes to the .category class as follows:

.category {
float: left;  /* REMOVE */
text-align: center;
font-size: 12px;
color: white;
padding: 8px 18px;
margin: 18px 0 0 0px;
text-decoration: none;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-ms-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
background: rgba(71, 186, 255, 0.8);
}

Change it to:

.category {
max-width:70px; /* EDITED */
text-align: center;
font-size: 12px;
color: white;
padding: 8px 18px;
margin: 18px 0 0 0px;
text-decoration: none;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-ms-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
background: rgba(71, 186, 255, 0.8);
}

These adjustments should work perfectly.

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

I would like some clarification on how bookmarking works

As I encountered a puzzling issue recently, I realize that I may need some assistance to navigate through it. It involves bookmarking some links for future reference. I attempted to search for answers online but found myself even more perplexed. Does boo ...

"Eliminate any inline styling from a string element with the power of JavaScript/j

If I have the following string: let sentence = '<h1 style="lots of class"> </h1><h2> <p style="bunch of class"> </p> <p style="bunch of class"> </p></h2>'; This string contains multiple elements a ...

What is the best way to ensure the menu background aligns perfectly with the header in HTML/CSS?

Issue: Menu background doesn't align with header. (visible in the image provided below) VIEW IMAGE Any suggestions on how to resolve this alignment problem? CSS CODE : .header { margin:0px auto; max-width: 960px; } #header { height:30 ...

CSS creates captivating image hover transitions with span elements

<a href=""><img src=""><span>content</span></a> When I hover over the image, the content within the span appears using relative positioning with display set to none and absolute positioning in the span tag. My query is regard ...

How can we use jQuery to extract an HTML element's external stylesheet and add it to its "style" attribute?

My goal is to extract all CSS references from an external stylesheet, such as <link rel="stylesheet" href="css/General.css">, and add them to the existing styling of each HTML element on my page (converting all CSS to inline). The reason for this re ...

Mastering the Material-UI Grid in SPAs: Conquering the Negative Margin Dilemma

While attempting to build a single page application (SPA), I've encountered an issue with using the Grid component from material-ui. Normally, I rely heavily on the Grid, but in this new project, something seems amiss. The current problem is evident ...

Ways to delete an image from a batch file uploading feature

I encountered an issue with my multiple image upload function that includes preview and remove options. When I select 4 images and preview them correctly, removing 2 from the preview still results in uploading all 4 images to the database. $(document).rea ...

Storing multiple email addresses in an array using an HTML input element

I have a small React Bootstrap form where I am trying to save multiple email addresses entered by the user into an array. However, when I use onChange={()=> setEmails(e.target.value as any} it stores them in string format like this --> [email p ...

There appears to be an empty void on the website

If you could kindly click on this link & use CTRL + F to search for the text "Info", you will see a visual representation similar to the image below. There seems to be quite a bit of empty space below these texts. I experimented with padding, display: ...

Divs that overlap and share the same font may exhibit variations in letter spacing

In my design, I have a div that overlays another div with the exact same offsets and font properties. The upper div has a transparent background and typically covers the text of the underlying div. However, I recently noticed an issue with my script where ...

Tips for positioning a div element at the center in ASP.NET

I have written the following code snippet: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit ...

Adjust the viewport to fit the width of the screen and display large images

Currently, I am experimenting with using a WebView to display a large image while incorporating multitouch functionality to prevent memory crashes. My webView is configured as follows: setInitialScale(20); WebSettings settings = getSettings(); ...

Enhancing Next.js Images with Custom CSS Styles

I am working with a Next.js component: import styles from '../styles/Navbar.module.css' import Image from 'next/image' export const Navbar = () => { <div> <Image className={styles["navbar-home-icon"]} ...

Different methods of transferring PHP post information to JavaScript

Is there a cleaner and more elegant way to pass posted PHP variables to JavaScript for manipulation, rather than using inline JavaScript? I currently have a simple PHP form that posts data to specific variables and then uses inline JavaScript to handle the ...

Achieve Perfect Alignment of Text Inside a Floating Div

Currently, I have a div aligned to the right inside another container. The text (date/time) within this right-aligned div needs to be vertically centered without using top padding. Whenever I apply top padding, it shifts my div downwards and disrupts its ...

Can you help me with sorting asynchronous line points for KineticJS?

For the past couple of days, I've been grappling with a peculiar issue that I found difficult to articulate in the title. The challenge I'm facing involves a KineticJs Line, which contains an array of points (line.attrs.points) represented as ob ...

I'm struggling to incorporate the JQuery slideDown function into my code. Can someone lend a hand?

Why isn't the video div sliding down and displaying properly in the beginning? Any ideas on how to fix it? Here is the snippet of HTML code and JavaScript: <!DOCTYPE HTML> <html> <head> <title>Team Songs</title> <link ...

Can you provide guidance on showcasing mongodb data in a flask template with flask_pymongo?

Apologies if my question seems a bit unclear. I am struggling to display data from MongoDB in a Flask template. The code I have currently isn't working as expected. Here's what I've attempted so far: (I tried to get creative) @app.route(&apo ...

Issue with checkboxes preventing submission of form

Currently working on a website project for a company that requires certain steps to be completed for deliveries. Unfortunately, I am facing issues with the submit button, and I apologize as I am still new to this. The code I have pasted is divided into tw ...

Alteration in relational shift of division placement

My webpage is divided into three sections with the following proportions: 15% - 65% - 20% In the right section, there is a div with the ID alchemy. I want to set the height of this div using <div style="height:150px;">. However, when I set the heig ...