Styling button with CSS to change its position

Can you help me position a button next to a textbox using CSS?

Here is the HTML code:

  <div data-bind="text:name" class="my-name"></div>
  <div id="wrapper">
  <input class="my-input"/>                   
  </div>             
  <div data-bind="dxButton: { icon: 'user' }"></div>

This is the CSS code I used:

.my-name{float:left;color:#fd9802;position: absolute}
.my-input{margin:0 auto 0 30%;display:block;}

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

Answer №1

Utilize CSS in the following way, eliminate auto and adjust the right margin accordingly:

.my-name{float:left;color:#fd9802;}
.my-input{margin:0 0 0 30%;display:block;}

Answer №2

To ensure proper alignment, the float property should be set on elements at the same level (e.g. apply it to the wrapper rather than the input) and on every element individually (including buttons).

.my-name {
  float: left;
  color: #fd9802;
}
#wrapper {
  margin: 0 auto 0 30%;
  float: left;
}
.my-button {
  float: left;
}
<div data-bind="text:name" class="my-name">Name</div>
<div id="wrapper">
  <input class="my-input" />
</div>
<div data-bind="dxButton: { icon: 'user' }" class="my-button">Button</div>

Answer №3

.your-name{float:right;color:#f78002;position: fixed}
.your-input{margin:0 auto 30% 0;display:inline-block;}
 #container{display: block;}

Answer №4

To target the div that comes directly after the wrapper div, you can use the + selector in CSS

div#wrapper + div{
    /*add your CSS code here*/
}

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

Manipulate CSS classes according to the attribute value of a button

Is there a way to change the icons on a navigation button based on an attribute value using jQuery? I have a button that expands and collapses the navigation menu, and I want to toggle between left arrows and right arrows icons. I thought of achieving this ...

Unable to retrieve the data from HTML buttons in Django view

Here is the original HTML code with "radio" buttons: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" integrity="sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyM ...

Is it possible to receive real-time updates for a specific location in Cesium

I am currently developing a live tracking application using Cesium, and I'm encountering an issue with updating the point location on the map in real-time. Currently, my Cesium viewer successfully receives the data from the server in JSON format and ...

What is the best way to enlarge an image on a webpage so that it is twice its original size?

I have a photo that is 320 x 240 pixels in size, and I want to enlarge it to 640 x 480 pixels when displaying it on a webpage. In the past, I used to achieve this by setting width=640 on the img tag. However, recently I came across the following informati ...

Searching for specific values within data attributes using jQuery wildcards

I am currently utilizing the data_attribute on this page and have the following elements with data attributes. No. 1.<div class="row hidden" data-party-registration-source-type-id="1"> 2.<div class="row hidden" data-party-registration-source- ...

Are you making alterations to the URL?

Is there a way to change the displayed URL on a webpage to show "bananas" instead of "http://example.com/" after the page has loaded? ...

What is a method for choosing information from a webpage without relying on the written words?

Is there a way to select and click the blog title without relying on the text, which can change frequently? Unfortunately, I don't have an "li" tag, so my previous methods aren't working in this scenario. Any assistance would be greatly appreciat ...

Tips for creating a mobile-friendly website with Twitter Bootstrap

Having an issue with my site on mobile devices while using Twitter Bootstrap. The header is not displaying correctly when I resize the window, it appears like this: It should look consistent across all devices as shown below: Below is my HTML code: ...

Using inline CSS to apply conditional styles to a component in React is a great way to customize the

I'm currently working on customizing the styles of some buttons depending on their 'active' status and whether the user is hovering over them. So far, it's partially working but I'm encountering behavior that I can't fully com ...

Utilizing local storage functionality within AngularJS

I've been encountering challenges while trying to integrate local storage using ngStorage in my ongoing AngularJS project. Despite fixing what seems to be the root cause of data type problems and errors during debugging, issues persist. Here is the P ...

Error: The selector "html" is not considered pure as it does not contain any local class or id. Pure selectors must include at least one local class or id

When working on my Next.js project, I included the following code in _app.js: import '../src/styles/style.module.scss'; import '../src/styles/main.module.scss'; This is the content of main.module.scss: // ./src/styles/main.module.scss ...

Navigating using JavaScript dot notation is a powerful way to

Is there a way to implement JavaScript or jQuery code that will assign an active class to a dot when it is clicked, while also removing the active class from any other dots in the sequence? HTML: <div class="dotnav"> <div class="dot active" ...

Fade between two elements using jQuery

Can someone assist me with adding a fade effect between elements in my code? Any advice or suggestions would be greatly appreciated! $("#example p:first").css("display", "block"); jQuery.fn.timer = function() { if(!$(this).children("p:last-child").i ...

What is the best way to link a .css file in handlebars when setting /public/css and /public/img directories as static?

I'm struggling to get my handlebars file to access my .css file. Here's how my current folder structure looks: root public css base.css (css file) img ping.png (image file) To make the /public/img and /public/css folders ...

Slider with a progress bar

Have you ever wondered if it's possible to create a progress bar using an input range? Imagine someone entering a number and the bar moves to the right, changing its background color on the left side of the thumb based on the size of the number. Check ...

Having trouble with the visibility of the hover background?

I have a goal in mind: This is the outcome I've achieved so far: LINK My aim is to have a white background with a blue border appear at the bottom when hovering over navigation links. Unfortunately, this isn't happening as expected. Can anyone ...

Exploring ways to transfer a function variable between files in React

Currently, I am working on a quiz application and have the final score stored in a function in app.js. My goal is to generate a bar graph visualization of the user's results (e.g. 6 right, 4 wrong) based on this score. To achieve this, I created anoth ...

The problem of Angular material toolbar's erratic height issue

Currently, I am using angular material version 1.1.0-RC.5 which involves a simple toolbar creation. <md-toolbar> </md-toolbar> However, there seems to be an issue when the browser width is less than 960px - the toolbar's height changes t ...

Prevent horizontal scrolling and bouncing on iOS devices without using overflow hidden

I've been on the lookout for a way to stop horizontal scrolling/bounce effect on iOS, but my search has been in vain. It's quite surprising that there doesn't seem to be a solution out there. Unfortunately, setting overflow hidden is not an ...

Creating a dynamic 2x2 grid with centered responsiveness in Angular Ionic framework

I'm having trouble achieving a 2 x 2 grid that is centered on my screen. The code snippet below shows what I have so far in the HTML file. Just to provide some context, this project is meant for a native mobile application. <ion-header> <i ...