The button adjacent to my input consistently appears beneath the input field

I am currently working on a blog that consists of entries. I have included a form with hidden variables to delete posts by submitting the entry ID and other data. However, I am facing an issue where the delete button always displays below the entry instead of alongside it.

To resolve this problem, I attempted using CSS Clear and consolidating all elements within a single <p> tag, but without success. It appears that the presence of a form with hidden variables is causing the misplacement, yet I am unsure of how to rectify this issue.

 <div id="subformposts">
    <?php echo $subentry['Body']; ?>
    <?php echo $subentry['CreateDate']; ?> - <?php echo $subentry['UserName']; ?><br />

<!-- Determine whether to show the delete button -->
<form action="Delete_entry.php" method="post" id="Deletesub<?php echo $subentry['EntryID'];?>" onsubmit="return confirmdelete('Deletesub<?php echo $subentry['EntryID'];?>')">     
        <input type="hidden" readonly="true" name="EntryID" value="<?php echo $subentry['EntryID']; ?>" />
        <input type="hidden" readonly="true" name="UserID" value="<?php echo $subentry['UserID']; ?>" />
        <?php if ($userid == 1 || $userid == $res['UserID']) { ?>
        <input type="image" src="redx.png" alt="Delete Post" id="btnDelete" value="Delete Post" />
    <?php } ?>
</form>
</div>

I aim to reposition the delete button to float to the right side of my entry (or even to the left). It would be ideal if I could nestle it within the div container seamlessly.

Answer №1

To achieve a desired layout, you can apply the CSS property display: inline-flex to the subformposts element.

Here is an example:

<div id="subformposts" style="display: inline-flex;">
<?php echo $subentry['Body']; ?>
<?php echo $subentry['CreateDate']; ?> - <?php echo $subentry['UserName']; ?><br />

<!-- Determine whether to show the delete button -->
<form action="Delete_entry.php" method="post" id="Deletesub<?php echo 
$subentry['EntryID'];?>" onsubmit="return confirmdelete('Deletesub<?php echo $subentry['EntryID'];?>')">     
    <input type="hidden" readonly="true" name="EntryID" value="<?php echo $subentry['EntryID']; ?>" />
    <input type="hidden" readonly="true" name="UserID" value="<?php echo $subentry['UserID']; ?>" />
    <?php if ($userid == 1 || $userid == $res['UserID']) { ?>
    <input type="image" src="redx.png" alt="Delete Post" id="btnDelete" value="Delete Post" />
<?php } ?>
</form>
</div>

An alternative option is to place each content section in separate div elements and set their styles to display:inline-block. Here's how you can do it:

<div id="subformposts" style="display: inline-block;">
 <?php echo $subentry['Body']; ?>
 <?php echo $subentry['CreateDate']; ?> - <?php echo $subentry['UserName']; ?><br />
</div>
<div style="display: inline-block;">
<!-- Determine whether to show the delete button -->
 <form action="Delete_entry.php" method="post" id="Deletesub<?php echo 
 $subentry['EntryID'];?>" onsubmit="return confirmdelete('Deletesub<?php echo $subentry['EntryID'];?>')">     
<input type="hidden" readonly="true" name="EntryID" value="<?php echo 
$subentry['EntryID']; ?>" />
<input type="hidden" readonly="true" name="UserID" value="<?php echo 
$subentry['UserID']; ?>" />
<?php if ($userid == 1 || $userid == $res['UserID']) { ?>
<input type="image" src="redx.png" alt="Delete Post" id="btnDelete" value="Delete Post" />
<?php } ?>
</form>
</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

Step-by-step guide on embedding a function in HTML using vbscript

I'm working on a dynamic HTML list that I want to enable or disable based on user input. Typically, you can just use the "enabled" or "disabled" attribute at the end of the select element to control the entire list. However, I'm unsure how to ach ...

What is the best way to create a view that caters to both administrators and regular users?

Currently, I am developing a system in Django which displays different fields and options based on whether the user is an administrator or a Jefe from the table. The administrator can access the panel in Django. class UsuarioCrear(SuccessMessageMixin, Crea ...

Troubleshooting varying <li> heights in Google Chrome with CSS

Kindly review the image enclosed below ul li{ width:100px; height:200px; float:left; border:10px double #333; -webkit-border-radius: 10px; -moz-border-radius: 10px; } <ul> <li><a href="image.jpg"><img src ...

Numerous toggles available for the mobile version

Hey there, I need some help! I have a footer navigation on my desktop website with 3 Ul elements. I want to turn each Ul into a toggle for the mobile version. Can anyone assist me with this? Thanks in advance! <footer class="footer"> <d ...

Why must the sidebar be displayed horizontally on the smartphone screen?

I've been struggling to make the sidebar menu on my smartphone display horizontally with icons at the top and text at the bottom. I've tried using flex and other methods, but it still doesn't work sideways. Am I missing something? const s ...

Tips on positioning an image at the center of an HTML page

When designing a website, I encountered an issue where only a portion of the image was displaying in the slider due to the fixed height of the div being set to 500. I want the full image to be displayed centered within the same height. <div id="myCar ...

Is there any benefit to making the SVG elements width and height 100%?

The Angular Material documentation app features an SVG Viewer that is able to scale the SVG content to fit the container using the following function: inlineSvgContent(template) { this.elementRef.nativeElement.innerHTML = template; if (this.sca ...

Customizing the Bootstrap navbar background to remain consistent, despite attempted changes

https://github.com/cooperlappenbusch/coopernaumwebsite Struggling with the navigation bar in Bootstrap - I mainly work on programming and am new to Bootstrap. I'm having difficulty finding a solution to my problem as most of the resources I've c ...

Styling select tags in Rails with options_from_collection_for_select using CSS

I need help with a form_tag in Rails. Here is the code snippet: <%= form_tag(listings_path, method: :get) do %> What <%= text_field_tag :title, "",class: 'form-control' %> Category <%= select_tag(:cat ...

Tips for implementing a search filter in a select dropdown menu using Angular

I am attempting to enhance my select option list by including a search filter. With numerous options available, I believe that having a search function will make it easier for the user to locate their desired selection. I hope my message is clear despite ...

Tips for implementing a sliding list feature with next and previous buttons:

Currently, I am utilizing a list attribute to display thumbnail images of a YouTube-generated playlist (gdata feed). However, my goal is to enclose the list within a div container and implement next and previous buttons to slide through the playlist images ...

How can one ensure that the column width in a Datatable adjusts dynamically based on the content within?

My data table creation code looks like this: var Master = $('#MasterGrid').DataTable( { "data": response, "columns":columns, "scrollX": true, }); $('#Mas ...

Enhancing your website with HTML5 Audio Player's Next and Previous functionalities

I've successfully created a playlist that is working, but I'm struggling to make the Next and Previous Buttons actually move forwards and backwards in the playlist. It seems like using the playNext function when next is clicked might work, but I ...

Using the "unicode-range" property for numerical values

Having incorporated a custom font using @font-face, I am attempting to showcase text in two different languages on a webpage with distinct fonts utilizing the font-face at rule in CSS and employing the unicode-range property. While the text appears corre ...

Tailwind configuration is failing to export complete CSS styles

I have been attempting to integrate the entire Tailwind 3.0 CSS library into a new Laravel 8.* project in order to utilize the corePlugins feature to eliminate unwanted styles. Despite setting everything up quickly, I am only seeing the basic styles publis ...

CSS for arranging products in varying sizes of divs to create a structured layout

Hey there! I'm looking to showcase my products in a similar layout as the one in this image. However, I'm struggling with figuring out how to apply different sizes to each div containing product information. Are there any CSS or jQuery plugins a ...

Is it common practice to create a gap between columns by inserting an empty col-md-1 in Bootstrap?

<div class="row justify-content-center"> <div class="col-md-4"> Displaying Column with a width of md-4 </div> <div class="col-md-1 .d-sm-none"> <!-- Creating a gap betwee ...

The alignment of the label on the Watu Quiz does not match with the Radio Button

I've encountered an issue with a Watu quiz I created where the labels are not aligning with the radio buttons. Any suggestions on how to style this and fix the alignment? You can view the page here. Here is a screenshot for reference: https://i.sst ...

The AddClass function does not work properly in the Kendo Tree View after the RemoveClass function, especially when selecting the same node

Hey there, I am currently working with a kendoTreeView and trying to set up an action triggered by clicking on the same selected node. To achieve this, I incorporated the following code in the change event: change : function(e) { $ ...

Selecting CSS tag excluding the first-child element

My goal is to use CSS to target the li elements in a list that do not have a description and are not the first-child with a b element. I want to apply padding-left to these specific li elements that do not have a title. <ul> <li><b>t ...