Padding for headlines is not working as intended

I have been working on a website design that features a main heading with a light blue background behind it. I initially used 'padding-right' to create the wide background effect, and applied the background attribute to the class. However, this resulted in only the text being covered with a light blue background without achieving the desired width. I attempted to switch the class to the ID of each headline (#title1, #title2, etc...), but this caused the entire line to be filled with a light blue background, which was too long.

The HTML code looks like this:

<p dir="rtl"><span class="bluetitle"><span style="background-color:#dff2f6">headline<font color="#dff2f6">.</font></span></span><span style="font-family: Heebo, sans-serif; font-size: 1.938em; font-weight: 600;"></span></p>

And here's the CSS:

@media (min-width: 1920px) {
#title1{
padding-right: 27.5% !important;
background-color: #dff2f;
}
}
@media (min-width: 1920px) {
#title2{
padding-right: 21.3% !important;}
}
@media (min-width: 1920px) {
#title3{
padding-right: 37.2% !important;}
}
@media (min-width: 1920px) {
#title4{
padding-right: 23.75% !important;}
}
@media (min-width: 1920px) {
#title5{
padding-right: 26.3% !important;
}}

Despite various attempts, I'm still struggling to achieve the desired look for the light blue background in alignment with the design. Adjusting margin units and aligning titles left did not produce the same effect as shown in the design sample.

If you'd like to take a look at the website, you can find it here.

If anyone has suggestions on how to achieve the same effect from the original design, please let me know! Thanks!

Answer №1

Your current approach seems a bit cumbersome. I have devised a simpler and more adaptable solution for you to better demonstrate how it should function:

To begin with, I positioned the headline next to the paragraph as a sibling element. Then, I utilized the :before pseudo-element for the headline to handle the extending background. This eliminates the need to manually adjust the size of the headline, as the background will automatically adjust accordingly:

body{
  direction: rtl
}
h2 {
  background-color: #dff2f6;
  color: #001a71;
  display: inline-block;
  position: relative;
  animation: do-the-weird-padding-thingy ease infinite 5s;
}

h2:before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  background-color: #dff2f6;
  width: 100vw;
  left: 100%;
}

.container {
  max-width: 90%;
  width: 600px;
  margin: auto;
  animation: show-how-amazingly-flexible-cool-thingy-it-is ease infinite 10s
}

@keyframes show-how-amazingly-flexible-cool-thingy-it-is {
  0% { width: 600px }
  50% { width: 400px }
  100% { width: 600px }
}

@keyframes do-the-weird-padding-thingy {
  0% { padding: 0 }
  50% { padding: 30px 0 }
  100% { padding: 0 }
}
<div class="container">
  <div>
    <h2>This is just a headline</h3>
  </div>
  
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p>
</div>

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

`Changing drop-down menu to display the previously selected item upon page refresh in a Django application`

Is there a way to retain the selected filter in a Django/Python application when a page refreshes after using an HTML drop-down form? Here is the current form I am using: <form name="portfolio_filter" action="" method="get"> <select class="o ...

Having trouble with the "Corrupted @import" error during grunt build?

As I embark on my journey to create my very first Angular application, I have encountered a roadblock. Using Yeoman and angular-generator, everything seemed to be running smoothly with "grunt serve." However, when I attempted to execute "grunt build," the ...

The z-index property of the element is causing it to remain fixed and not

One scenario I'm dealing with involves a container where users can input a value into an input field. As they type, an auto-complete box (an element with the z-index property) appears below the input. When the user hits enter, the input value is saved ...

What is the reason that the CSS3 property name 'filter' is not recognized in Windows 8 applications?

I'm in the process of adapting my own codepen for a Windows 8 desktop app. Everything runs smoothly on Codepen, with the exception of some CSS adjustments from -webkit- to -ms-. However, I encountered an issue regarding this specific line in the CSS s ...

Is there a way to include a cancel order button specifically for guest users in the WooCommerce order details template?

Within our woocommerce order tracking shortcode, the woocommerce order tracking.php file is utilized to track the orders of guest users by order ID and email address. Is it possible to include a cancel order button specifically for guest users within this ...

Guide to pre-populate a text field within a WKWebView on a website with the use of Swift

I am a beginner in the world of coding, specifically with Swift. My goal is to allow users to input their username and password in the settings section, which will then automatically populate the login page on a WKWebView that I have created. Currently, I ...

React element featuring various interfaces

Currently, I am working on styling a React component in a way that allows for either horizontal or vertical styling without using flexbox. My question is, how can I pass styles down to the component in a way that applies individual styles to the child ele ...

Ways to modify the color of text in a hyperlink?

When working with hyperlink generation like the code snippet below, the typical blue color can be less than ideal. How can I dynamically change the font color of this hyperlink using JavaScript? $element.html(indicator.link(url)); ...

Troubleshooting problems with jqplot pie charts

Currently, I am utilizing jqplot to create pie charts. Despite following the example code provided in the jqplot documentation, I am encountering errors such as "e.jqplot is undefined." Below is a snippet of my code: <script src="jquery-2.0.3.js"> ...

Utilizing Selenium IDE and XPath to confirm that a checkbox is selected only when the associated label contains certain text

I need assistance in creating an Xpath query to validate if a specific checkbox is checked within the nested divs of the panel-body div. My goal is to ensure that a checkbox with the label "Evaluations" contains the class "checked". Below is the snippet of ...

In making reference to a particular subpage within a parent page

My website is designed with all inner pages linked to one master file. I'm looking to change the title font size on just one specific page, without affecting the rest of the pages that use the master file. Is there a way to target a specific page titl ...

Deactivating Cluetip tool tips and adjusting the height limit in JQuery

How can I momentarily turn off the hints? I have seen references to being able to do so on the website and in this forum, but I am having trouble locating the command to disable them. I just need to temporarily deactivate them and then enable them again. ...

Wrapbootstrap offers dynamic design options for Java-based web applications

I recently obtained a bootstrap theme from the website wrapbootstrap to use in my Java web application. However, I am unsure of where to begin with it. Despite having already added the bootstrap css to my application, I now wish to remove it and replace it ...

Pass the input array using a jQuery Post request without the need to submit the form

I am looking to send data to a URL without the need to submit a form and reload the page, but my JQuery skills are not very strong. Can someone show me how to achieve something like this in HTML? <input type="text" name="name"> <input type="text" ...

"Upon loading the page, I encounter JavaScript errors related to Angular's ngOnInit function. However, despite these errors,

I have a page in angular where I am loading data in the ngOnInit function. The data loads correctly and is displayed on the page, everything seems to be working fine. However, I am encountering numerous javascript errors in the console stating cannot read ...

Defending Against SQL Injection Vulnerabilities

Greetings everyone! I'm currently working on developing a website that will feature a forum. As part of this process, I've been researching potential security vulnerabilities that could impact the site, such as cross-site scripting and SQL inject ...

Can you please tell me the CSS combinator used for the selectors (foo bar, foo biz, foo tar, foo boo { })?

What is the CSS combination or shorthand for creating this ruleset? foo bar, foo biz, foo gaz > boo, foo tar { ... } I remember seeing on the MDN that there was a shorthand for this. Is it: foo (bar, biz, gaz > boo, tar) { } I am having troub ...

What is the reason for having the navigation bar stretch across the entire width of the mobile device?

NEW QUESTION: How Can I Fix the Navigation Bar Issue on Mobile Devices? I apologize for any language issues as I am using a translator. Hello, I have encountered an issue with a website form containing a price list. When viewed on a mobile device, all the ...

Interactive Canvas Feature: Drag and Drop Across Various Objects in HTML 5

I have developed a custom code that enables the creation and rendering of objects on an HTML5 canvas. class Rectangle extends Shape { constructor(options, canvas, type = 'rectangle') { super(...); // inherited from the super class thi ...

Adjust the width of the dropdown menu to match the text input field using jQuery

Struggling with jquery-mobile to collect user information, I am facing an issue aligning the width of my select menu with the text input fields. Despite successfully matching the background and border colors of the select menu with the text input fields, ...