Shift heading 1 as well as heading 2 to the image's right side

Is it possible to position <h1> and <h2> to the right of an image while ensuring that <h2> is displayed below <h1>? Any suggestions on how I can achieve this layout?

This is my current code

<html>
<link rel="stylesheet" href="style.css">
<img src="images/SelzerSeal.jpg" alt="Henry Selzer attorney at law">
<h1>Test</h1><br>
<h2>Test 2</h2>
</html>

CSS Styling

img {
max-width: 100%;
text-align: center;
float:left;
}
h1{
color:white;
font-size: 24px;
float:left;
font-family:"Book Antiqua";
}
h2 {
color:white;
font-size:20px;
float:left; 
font-family:"Times New Roman";
}

Answer №1

give this a shot:

.image {
  float: left;
  margin-right: 10px;
}
<img src="http://lorempixel.com/400/200" alt="" class="image">
<h1>Main Heading</h1>
<h2>Subheading</h2>

I trust this was useful.

Answer №2

To improve the layout, consider removing the float: left; property from both header tags, eliminating the <br> tag in HTML code, and getting rid of the unnecessary div with class "clear".

For reference, you can check out this example:

https://jsfiddle.net/t769avo2/

Answer №3

It is not necessary to apply the float property to either h1 or h2 in this case.

Check out the demo here

<html>
<link rel="stylesheet" href="style.css">
<img src="images/SelzerSeal.jpg" alt="Henry Selzer attorney at law">
<h1>Test</h1>
<h2>Test 2</h2>
</html>

img {
max-width: 100%;
float:left;
margin-right: 1%}
h1{
color:white;
font-size: 24px;
font-family:"Book Antiqua";
}
h2 {
color:white;
font-size:20px;
font-family:"Times New Roman";
}

Answer №4

To correct the alignment of your heading tags, simply delete the floats:

body {
  background:#000;
}
img {
  max-width: 100%;
  text-align: center;
  float:left;
}
h1{
  color:white;
  font-size: 24px;
  font-family:"Book Antiqua";
}
h2 {
  color:white;
  font-size:20px;
  font-family:"Times New Roman";
}
<img src="http://placehold.it/250x250" alt="Henry Selzer attorney at law">
<h1>Test</h1><br>
<h2>Test 2</h2>

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

Grid system that is responsive, while also maintaining a fixed column width

My problem seems simple, but I can't find an easy solution. What I need is to create a grid with fixed widths and a fixed distance between each column. Each column should be 400px wide, and as the browser window is resized, the grid should adjust by ...

Floating action buttons in CSS

I'm trying to create a button that reveals additional options when hovered over. I've been looking for a method similar to what's shown in the image below, but haven't been successful. This needs to be implemented on a web page using HT ...

Setting the height of an element based on the height of its background image

Hey there! I'm currently working with this component in my app, and right now, the height of the ButtonBase element is fixed. I fetch an image from the backend and use it as a backgroundImage for the ImageImagine component. I want to dynamically adjus ...

Is there a more efficient way to optimize my coding for this Cellular Automata project?

As a beginner in programming, I wanted to delve into the world of cellular automata and decided to create my own using JavaScript. The project involves a simple binary (black and white) 2D CA where each cell updates its color based on the colors of its 8 ...

Avoiding conflicts between banners, text, and images for HTML/CSS design

I'm having an issue with the banner I created for my project. It seems to be overlapping with text and images, hiding behind them. How can I fix this? Unfortunately, I can't post the link to my project here due to other files present. The specif ...

Puzzled by the CSS Box Model - There's a piece of the puzzle I

Check out my simplified fluid layout right here at this link. I've been trying to figure out why the alignment between the right column and the header above it seems off, even though there's no padding involved. Both have the same border styles, ...

Angular router link circles back to its originator

I've been working on a basic login page that transitions to a homepage once the user successfully logs in. So far, I've focused solely on the HTML structure of the login component without implementing any code in the corresponding TypeScript file ...

Utilizing ReactJS useState to eliminate a className

Basically, I'm trying to remove a className from an element when a button is clicked. I've attempted to use useState hooks and a regular function, with the onClick event on the button triggering this function/setUseState. However, the className l ...

The styled components can create identical CSS classes with varying conditions

Below are the CSS styles I am currently using: import styled, { css } from "styled-components"; const H4 = css` font-family: "Futura"; font-style: normal; font-weight: 500; font-size: 20px; line-height: 140%; color: #3a786a ...

The div structure generated through JavaScript appears distinct from its representation in the live DOM

Currently, I am facing a challenge with creating a complex nested Div structure within a JavaScript loop that iterates over JSON response objects from the Instagram API. The main goal is to set the URL for each image within a specific Bootstrap div layout. ...

Comparison of getComputedStyle() and cssText functionality between Internet Explorer and Firefox

Take a look at this example to see the issue in action. I'm attempting to access the cssText property of a <div> using window.getComputedStyle(element) (which provides a CSSStyleDeclaration object). While this works smoothly in Chrome, it' ...

Leverage JavaScript to retrieve the formatting of an element from an external CSS stylesheet

Check out this HTML snippet: <html> <head> <link rel="stylesheet" type="text/css" media="all" href="style.css"> </head> <body> <div id="test">Testing</div> <script> ...

Using Scrapy to extract data from Project Euler's website

Currently, I am working on scraping projecteuler.net using Python's scrapy library as a way to practice my skills. While there are existing implementations of similar scrapers online, they seem too complex for my needs. I simply want to save the probl ...

What is the best way to make a linear gradient that spans the entire vertical space that is visible (or shifts to a solid color)?

I'm trying to figure out how to apply a linear gradient to the body element of my webpage. Here's the CSS code I've been using: body { background: linear-gradient(0deg, white, lightgray); } The issue I'm facing is that the gradien ...

Adjusting the color of text based on the fulfillment of a condition

Is there a way to change the text color of a variable based on its value in PHP? For example, if the $status is set to admin, can we display it in red when echoed out using <h3>Status: <?php echo $status; ?></h3>? I'm not quite sure ...

Designing a flexible layout that allows for both vertical and horizontal scrolling of content

I have successfully implemented a flexbox layout with fixed header, fixed footer, fixed menu, and scrolling content based on resources from various articles and Stack Overflow answers. However, I am facing difficulty in achieving horizontal scrolling for ...

The sliding hamburger menu children fail to move in unison with the parent

I'm currently working on a dynamic sliding navigation menu that activates when the hamburger icon is clicked. However, I am facing an issue where the child <a> elements are not sliding along with the parent div. You can see how it currently loo ...

The alert dialog does not appear when clicking on "a"

Attempting to retrieve the ID of the clicked element using jQuery has proven unsuccessful for me. Below is the jQuery code I am working with: <script> $(function(){ $("a.step").click(function(){ var id = $(this).attr('id'); ...

Refresh a specific DIV element without having to refresh the entire page

I have a Div Tag that includes Small.php to populate it with information. My goal is to refresh the content every 15 seconds without reloading the entire webpage. I've attempted using JavaScript/jQuery without success. <script type="text/javascrip ...

AngularJS ui-router in HTML5 mode is a powerful combination that allows

Hey, I'm looking to implement HTML5 mode in my project. Here's how my file structure looks: mypage.de/mysub I can only make changes within the "mysub" directory. So far, I've added the following into my index.html: <base href="/mysub/ ...