Issues with alignment in Bootstrap CSS

I have Bootstrap downloaded and the following code snippet.

<header id="top">
        <div class="container">
            <div class="row">
                <div class="col-sm-3 ">
                    <image alt="here will be the logo" src=""></image>
                </div>
                <div  class="col-sm-6 ">

                </div>
                <div class="col-sm-3">
                    <form class="form-horizontal" >
                    <div class="form-group row">
                    <label class="control-label col-sm-4" for="document">Document:</label>
                    <div class="col-sm-8">
                      <input type="email" class="form-control" id="document" placeholder="document">
                    </div>
                    </div>
                    <div class="form-group row">
                    <label class="control-label col-sm-4" for="revision">Revision:</label>
                    <div class="col-sm-8">
                      <input class="form-control" id="revision" placeholder="revision">
                    </div>
                    </div>
                    <div class="form-group row">
                    <label class="control-label col-sm-4" for="pagenr">Page nr:</label>
                    <div class="col-sm-8">
                      <input class="form-control" readonly = "true" id="pagenr" placeholder="here will be page number">
                    </div>
                    </div>
                    <div class="form-group row">
                    <label class="control-label col-sm-4" for="iso">ISO:</label>
                    <div class="col-sm-8">
                      <input class="form-control" id="iso" placeholder="iso">
                    </div>
                    </div>
                    </form>

The result I get can be viewed here: web page I am interested in 1. the alignment of text inside the forms (for some reason, the label is positioned higher than the input) and 2. the huge right margin that does not go away no matter what I try, taking up input space. It's also worth noting that making an input field 'readonly' turns it perpetually gray. Here is my CSS code:

input.form-control{
    width: 80%;
    padding: 15px 22px;
    margin: 5px 5px;
    box-sizing: border-box;  
    font-size: 14px;
    height: 10px;
    border:0;
    background-color: #FFEBCD;
}
header {
    padding-top: 20px;  
    height: 100px;
    font-size: 14px;
}
div.container
{
    margin-right: 1px;
    margin-left: 100px;
    padding-right: 1px;
    border-right: 1px;
}
div.form-group
{
    margin-right: 1px;
    padding-right: 1px;
    border-right: 1px;
}
form.form-horizontal
{
    margin-right: 1px;
    padding-right: 1px;
    border-right: 1px;
    vertical-align: bottom;
}
div.row
{
    margin-right: 1px;
    padding-right: 1px;
    border-right: 1px;
}
label.control-label
{
    width: 100%;
    vertical-align: baseline ;
    background-color: CadetBlue;
    text-align: left;
}

Vertical or text alignment attributes do not seem to work, nor setting 'right margin' = 1px to any element I can think of. The HTML code provided only covers the first form, as the entire code would be twice as big with the same problem in the second form.

Answer №1

I've made some modifications to their code. I hope this aligns with your expectations. It was quite complex to work through.

  <header id="top">
    <div class="container">
      <div class="row">
        <div class="col-sm-4 ">
          <image alt="here will be the logo" src=""></image>
        </div>
        <!-- <div class="col-sm-6 ">

        </div> -->
        <div class="col-sm-8">
          <form>
            <div class="form-group row">
              <label class="col-form-label col-sm-2" for="document">Document:</label>
              <div class="col-sm-10">
                <input type="email" class="form-control " id="document" placeholder="document">
              </div>
            </div>
            <div class="form-group row">
              <label class="control-label col-sm-2" for="revision">Revision:</label>
              <div class="col-sm-10">
                <input class="form-control" id="revision" placeholder="revision">
              </div>
            </div>
            <div class="form-group row">
              <label class="control-label col-sm-2" for="pagenr">age nr:</label>
              <div class="col-sm-10">
                <input class="form-control" id="pagenr" placeholder="here will be page number">
              </div>
            </div>
            <div class="form-group row">
              <label class="control-label col-sm-2" for="iso">ISO:</label>
              <div class="col-sm-10">
                <input class="form-control" id="iso" placeholder="iso">
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    </div>
  </header>

Answer №2

After some experimentation, I managed to correct the text alignment issue by adjusting the line-height of the form elements until they appeared satisfactory. However, when adding color to the boxes, the misalignment became noticeable again. The unequal spacing on the right margin was a result of compensating for an initially too small left margin - quite a puzzle!

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

Convert lengthy URLs in PHP into multiple lines

I need to display a lengthy string within a cell in a table, but the URL is too long. How can I convert something like this: /vlive.qqvideo.tc.qq.com/u0020mkrnds.p1203.1.mp4?vkey=7AB139BF6B32F537 47E8FF192E6FE557B3A3D644C034E34BF6EAEB4E0774F2A92EF3AC5C0075 ...

Cannot add padding to the DIV element

Here is some HTML and CSS code that I've provided. .x{ border-bottom: 1px solid #000; } .y { border-bottom: 1px solid #000; } .z li{ display: inline; padding-top: 50px; } <div class="x"> <br> <br> <b ...

Exploring the versatility of Angular by creating various flex layouts with Angular Material cards

I'm struggling to implement the design shown below using cards and a flex layout in a responsive way. I've tried working on it using StackBlitz but haven't been able to get it right - the margin and layout get messed up on different screens. ...

What is the recommended sequence for adding AngularJS to the index page?

I am new to AngularJS and currently working on a project where I need to include multiple JavaScript files in my index.html page. After doing some research, I came across a post on Stack Overflow that mentioned the importance of including the angular.js fi ...

What steps should I take to make my alert vanish?

I'm facing a challenge with an alert I created using Bootstrap in my Django project. Despite following instructions from the bootstrap website, I can't get the alert to disappear when I click on the x button. The errors I encountered are: Uncau ...

Unexpected problem with redrawing HTML application in Android WebView

I created a basic nixie clock app using HTML and wrapped it in a WebView for use on Android. It consists of one HTML file, a JS file, a CSS file, and ten digit images. After a few hours, I noticed stripes appearing in the center of the screen where the an ...

Jquery and Ajax failing to function properly with multiple dropdown selections

I've been working on creating a functionality to have multiple dropdown menus using Bootstrap, JQuery, and AJAX. The goal is to select multiple countries from these dropdowns and store the selected values in CSV format in my database. Initially, I had ...

The arrow in the dropdown menu is missing

I recently came across this code snippet in a Boostrap 4 website: <div class="btn-group mb-2 mr-2"> <button type="button" class="btn btn-primary">Primary</button> <button type="button" cl ...

Left-aligned and centered - Bootstrap

I need help figuring out how to center a list of items on the page, but have them aligned left. I am using bootstrap. I want the text to be in the center of the page but aligned left. <ul class='text-center'> <li class=& ...

Using jQuery sortable with the overflow property set to hidden to sort items between two lists

I need help with a jQuery sortable feature where I have two lists and can move items between them: $( '#productsList, #orderList' ) .sortable({connectWith: '.containerDiv'}) .disableSelection(); My issue arises when I try to implement ...

Choosing elements that are visible on the webpage using CSS selectors or XPath

The CSS selector for the parent element (which is always visible) can be found at this XPath: /html/body/section/div/div[2] After a few seconds (due to some JavaScript), one of its children will become visible. I need to locate and select this visible ...

The foundation gem is encountering an issue with incompatible units: 'rem' and 'px'

After installing the foundation gem version 5.5.2.1, I encountered an error when starting the application: Showing /home/user/Scrivania/sites/store/app/views/layouts/application.html.erb where line #9 raised: Incompatible units: 'rem' and &apos ...

Blazor Navbar with Custom Background and Text Color

Can someone please help me figure out how to change the background color of a navbar in Blazor? I've been trying but can't seem to find the right way to do it. Would appreciate any guidance! <div class="top-row pl-4 navbar navbar-dark bg-prim ...

How does my navigation and slider function in Internet Explorer 10?

Currently, I am in the process of developing my own website at www.heike-waltz.de In the past, I relied on conditional comments for IE, but now that this is no longer an option for IE10, I am facing some issues that I'm not sure how to resolve. Whil ...

Deactivated jQuery contextMenu following a mouseup event

Having an issue with my jQuery custom text-selection function disabling the contextMenu event. Here is a simple example with javascript and an html file: var markFeature = { getSelected: function(){ var t = ''; if(window.getSelectio ...

Is it possible to break a single word when word wrapping?

Is it possible to apply word-wrap: break-word to just one word within an element without affecting the entire element? I find that when I apply it to the entire element, it looks messy. I tried searching for a solution but couldn't find anything. Has ...

Ensure the TUMBLR og:image appears in larger dimensions for enhanced visibility [updated: additional code implemented]

I recently incorporated two widgets into my blog - one on the sidebar and another attached to each post. You can check them out at . To enhance the visual appeal, I uploaded a 900x900 og:image to the tumblr static servers, accessible through my FB Debug p ...

Changing icons in a collapsed menu in Bootstrap 4

I have been working with Bootstrap 4 alpha 6 version and I am facing an issue with multiple collapse blocks on my page. I want to change the icon when a user opens or closes a block, so I tried using classes but it didn't work. Can you help me figure ...

Using jQuery to activate classes on navigation pill elements

I'm currently developing a website and using a nav-pills setup with bootstrap 4. I am trying to implement an active state on click for two links that trigger accordions to display content. Below is the jQuery code I am using: $(function () { $("#filt ...

php redirecting form data

Being a beginner in PHP, I'm aiming to create a script that can direct me to a specific address based on the value of an input form. Is this the right approach? index.html <form action="process.php" method="post"> <input type="text" nam ...