Attempting to shift an element without relying on the use of position:relative

I'm trying to figure out if I can relocate this (image1) to (image2). I prefer not to utilize position:relative as it may disrupt my design in bootstrap.

Image 1 (I don't want it here)

Image 2 ( I want it here)

Here is the relevant CSS code:

  .results {
        color: red;
        display: block;
        font-size: 20px;
        text-align:center;
        text-decoration: none;
        font-weight: bold; 
        background: #232323;
        color:red;
        font-family: 'Julius Sans One', sans-serif;
        font-size: 150%;

        }

Thank you for your help! :)

COMPLETE CODE UPDATE:

<?php
 session_start();
include ('../includes/config.php'); 
include ('../includes/header.php'); 
?>

<!DOCTYPE HTML>
<html>
... (Full code continuation with website structure)

Answer №1

If you're comfortable with css 3, have you considered using the "translate" transformation?

For example:

.results {
  ...
  transform: translate(0px,-200px); 
}

You may need to adjust the value instead of -200px.

Update:

Upon reviewing your code.

Have you thought about placing the "php" section where you want the error message to appear?

Update 2

Here is a revised code snippet based on OP's original code as recommended by @Moob.

<?php
 session_start();
include ('../includes/config.php'); 
include ('../includes/header.php'); 
?>

<!DOCTYPE HTML>
<html>
<body>
<!--start header-->
...
    </form>
    </div>

    </div>
     </ul>
    </div>
    <div class="clear"></div>
</div>
</div>
</div>
</div>
<!-- start content -->
...
        </div>
        </div>
        <div class="clear"></div>
    </div>
</div>
</body>

Answer №2

To enhance your design, you might want to use css :after pseudo-selector

Check this link for more information

.search1::after { 
    color: red;
    display: block;
    font-size: 20px;
    text-align:center;
    text-decoration: none;
    font-weight: bold; 
    background: #232323;
    color:red;
    font-family: 'Julius Sans One', sans-serif;
    font-size: 150%;
    content: "your content here";
}

You can control the visibility of the element using JavaScript based on PHP response.

Here is a sample code snippet:

.search1::after {
  display:block;
  content:attr(data-content);
}

<?php
 session_start();
include ('../includes/config.php'); 
include ('../includes/header.php'); 
?>

<!DOCTYPE HTML>
...
... (remaining code as it is)
...
</body>

Answer №3

To seamlessly integrate the div within a form, simply position it as desired, assign an id, and hide it using CSS. Then, within the else section of your code where you typically display the div by echoing it, step out of PHP and utilize JavaScript to reveal the div in case of an error. For example:

else{ ?>
      <script>document.getElementById("your_chosen_id").style.display="block";</script>
      <noscript><div class='results' style='position:relative;top:-200px;'>Invalid username or password</div></noscript>
<?php

EDIT

An additional noscript tag has been included, acknowledging that this method may not function correctly with JavaScript disabled.

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

Troubleshooting: Why isn't my CSS fixed position working for my sticky

I have a simple jQuery code snippet that is supposed to make the navigation element sticky by applying a class with position: fixed. However, I'm facing an issue on my Commerce platform where the fixed position property doesn't seem to work corre ...

Unleashing the Power of the "OR" Operator in Form Field Validation

The custom JavaScript function FormQuote_Validator is used to validate form fields. It should return the value "TRUE" and display an alert message if all three input fields are submitted without any numbers; otherwise, it should return the value "FALSE". ...

Disappearance of logo div causes video to vanish

Hey there fellow coders! I'm facing a little issue. I'm attempting to replicate my webpage on another page, but every time I try to remove the logo, the video disappears as well. It's quite puzzling. I have the code in place, but it seems l ...

A guide to automatically playing audio on a webpage using HTML and JavaScript

I'm currently in the process of developing a quiz application, and my goal is to have a sound play when a user enters the webpage to initiate the quiz. Initially, I attempted to use JavaScript to trigger the sound on page load, but unfortunately, the ...

There is a property name missing before the colon in the "(property) : (value)" declaration for a CSS global variable

I have been trying to create a global variable in CSS by following the suggestions I found online. According to various sources, including this article, the correct way to declare a CSS variable is as follows: :root{ --variableName:property; } However, ...

Ways to insert text inside a border

I'm struggling to figure out how to insert text within a border. Can someone guide me on how to accomplish this? Is there a way to place text in the center of a border? I have included a screenshot for reference. ...

A dynamically-generated dropdown element in the DOM is being duplicated due to JavaScript manipulation

Currently, I am dynamically adding a dropdown element to the page using javascript. The goal is for this dropdown to modify the properties displayed on a map. However, when attempting to add the element after the map loads, I encounter an issue where the d ...

What is the best way to strip the text from a link that encompasses both text and an image using jquery?

I have a website with a list of items. Each item in the list has a link that includes both text and an image. Here is an example of the HTML structure: <li class="li-one" style=""> <a href="#" onclick="return ...

Displaying text underneath an image

Hey everyone, I'm currently working on getting some text to show up below an image using Bootstrap 3. Here's what I have so far: <div class="row"> <div class="col-xs-12 col-sm-6 col-md-3"><img alt="my image" class="img-about" ...

How can I change the names of links containing question marks?

In the past, I would rename links by adding a question mark at the end of them, for example: LinkName.mp4? to Anything I want.mp4 This method allowed me to download the file with the desired name "Anything I want" instead of the original "LinkName"... U ...

Prevent floating labels from reverting to their initial position

Issue with Form Labels I am currently in the process of creating a login form that utilizes labels as placeholders. The reason for this choice is because the labels will need to be translated and our JavaScript cannot target the placeholder text or our de ...

WordPress WooCommerce causing the right bar to be pushed below

I'm currently facing an issue on my WordPress site with a purchased template and Woocommerce integration. The problem lies in the fact that the right sidebar gets pushed down on the shop page. When I reached out to the template developers, they sugges ...

implementing a fixed header in HTML

I am facing a challenge where I have a header with dynamic height and fixed position. My goal is to position the container div right below the header. However, since the header height varies, using a fixed value for margin-top is not feasible. Any sugges ...

The jQuery plugin embedded in the Joomla 3.2 module fails to load or function properly

Seeking help with a JavaScript issue on my Joomla website. I'm not an expert, so please bear with me. I am using a regular plugin (not a Joomla specific one) to display my portfolio. It should work like this: ... black.html This is how it shouldn&a ...

Having difficulty achieving the hover transition effect

I've been working on a navbar design and I'm having trouble getting the hover effect to work on the links. Specifically, I am trying to add a transform property to the after element of the links but it doesn't seem to be taking effect. #navb ...

Is there a way to retrieve the dates from last month using jQuery?

Currently, I am unable to select past dates with the provided code. How can I adjust it to allow for selecting dates from previous months? let firstDay = new Date(); $('#date_filter_startmonthly').datepicker({ startDate: firstDay, endDate: ...

"Retrieve data from an Excel file and either present it in a textarea or store it as an array

Is it possible to use JavaScript to read an Excel file and convert a single column (identified by name or index) into an array in JavaScript? ...

Is there a way to manipulate the appearance of a scroller using JavaScript?

I'm intrigued by how fellow front-end developers are able to customize the scrollbar shape on a webpage to enhance its appearance. Can anyone guide me on using JavaScript to accomplish this? ...

Transform HTML into PDF while maintaining the original letter spacing

We are in need of converting numerous files to enable search and word highlighting functionality in a web browser, as well as server-side indexing for the searchable words. I have previously utilized an online service like (Step 1, Step 2 on linked page) ...

Mastering the art of extracting elements from an HTML Dygraph

Attempting to extract all data points from this particular website utilizing BeautifulSoup and requests in Python. The current code in progress is as follows: session = requests.Session() page = session.get(https://bitinfocharts.com/comparison/bitcoin-tra ...