`Combining a button and text field aesthetically with CSS`

I am working on developing a web forum in Django/Python where users can post quick single-line replies (similar to tweet length) that are visible to all participants. Currently, this is the layout of the simple form:

https://i.sstatic.net/dpk4p.png

What modifications should I implement in my HTML/CSS to achieve the following form layout instead:

https://i.sstatic.net/MklfZ.png

I am seeking a completely responsive solution that works seamlessly across all browsers, utilizing pure CSS.


This is my current code snippet:

<form method="post" action="{% url 'home_reply' pk=link.l %}">
    {% csrf_token %}
    {{ replyform.description }}<br>
    <button type="submit">Submit</button>
</form>

Please disregard the {{}} syntax as it pertains to Django's template language.

Answer №1

To achieve a similar outcome, my approach is to enclose both elements within a container

<div class="fancy-box-with-button">
  <input type="text"/>
  <button>Submit</button>
</div>

Next, transfer all styling for the <input> to the .fancy-box-with-button class and set the <input> to be transparent, making any other necessary tweaks accordingly.

Position the button with position: absolute on the right side, ensuring to add sufficient padding-right to the parent element to avoid overlapping the invisible input.

The final appearance would likely resemble this:


.fancy-box-with-button {
  background-color: white;
  border-radius: 4px;
  margin: 10px;
  display: block;
  position: relative;
  height: 30px;
  box-sizing: border-box;
  padding-right: 100px;
}

.fancy-box-with-button input {
  height: 100%;
  width: 100%;
  border: none;
  margin: 0;
  background-color: transparent;
}

.fancy-box-with-button button {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0;
  height: 100%;
  width: 100px;
  border: none;
  color: white;
  background-color: blue;
}

Check out a working example here

Answer №2

Check out the JSFiddle demo here
For optimal responsiveness, it is recommended to eliminate the width: 1000px style attribute as it can cause the text field to appear too wide and hinder its adaptability on different devices.

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 are the steps to position a group of elements at the bottom of the page?

I am trying to align a list of elements at the bottom of a container, but by default they are positioned at the top. It's important that this list retains its scrolling functionality, so using flexbox is not an option. Flexbox causes elements to resi ...

Different sizes of CSS tables

Creating a responsive layout involves displaying <div> boxes within a grid: The six individual boxes on this page are placed in a row within the HTML source: <div class="control"> <div class="controlContent"> <a>VARIABLE-HEIGHT CO ...

Increase the height of the div element by a specified number of

Is there a way to dynamically expand a div's height using CSS without knowing its initial height? I want to increase the height by a specific amount, such as "x px taller" regardless of its starting size. For example, if the div starts at 100px tall, ...

Is it possible for data attributes to start with a number? For example, can a data attribute be like data-1234=""?

While I understand that identifiers cannot start with numbers or hyphens, I am curious if the same rule applies to data attributes. Would there be any issues with using data--=""? (I have no intention of doing so, just wondering) ...

Adjusting the style attributes for Material-UI Icons

I could use some assistance with changing the CSS property of MUI icons in order to assign a specific color when the icon is focused. I have implemented the icons in the header and am displaying different pages below them, so I would like to give each ac ...

Utilizing Selenium for the Upload of an APK Document

I've encountered an issue during my test. I'm attempting to upload an APK file, but the process seems to halt at that stage. My attempts with simple sendKeys using the file path and an AutoIT script have both proven unsuccessful. Below is my in ...

Submitting the form with a target of _blank will result in the form being submitted on both a

I am currently working on a form that includes both a "Submit" button and a "Preview" button. While the submit button is functioning correctly, I am experiencing an issue with the Preview button. When clicked, it opens up a new page with the preview as in ...

Creating a bootstrap carousel configuration

I recently encountered a problem while using a single bootstrap carousel. The carousel contains multiple items/images to display, with one of them needing to be active initially. Below is the code snippet: <div id="myCarousel" class="caro ...

What is the best way to send an email with a randomly generated HTML output using a <button>?

I am currently working on a feature where a random HTML output is sent to me via email whenever a user clicks on a button on the website page. The user receives a code when they click the button, and I want that code to be emailed to my address automatical ...

What could be the reason for the Javascript function failing to run?

I need assistance in executing a function called "send()" which includes an AJAX request. This function is located in ajax.js (included in the code snippet) The Ajax success updates the src attribute of my image. The function seems to be working correctly ...

Techniques for adding multiple elements in a grid system while ensuring responsiveness

Looking for guidance on designing a responsive screen using the Bootstrap-4 grid system for web development. Here's an image of what I'm aiming to create using rows and columns: View the grid picture here Code snippet: <div className="row"& ...

Rearrange the order of all elements following a specific li element to the beginning with the help of

How can we rearrange elements in a ul list using jQuery after selecting a specific li element? For example, moving all elements after the third li to the beginning. <ul> <li>1</li> <li>2</li> <li>3</li> <li>4 ...

What is the best way to incorporate external HTML content while ensuring HTML5 compatibility? Exploring the different approaches of using PHP, HTML

While this may seem like a simple task to the experts out there, I have been struggling for over an hour without success... My objective is to use a single footer file and menu file for all my webpages while considering blocking, speed, and other factors. ...

How can I successfully use the Confluence REST API to publish a dynamically generated HTML table (created with PHP) without encountering the problematic HTTP

I am striving to build a page within a Confluence wiki that contains a table created using the provided REST API, which can be conveniently edited by wiki users using the WYSIWYG editor once the page is established. To achieve this, I have organized vario ...

Updating a <div> using Ajax while also transmitting a counter variable

In my possession are two .php files. The initial file, named ajax_testing.php, is structured as follows: <!DOCTYPE html> <html> <?php $index_local=1; $_SESSION['global_index'] = $index_local; ?> <head> <script ...

Any ideas on how to create a fading effect for a background image while scrolling using jQuery?

I am looking to create a fading background image that changes as I scroll down my page. I remember seeing something similar with two divs that fade using opacity. It looked like this: <div class="background1"></div> <div class="background2 ...

When bootstrap is imported, SVG is displayed with a square background

The combination of reactJS and bootstrap has caused an unexpected issue for me. After importing bootstrap, strange squares have started to appear behind my SVG images... https://i.sstatic.net/4vmP8.png Is anyone familiar with what is causing this and ho ...

Tips on eliminating expansion upon button click in header within an Angular application

While utilizing Angular Materials, I encountered a challenge with the mat-expansion component. Every time I click on the buttons within the expansion panel, it closes due to the default behavior of mat-panel. Requirement - The panel should remain expanded ...

Do mouse users prefer larger buttons on RWD sites for a better experience?

Not entirely certain if this platform is the most suitable for posing this query, so if warranted, please close it and recommend a more appropriate venue for such inquiries. In the realm of responsive web design (RWD) today, it is common practice for webs ...

What is the best way to ensure that bootstrap columns collapse in equal multiples?

I need to have 4 equal columns in each bootstrap row with only specific configurations allowed: All 4 next to each other Two above and two below All in a single column The issue is that when I adjust the screen size, sometimes I get 3 columns at the top ...