Enhanced emphasis on user input with Bootstrap animation

I am just starting out as a web developer and I'm currently working on a project using Bootstrap 4.

Here is the HTML code I have:

Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque 03 Baza wiedzy

And here is the CSS code:

.boxes .box3 {
  background-position: center;
  background-size: cover;
  background-image: url("/img/slide3.jpg");
  color: white;
  height: 872px;
}

...

.boxes-show-search-ico {
  cursor: pointer;
}

.boxes .border-3 {
  border-width: 3px !important;
}

Here is a preview of my work: https://ibb.co/wB4qht5

However, I am facing a small issue with my input field.

I want to create an animation for the input field when it's in focus, where the text "czego szukasz" should appear after clicking on the input field. It should behave similar to this example: (imie, nazwisko, numer telefonu, etc).

Can anyone guide me on how to achieve this effect?

Answer №1

If you want to implement a "floating" label effect, you can make use of CSS3 transitions by setting the position of your <label> element to absolute. This will allow the label to move and scale when the input is focused or valid. You can also use a simple script to check if the inputs are not empty and add a class instead of relying solely on CSS pseudo classes (which cannot achieve this functionality using pure CSS). Make sure to wrap both your <input> and <label> elements in a container with its position set to relative, similar to what was done in the example provided.

* {
  font-family: 'Arial', sans-serif;
  font-size: 20px;
}

.inputContainer {
  position: relative;
}

.inputContainer input {
  padding: 18px 10px 5px;
  margin-top: 10px;
  border: none;
  border-bottom: 1px solid gray;
}

.inputContainer label {
  position: absolute;
  top: 28px;
  left: 10px;
  transform-origin: 0 0;
  transition: all 0.3s ease;
}

.inputContainer input:focus+label,
.inputContainer input:valid+label {
  transform: translateY(-15px) scale(.625);
}
<div class="inputContainer">
  <input type="text" id="search" required />
  <label for="search">Enter your search query</label>
</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

The CSS styling for an active link is not functioning correctly on a single page when using sections

I recently received a zip file containing a template purchased from themeforest, with a request to make modifications. The template includes a horizontal navigation bar with links to various sections on the page. In the original template, when you click on ...

What is the solution to the question: "Hey there, time traveler. We are currently in an era where CSS prefixes are no longer necessary, thanks to the advances in prefix-less CSS

I'm having an issue in my Next.JS app with importing my stylesheet in _app.js. Here is how I currently import it: import '../public/css/Index.css'; The content of Index.css looks like this: .index-container { margin: 20px auto 0; } Wha ...

Animate the coloring process with dynamic motion

Is there a way to dynamically fill a canvas with color and apply animation? I have successfully created a canvas cylinder that fills with color, but I'm hoping for a slow animation effect when the color is filled. I've tried searching on Google ...

Creating a FadeIn animation for a hidden div element by using the display:none property

Struggling to implement a fadeIn function for a div tag with a display:none property. How can I make the div tag visible and smoothly fade in while still keeping the display:none property? Attempted solution so far: <div class="graphs_line_based cle ...

Adjusting Iframe to Fit Entire Screen Using CSS

I've been working on making an iframe adjust to fit the screen size, regardless of the user's resolution. However, no matter what I do, I can't seem to get it just right. It always ends up either too small or with a double scroll bar issue ( ...

How to Customize Shadow-DOM Elements in Audio Player on Webkit and Chrome

Context: In my quest to enhance the appearance of the audio element in Chrome, specifically version 89 on MacOS, I encountered two perplexing issues that I am seeking a deeper understanding of. By utilizing pseudo selectors, I was able to successfully styl ...

Troubleshooting: jQuery unable to locate element within iframe

I need help finding all elements within an iframe that contain a specific word, for example, 'stack' on this page: http://en.wikipedia.org/wiki/Stack_Overflow Here is the code I am currently using: <body> <iframe src="http://en.wik ...

Code-behind not functioning properly for Bootstrap Modal

Whenever the password or username are incorrect, I need to open a modal and keep it in the 'Else' statement. However, it is not working, the modal does not open. protected void bntLogar_Click(object sender, EventArgs e) { Registrar c ...

Adding or removing a class on hover in Tailwind: The simple way!

Is there a way to change the class upon hovering an object using tailwind classes? <span className='group inline-block relative'> Hello <span className='hidden absolute -top-16 left-16 group-hover:inline-block'>&#45; ...

How can I create a custom column in Bootstrap-Vue?

Here is my code snippet: <b-table hover :items="usergroupTable.datas" :fields="usergroupTable.fields" :sort-by.sync="sortBy" :sort-desc.sync="sortDesc" ...

The webview is failing to display the dropdown menu

Everything seems to be working fine with the 3 dropdown menus on this website, as they appear on top of the images below them. However, when I convert the site into an Android app using Webview, the menus end up going under the images instead of on top. ...

An issue is being caused by altering the custom.scss.css file in Rails

After following the tutorial by Michael Hartl (), I encountered an issue when trying to modify some CSS functions in the custom.scss.css stylesheet. Every time I make a change, such as adjusting the margin from 10 px to 11 px, I receive this error in my br ...

When Bootstrap 4 teams up with Autoprefixer, it results in malfunctioning old iPads

.row { display: -webkit-box; display: -ms-flexbox; display: flex; -ms-flex-wrap: wrap; flex-wrap: wrap; margin-right: -15px; margin-left: -15px; } Recently, we implemented Bootstrap 4 and the Flex model at my company. We'v ...

Modifying the background-image to an SQL image

Can the background-image: url(--SET THIS--) be set to an SQL picture? I am considering something like this: $img = $MysqliHandler->query(SELECT avatar FROM account WHERE username="'.$_SESSION['name'].'"'; And then somehow cha ...

Dim the entirety of the page while accentuating specific regions

Check out this demo on JSFiddle I'm trying to figure out how to bring the .highlight element to the front. <body> <p>bla bla</p> <p class="light">highligh this</p> </body> CSS body{ background-color: ...

Offspring Div Protruding from Mother Div

Struggling to contain the character div within the game div in my project. Seeking advice as I am relatively new to CSS and would appreciate any tips or feedback. * { padding: 0; margin: 0; } #game { margin: auto; width: 400px; height: 500p ...

"Enhancing the Spacing of Elements Using Margin and Padding in a Floating

I'm facing an issue with adding margins and padding to my paragraph tag. This problem seems to be related to floating the img element to the left. I am trying to position the paragraph on the right side of the image while adding both left and right pa ...

Issue with Bootstrap dropdown not appearing properly when switching between screen sizes

I am currently working on converting a side navigation in bootstrap to a dropdown when the window is resized. However, I am experiencing an issue between the medium and small screen sizes where for a few pixels, nothing is shown. The side navigation disapp ...

Tips on customizing the appearance of mat-card-title within a mat-card

Is there a way to truncate the title of a mat card when it overflows? I tried using the following CSS: overflow:hidden text-overflow:ellipsis white-space: nowrap However, the style is being overridden by the default mat-card style. I attempted to use mat ...

Solving the mystery of background color in CSS for heading/title div

I am facing an issue with the title div setup where the red background is not applied when only the leftmost div has content. Despite the 'title' div having content, the background remains white. Can anyone suggest why this might be happening? H ...