What's the best way to insert an image right beneath a title within a webpage?

Check out my fiddle here.

I'm trying to position the pencil directly below the word "blah", but it seems like margin-top is not working as expected...

Additionally, I'm struggling with making sure that the pencil stays aligned below "blah" regardless of the screen size. I've heard that using percentages can help with this issue – is that true?

Here is the HTML snippet:


  <head>
  <h1>Blah Pencil</h1>
  <img src="http://www.pngall.com/wp-content/uploads/2016/03/Pencil-PNG-Pic.png" id="pencil" height="5%" width="20%">
  </head>
  <link rel="stylesheet" type="text/css" href="pencil.css">
  <link href="https://fonts.googleapis.com/css?family=Fugaz+One|Roboto" rel="stylesheet">

  <body>

  </body>

</html>

And here is the CSS code:


h1 {
  text-align: center;
  font-family: 'Fugaz One', cursive;
  font-size: 590%;
}

body {
  background-image: url(https://www.xmple.com/wallpaper/graph-paper-grid-white-blue-1920x1080-c2-fdf5e6-1e90ff-l2-2-54-a-0-f-20.svg);
}

#pencil {
  display: inline-block;
  margin-top: 21px;
}

Answer №1

To create a unique design, try using just one span element within the h1 tag. Place an img inside the span and apply positioning with relative/absolute to both the span and the img.

h1 {
  text-align: center;
  font-family: 'Fugaz One', cursive;
  font-size: 590%;
}

body {
  background-image: url(https://www.xmple.com/wallpaper/graph-paper-grid-white-blue-1920x1080-c2-fdf5e6-1e90ff-l2-2-54-a-0-f-20.svg);
}
span {
  position: relative;
}

h1 img {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
}
<h1><span>Blah<img src="http://www.stabilo-promotion.com/download/C27ad4c3cX13ba9b553a7X2665/STABILO_Giant_5430K_ALL_STABILO_red_SPP_150dpi.png" id="pencil"></span> Pencil</h1>

<link rel="stylesheet" type="text/css" href="pencil.css">
<link href="https://fonts.googleapis.com/css?family=Fugaz+One|Roboto" rel="stylesheet">

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

Can floated divs be prevented from collapsing without taking up any width?

Let's discuss an issue that is not related to block elements collapsing when their children are floated, and has nothing to do with clearing at all. Imagine having a set of floated divs like: <div class="column">Column 1</div> <div cl ...

Problem with Flexbox Wrapping on iPhone 6

I love the flexibility that flexbox provides, but I've been facing an issue specifically with wrapping on iOS devices. Is there a simple fallback option for handling wrapping? Here's a problem scenario where items refuse to wrap: ( JSFiddle Fans ...

Using Javascript to dynamically add and remove elements on click

Whenever I click on a link, I am able to generate input, label, and text. However, I want to be able to delete these elements with the next click event on the same link: I've tried updating my code like this: var addAnswer = (function() { var la ...

Applying CSS3 transition only to the active link, not all links on the page

Trying to implement a transition effect on all navigation links on my website, but so far only achieved it for visited links. Additionally, working on adding the transition effect to drop-down menus. body .main-nav .active-link >a, body .main-nav .ac ...

Tips for positioning two fields side by side on a webpage with CSS

I currently have two datepickers aligned vertically and I'm looking to display them in a horizontal layout with some spacing between them. What changes do I need to make in order to present these two calendar pickers side by side on the same row? Cou ...

What could be causing the mousedown event to go unrecognized in JavaScript when using THREE?

I have a basic THREE.js setup and I am trying to click on a spherical object, however, nothing happens when I click anywhere in the browser. I attempted to follow the advice given in this post but it did not work. The full code is provided below: <!DO ...

Is it permissible to employ both CSS pseudo-elements, namely before and after, on a single selector in this instance?

Seeking to create a visually appealing horizontal menu navigation resembling: {image1} ITEM1 [separator1] {image2} ITEM2 [separator2] etc. However, a constraint exists - the HTML structure must remain unchanged. Can this be achieved solely with CSS us ...

Updating the value of each preceding sibling of every checked checkbox using jQuery upon form submission

After extensive research, I discovered that the most effective approach involves using a clever workaround to capture every tick and untick on a dynamic input row with multiple checkbox arrays. However, none of the solutions provided a viable method. I th ...

Ways to manage intricate HTML tables using Beautiful Soup

Currently, I am facing an issue while loading an HTML file into a data frame using BeautifulSoup. The table I am parsing contains a nested table in every row, and I am unsure of how to handle this situation as it is resulting in an AssertionError. The prob ...

Scrollbar in iframe disappears when using Chrome on a Mac computer

In my webpage, I have a full-page iframe that behaves strangely in Chrome. The scroll bar appears initially but then disappears, making it invisible even though the space for it is still there. Oddly enough, it works perfectly on Safari and Firefox as well ...

What are your thoughts on using image maps with CSS?

My images are also links, and the code looks like this: <a href="../www.google.com"><img src="pages/squirrely.png" /></a> While they function properly as links, I want them to only be clickable if you click on the central part of the im ...

Adding a newline character ( ) to each element in the array before converting

Why, when I use JSON.stringify, is appending to the value? Take a look at this example link: http://jsfiddle.net/7nketLmy/ var formData = new Array(); if ($(this).get(0).tagName.toUpperCase() === 'DIV' ){ content = $(this).html(); ...

Utilize dynamic CSS application within an Angular application

In my Angular application, I dynamically load URLs inside an iframe and want to apply custom.css to the loaded URL once it's inside the iframe. I attempted using ng-init with angular-css-injector function in the iframe, but the CSS is not being applie ...

Ways to enhance the resilience of the max-width property when utilizing PHP calls or dynamic CSS styling

I attempted to customize the CSS in page builder mode by adding the following code: #content { max-width: 2000px; } While in page builder mode, the desired effect was achieved. However, once I published the changes, the page reverted back to the prev ...

The CSS ID is being shared throughout the entire website

I'm having some trouble with my website's navigation menu. The style I defined for the id topnav_ubid seems to be applying to other parts of the site, particularly on a:link and a:visited. I only want this style to be applied to the menu itself. ...

How ASP.net can dynamically generate URLs in external CSS files

I have been trying to organize my css separately from the *.aspx file. Everything was working fine when the following code was included in the aspx file: background-image: url('<%=Page.ResolveUrl("~/Themes/Red/Images/Contestant/1.jpg)%>';) ...

Step-by-step guide on generating a canvas with a circle inside whenever a button is pressed

I need help with my code that is supposed to add a new canvas with a circle inside every time a button is clicked. The new canvas should be displayed next to the older ones. Here is my current code: I have two default canvases on the page, and I want new ...

Build interactive web pages using Python scripts

By utilizing the Python scripts provided below, you can generate an HTML file with pre-set global variables (a, b, c, d). However, there might be instances when certain variables are not set globally, resulting in errors like "global 'a' is not d ...

Respond.min.js is specifically optimized for compatibility with IE 8 emulation mode within IE 11

The respond.min.js script seems to only work on Internet Explorer 8 emulation within the developer's mode of IE 11. However, when tested on the actual IE 8, it fails to function without any indication, and in the IE Tester tool, it throws an error sta ...

Can the meta viewport be eliminated using a script?

I currently do not have access to the HTML file on the server side, but I can make changes by adding additional HTML to the website. My issue is with a non-responsive site listed below, which now requires me to zoom in after it loads due to the new viewpor ...