Arranging H1 Styling with CSS for Optimum Alignment

My issue revolves around a DIV tag adorned with a background image:

<a href="#">
  <div class="pagebar jquery">
    <h1>JQuery Demonstrations</h1>
  </div>
</a>

The CSS applied to this element is as follows:

.pagebar {
left: 0%;
right: 0%;
height: 200px;
border:1px solid black;
clear: both;
text-decoration:none;
font-size:x-large;
-webkit-filter: blur(0px);
filter: blur(0px);
margin-top:20px;
}
.pagebar:hover {
border:1px solid black;
-webkit-filter: blur(1px);
filter: blur(1px);
}

My aim was to align the text 'JQuery Demonstrations' to the right side of the background image. However, when attempting to adjust the code in the jquery class like so:

.jquery {
background-image: url(file:///C|/Users/James/Desktop/Website/Images/JQuery.jpg);
background-repeat:no-repeat;
background-size: 70% 100%;
background-position:left;
}
.jquery h1 {
width: 40%;
position:relative;
top: 5%;
bottom: auto;
right: auto;
left: 50%;
}

Using the values 'left: auto' and 'right: 10%', the text ends up disappearing off the left side of the div. Is there something I am overlooking or perhaps formatting incorrectly? I've experimented with adjusting the width since it initially filled the whole div width, however, no visible changes have occurred.

Answer №1

The h1 element is a block-level element that automatically spans the entire width of the window. Applying position: relative does not alter this default behavior.

Therefore, shifting it to the left by adjusting the right property, even if only by a small percentage like 10%, will cause it to extend partially beyond the window boundaries. The right property affects the entire block rather than just the right side. In simpler terms, setting right: 10% has the same effect as left: -10% on a block with relative positioning.

If your objective is solely to have the text aligned to the right side of the window, using text-align: right would be sufficient and eliminate the need for positional adjustments. However, if you wish for the text to appear completely on the right side of a background image, you can set left: 70% and width: 30%. Keep in mind that the text size may prevent it from fitting within the allotted 30% width, causing overflow beyond the window borders.

.pagebar {
  height: 200px;
  border: 1px solid black;
  clear: both;
  text-decoration: none;
  font-size: x-large;
  margin-top: 20px;
}
.pagebar:hover {
  -webkit-filter: blur(1px);
  filter: blur(1px);
}
.jquery {
  background: url('http://lorempixel.com/1000/200') no-repeat;
  background-size: 70% 100%;
  background-position: left;
}
.jquery h1 {
  position: relative;
  left: 70%;
  width: 30%;
}
<a href="#">
  <div class="pagebar jquery">
    <h1>JQuery Demonstrations</h1>
  </div>
</a>

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

What steps should I follow to utilize my spotify api token effectively?

Currently, I am working on developing a random playlist generator using the Spotify API. However, when I retrieve information from their server, I receive a 401 error code. I have managed to obtain an access token by following a tutorial. My main concern ...

Centering a div and span horizontally with an input child

I am looking for a way to automatically add a # before a hex color code in an input field and center both the div and span containers horizontally: <div id="color_wrapper"> <span>#<input type="text" value="ffffff"></span> & ...

Footer stays put as you scroll, peeking out from behind the main content

I'm trying to replicate the sticky-footer effect that can be seen on the website From what I understand, the footer needs to be fixed in place. The content should have a higher z-index. It seems like the body may need a margin-bottom equal to the ...

What techniques can I implement using JavaScript or CSS to create a slightly transparent effect on my text?

I am currently developing a website that features changing background images. I am looking to have the text on the site mimic the color of the backgrounds, but not so much that it becomes difficult to read. How can I make the text transparent in this man ...

retrieve the position of a descendant element in relation to its ancestor element

I'm encountering a challenge while attempting to solve this issue. I have elements representing a child, parent, and grandparent. My goal is to determine the offset position of the child (positioned absolutely) in relation to the grandparent. However, ...

Unveiling the Mystery: Java Tips for Capturing the Chosen Value from a DropdownChoice in Apache W

In my Java class, I created a method where I instantiate a DropDownChoice object for a select menu and add it to the form. Within this method, I am populating the projects list into the billableProjectsList. public class ReportCriteria implements Serializa ...

What could be causing me to receive null when trying to retrieve an element with document.getElementById, even after invoking $(document).ready(function() { ... })?

Here's a small example. I'm feeling a bit rusty with JavaScript, as it's been some time since I last worked with it. The problem I'm encountering is an error in Chrome developer tools: "Uncaught TypeError: Cannot set property 'src ...

Accessing JS code from HTML is not possible in React

Attempting to create a list using React, I have utilized the module found here: https://github.com/pqx/react-ui-tree I am currently testing out the sample application provided in this link: https://github.com/pqx/react-ui-tree/blob/gh-pages/example/app.js ...

Utilizing various z-index values for multiple background images in a single CSS class

My approach may be completely off. I am in the process of building a website using sliced images from a .PSD file created by a graphic artist. Essentially, the background image consists of 4 green bars angled at 45 degrees slightly intertwined with 3 blue ...

The CSS slideshow is malfunctioning when displaying images retrieved from the database

I received a complimentary website layout to enhance my PHP skills. The website originally had slides on the index page, sourced directly from my computer when it was in index.html. However, now I have modified it to retrieve images from a database. Instea ...

How to specifically exclude a checkbox from the "select all" function in J

One way to select all checkboxes with HTML code: Select All <input type="checkbox" name='select_all' id='select_all' value='1'/> To achieve this with Javascript code: <script type="text/javascript> $(&apos ...

Unlocking the potential of Bootstrap 4 pop ups and modals within an Angular 6 project

Angular.json "styles": [ "./node_modules/bootstrap/dist/css/bootstrap.min.css", "./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "src/styles.css" ], ...

small screen right-side navigation with Bootstrap 4

My goal is to have the logo image on the left and the navigation on the right for xs devices, and the logo in the center with navigation on the left for sm devices. However, I am facing an issue where the navigation does not align to the right on xs device ...

Do not make unnecessary calls to the server when changing the display property of an HTML object

How can I prevent a server request for the pdf file? I've experimented with using visibility=hidden and width=0. <object class='pdfClass' data='"+conventionId+"/showPdf.html' width='100%' height='600'>< ...

Scaling down a retina image sprite using CSS: A step-by-step guide

Struggling with loading retina images? You're not alone. Many web developers face the challenge of scaling down high-resolution images effectively. Take, for example, two image sprites: one normal and one retina. The issue arises when you need to adju ...

How to access the CSS and JS files in the vendor folder using linemanjs

Currently, I am in the process of developing a web application utilizing linemanjs. However, I have encountered an issue where the vendor css and js files are not being referenced correctly when explicitly included. I would appreciate any guidance on what ...

difficulties switching content between different screen sizes

Having trouble with hidden-xs and visible-xs-* classes not working as expected. Even a simple code snippet like the following doesn't hide the content: <div class="hidden-xs"> test test test </div> Even when scaling down my window to ...

The close button on the modal vanishes on a real iPhone

The issue I am facing is that the Close Button appears when testing responsiveness in Chrome, but disappears on a real iPhone. When clicking on an image, the image gallery should appear. However, on an iPhone, only the previous and next buttons are visibl ...

The hyperlink is not functional

I'm embedding PHP code within an HTML page and using an href link, but it's not working. Here's the HTML+PHP code snippet: <div class="panel-body"> <div class="row"> <div class="col-md-12 space20"> & ...

The table in React does not update after sorting the elements in the state, causing the list to not re-render

I'm encountering a problem with React where the data is not rendering properly after sorting the table. Even though I am updating the state variable using setState, the new updated data does not appear on the screen. Here's the snippet of my code ...