Adjusting the dimension of input elements using CSS

Is it possible to change the width of an input without using HTML? I had set the size to "35" and it looked fine on the site (check here at the bottom of the site) until I started working on the mobile version. Now, with a size of 35, it appears very wide and I'm unsure how to maintain the same look. On the mobile version, I want to display it in flex-direction: column. What am I doing wrong?

I attempted something like this:

input [type=text] {
width: 60%;}

But for some reason, it only affects two of my input boxes.

Thank you!

.bcs_za_form {
    width: 100%;
    background-color: #646C8E;
    height: 790px;
}

.textnadform {
    padding-top: 50px;
    text-align: center;
    font-size: 35px;
    color: #ffffff;
    width: 100%;
    font-family: 'Montserrat',Helvetica,Arial,Lucida,sans-serif;
}

.zanech {
    font-size: 17px;
    color: rgba(255,255,255,0.5);
    font-weight: 600;
}

.celyform {
    width: 100%;
}

.formular_2 {
    padding-top: 50px;
    display: flex;
    justify-content: center;

}

.formular_4 {
    border: 1px solid #ffffff;
    font-family: 'Montserrat',Helvetica,Arial,Lucida,sans-serif;
    font-weight: 600;
    font-size: 14px;
    color: white;
    background-color: #646C8E;
    padding-top: 25px;
    padding-right: 30px;
    padding-bottom: 25px;
    padding-left: 30px;
    border-radius: 10px;
}

.formular_4::placeholder {
    color: #ffffff;
}

.prvedva {
    margin-bottom: 1%;
    flex-grow: inherit;
    display: flex;
    width: 100%;
}

.druhedva {
    margin-bottom: 3%;
    flex-grow: inherit;
    display: flex;
    width: 100%;
}

.druhy {
    padding: 0px 0px 0px 20px;
}

.stvrty {
    padding: 0px 0px 0px 20px;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: none;
}

textarea:focus ,
input:focus {
    color: #3E3E55;
}
<div class="bcs_za_form" id="Kontakt">

    <div class="celyform">
        <div class="textnadform">
            <p class="napismi">Contact Me</p>

            <p class="zanech">Leave me a message and I will get back to as soon as possible.</p>
        </div>
  
            <div class="formular_2">
                <form class="formular_3" action="kontakt.php" method="post">
                    <div class="prvedva">
                        <input class="formular_4" type="text" name="meno" placeholder="Name" size="35">
                    <div class="druhy"> 
                        <input class="formular_4" type="text" name="priezvisko" placeholder="Surname" size="35">
                    </div> 
                    </div>
                        <br>
                    <div class="druhedva">
                    
                        <input class="formular_4" type="text" name="telcislo" placeholder="Phone Number" size="35">
                    <div class="stvrty">
                        <input class="formular_4" type="text" name="mail" placeholder="Your E-mail" size="35">
                    </div>
                        <br>
                </div>
                    <div class="">
                        <textarea class="formular_4" name="sprava" placeholder="Message" cols="85" rows="8"></textarea>
                    </div>
                </form>
            </div>

Answer №1

There seems to be an unusual nesting of divs in the form resulting in only 2 fields being resized.

I observed that your form width exceeds the container on resize. To prevent this, you can enclose your form within a div and set a max-width as follows:

.form-container{
max-width: 100%;
}

UPDATED CODE:

<html lang="en">

<head>
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <title>form</title>
    <style>
        /*CSS styles*/
        
    </style>
</head>

<body>
    <div class="bcs_za_form" id="Kontakt">
        <div class="celyform">
            <div class="textnadform">
                <p class="napismi">Contact Me</p>
                <p class="zanech">Leave me a message and I'll get back to you soon.</p>
            </div>
            <div class="form-container">
                <div class="formular_2">
                    <form class="formular_3" action="kontakt.php" method="post">
                        <div class="section">
                            <input class="formular_4" type="text" name="meno" placeholder="First Name">
                            <input class="formular_4" type="text" name="priezvisko" placeholder="Last Name"> </div>
                        <div class="section">
                            <input class="formular_4" type="text" name="telcislo" placeholder="Phone Number">
                            <input class="formular_4" type="text" name="mail" placeholder="Your Email"> </div>
                        <textarea class="formular_4" name="sprava" placeholder="Message" cols="85" rows="8"></textarea>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

The size="35" attribute has been removed for flexibility, and flex property is utilized to size the fields. Alternatively, you can set inputs to a percentage like 48% but manual margin adjustments are needed in that case.

Bootstrap is not required, but can be used for consistency if needed to maintain a uniform look across elements.

Answer №2

Have you experimented with a similar approach?

   @media only screen and (max-width: 600px) {
  .formular_4 {
    size: 20;
  }
}

To set the maximum width, specify the pixel size of the screen needed. In this case, any screen smaller than 600 pixels will follow the specified style rule.

Answer №3

I have enhanced your form with some Bootstrap to ensure better responsiveness. Check out the snippet below:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>

<body>
<div class="container">
  <form class="formular_3" action="kontakt.php" method="post">
    <div class="prvedva form-group">
        <input class="formular_4 form-control" type="text" name="meno" placeholder="Meno" size="35">
    </div>

    <div class="druhy form-group">
        <input class="formular_4 form-control" type="text" name="priezvisko" placeholder="Priezvisko" size="35">
    </div>

    <div class="druhedva form-group">
        <input class="formular_4 form-control" type="text" name="telcislo" placeholder="Tel. číslo" size="35">
    </div>
    
    <div class="stvrty form-group">
        <input class="formular_4 form-control" type="text" name="mail" placeholder="Váš E-mail" size="35">
    </div>

    <div class="form-group">
        <textarea class="formular_4 form-control" name="sprava" placeholder="Správa" cols="85" rows="8"></textarea>
    </div>
  </form>
</div>

</body>
</html

For more detailed information, please refer to the documentation.

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

Creating a dropdown menu with an initial value fetched from a text file

I'm currently working on a school project that involves adjusting basic wireless parameters in a Linux router using command-line operations through an HTML interface. My experience has mostly been with PHP, and so far, I've been progressing well. ...

Emphasize the present selection along with all prior items in a menu

Attached is my menubar for a unique web design concept I am working on. My webpage is designed as a fully scrollbar page shift type, meaning it is a single page containing six sections that are scrollable by selecting menu items. Currently, when I click ...

Getting rid of the outline on <html> while tabbing in Firefox

An odd outline keeps appearing as I tab through elements on a website, but only in Firefox and not in Chrome, Safari, or Opera. To identify the element causing the focus, I used Firebug console by typing: document.activeElement. It showed: >>> d ...

Scrolling to a specific anchor in a React webpage when the URL is opened in

Imagine having a component "Post" that contains multiple components "Comment". How can we make the application automatically scroll down to a specific comment when entering a URL like this: /post/:postId/#commentId The route for postId /post/:postId is a ...

Are you searching for a stylish tabbed navigation menu design?

I am searching for a tabbed navigation menu specifically designed to showcase images as the tab items. Here is an example of what I have in mind: <div class="menu"> <a href="#"> <img src="images/Chrysanth ...

Having trouble with the alignment in navbar using Bootstrap 4 mr-auto?

After browsing through similar questions on this platform, I still couldn't find a solution that works for me, as I am a beginner in web development. I am trying to align the contact link in my navbar to the right, but the "mr-auto" class and other me ...

Custom CSS Editor for Third Party Visual Studio Themes

Are there any reliable and user-friendly style sheet editors that can be integrated with Visual Studio? I recently came across a resource editor that surpassed the default version for opening .resx files. This got me thinking, there may be some advanced ...

Tips for displaying XML content within an AngularJS application using HTML

I have a string containing data: var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel> </rss>" ; My goal is to display this string on a web page in the proper XML format. <channel& ...

Unlocking the potential of data inputted in a JQuery Autocomplete form

Seeking assistance with extracting data from a form to utilize for additional purposes <form onsubmit="return false;"> Enter a School: <input id="schoolsearch" type="text" /> <INPUT TYPE=SUBMIT VALUE="GO"> </form> I am struggling ...

PHP Exception with dual inputs

I am currently exploring the best approach for capturing messages in my PHP code but I'm unsure if it's even possible. Within my simple PHP structure, I am using try and catch blocks like this: if (!$this->issetAndNotEmpty($id)) ...

Expanding the Background Color when Hovered Over

Despite my extensive search on SO, none of the answers I found seem to address my specific situation. In a col-md-2 section where I have a navigation bar, I am trying to change the background color to extend up to the border when hovering. While I can cha ...

Removing fields from the admin form in Django for certain users: A step-by-step guide

My admin interface currently displays the following fields for the Movie model: class MovieAdmin(models.ModelAdmin) fields = ('name', 'slug', 'imdb_link', 'start', 'finish', 'added_by') l ...

Customize your file input with Bootstrap 4 using bs-custom-file-input and create a Symfony 5 collection with dynamic upload fields

The issue of not having a label for the chosen filename in a bootstrap 4 upload field has been resolved using the plugin https://github.com/Johann-S/bs-custom-file-input You can utilize "bs-custom-file-input" to showcase the selected filename in the boots ...

Mobile navigation menu options on the left and right sides

I've encountered an issue with my mobile navigation. I have two navigation menus - one on the left and one on the right, designed to slide out when triggered. The left menu functions correctly with a smooth transition, but the right menu abruptly pops ...

What is the best way to choose a disabled field using Watir?

Recently, I've encountered an issue with my webpage's popup functionality. It used to work smoothly, with fields that could be manipulated when the popup was visible. However, I've noticed that now, when I try to inspect these fields using f ...

Issue with Django query not being successfully transferred to AJAX in JSON structure

Trying to populate a textfield with its corresponding database value using Django and AJAX. The objective is for the textfield to automatically update when the dropdown value changes. However, encountering an error in console: SyntaxError: Unexpected to ...

Background Patterns on Webpages

My website has a lovely gradient background on the html tag in css, while the body tag showcases a seamless pattern repeating on both the x and y axes. Everything was looking great until I checked the website on an iPad/iPhone in portrait mode, where the ...

What is the best way to include attributes in an HTML element?

I've been researching how to dynamically add attributes to an HTML tag using jQuery. Consider the following initial HTML code: <input type="text" name="j_username" id="j_username" autocorrect="off" autocapitalize="off" style="background-image: lin ...

Is there a way to create a navigation menu that highlights as we scroll down the page?

Check out this example of what I am looking for. https://i.stack.imgur.com/fdzvZ.png If you scroll, you will notice that the left menu highlights. Sub-menus will extend when the corresponding menu is highlighted and collapse when other menus are highlig ...

What is the best way to eliminate excess space on the right side in Bootstrap 4 while in mobile view?

I'm struggling to understand why this layout is not responsive on mobile devices, triggering a bottom scroll bar at around 616px. I'm looking for a solution to hide the scroll bar at least until 414px for iPhones and other smartphones. I've ...