Horizontal spacing with HTML/CSS within parent div - html

I am attempting to space elements throughout my webpage that are contained within a <div class="card"> from a template I am using. I have been trying to use inline CSS to space elements, as I am new to HTML/CSS and the CSS file from the template is difficult for me to navigate (and understand).
Inline CSS overrides the CSS files contained in the directory, as far as I understand. My elements looks like:
And I would like them to be spaced like:
My code looks like:
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card ">
<div class="card-body">
<select class="custom-select">
<option selected>Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<div class="form-group">
<label for="comment">Input:</label>
<textarea class="form-control" rows="10" id="comment"></textarea>
</div>
<i class="material-icons" style="font-size: 48px;">arrow_forward</i>
<div class="form-group">
<label for="comment">Output:</label>
<textarea class="form-control" rows="10" id="comment"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
I have tried a number of methods to get this to work, and nothing has worked particularly well for me. My question is, how can I achieve the spacing I laid out in the second picture?

That's the CSS I applied to your html.
.card-body > select {
vertical-align: top;
}
.card-body > div {
vertical-align: middle;
display:inline-block;
}
Demo link

You said you wanted inline css, so I did inline css.
We are doing display:inline-block so that we can keep our divs on the same row, float-left so they are positioned as far left as possible without colliding with other elements.
On class custom-select we also set the position to relative which enables us to do top:35px which moves that element down 35 pixels. I did that because that's sort of how it appears in your image.
Finally the use of !important will override ANY css usually unless !important is declared elsewhere, then you may still have a conflict. I highly doubt it's declared elsewhere however as there is no real point to doing it unless you want to override a previous setting.
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card ">
<div class="card-body">
<select class="custom-select" style="display:inline-block !important;float:left !important;position:relative;top:35px">
<option selected>Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<div class="form-group" style="display:inline-block !important;float:left !important">
<label for="comment">Input:</label>
<textarea class="form-control" rows="10" id="comment"></textarea>
</div>
<i class="material-icons" style="font-size: 48px;display:inline-block !important;float:left !important">-›</i>
<div class="form-group" style="display:inline-block !important;float:left !important">
<label for="comment">Output:</label>
<textarea class="form-control" rows="10" id="comment"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
JSFIDDLE: https://jsfiddle.net/hw2tv6g1/

Related

How to center a label inline in html with bootstrap

I'm trying to create an inline form with a text and select input, but I'm unable to get it to look how I want it.
<!-- Bootstrap-5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Body -->
<div class=r ow>
<div class="col-lg-12">
<div class=r ow>
<div class="col-md-2">
<label for="the_select" class="form-label">Key Name</label>
</div>
<div class="col-md-2">
<select class="form-select" id="the_select">
<option selected>Open this select menu</option>
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option value="Other">Other</option>
</select>
</div>
<div class="col-md-2">
<label for="value_field_id" class="form-label">Variable Name</label>
</div>
<div class="col-md-2">
<input type="text" class="form-control" id="value_field_id">
</div>
</div>
</div>
</div>
This is my current hmtl code. I'm using bootstrap 5. The label is waaaay to far apart from the corresponding input/select and it's not vertically center with it. Is there an easy way to correct this? I tried chaging the display in the styled field of the label but it gets completely ignored.
These 2 Bootstrap Flex class additions should:
center both flex items vertically and
move 1st flex item's <label> content to the right border of its parent flex item.
<div class = row align-items-center*>
<div class = "col-md-2">
<label for="the_select" class="form-label ms-auto">Key Name</label>

CSS class for rendering divs dynamically on half of page

I am stuck in rendering div via ng-repeat. I want to render the coming divs in ng-repeat one by one covering half the page.
Here is my code:
<div class="col-md-12">
<div class="form-group col-md-6" ng-repeat="field in selectedfields" ng-if="!selectedfields[$index].allowedValues || selectedfields[$index].allowedValues.length === 0 ">
<label class="control-label" for="domain">{{field.name}} </label>
<input placeholder="{{field.name}}" class="form-control" type="text" id="domain">
</div>
<div class="form-group col-md-6" ng-repeat="field in selectedfields" ng-if="selectedfields[$index].allowedValues.length >= 1">
<label class="control-label" for="{{field.name}}">{{field.name}} </label>
<select class="form-control">
<option value="{{allowedValue.name}}" ng-repeat="allowedValue in field.allowedValues" ng-model="field.allowedValues">{{allowedValue.name}}</option>
</select>
</div>
</div>
The divs(textboxes/dropdown) under the parent div should appear one by one covering half the page, but they are coming on full page. Each div is rendering on next line. Can someone please suggest what am I doing wrong in giving the css class?
Your final layout should be
<div class="col-md-12">
<div class="row">
<!-- ng-repeat stuff goes here !-->
</div>
</div>

How to position a set of div elements side by side?

I have placed two div elements contained in a form. My aim is to place the second div "App" side by side with the "Status" div like in the mock up below:
What I've tried so far is the following, setting the align="right" which positions the div on the extreme right.
Also I tried setting style="margin-left: which places the second div underneath and too far right of the first div.
Question:
Does anyone know how I can place the second div in line and side by side with the first div?
Form markup:
<form action="" method="post">
<div class="form-horizontal">
<div class="col-lg-6">
<!-- SELECT STATUS STATIC-->
<div class="form-group">
<label class="col-md-3 control-label" for="Current Status">Status</label>
<div class="col-md-8">
<select id="Status" name="Status" onchange="" class=" form-control">
<option value="Down">Down</option>
<option value="Up">Up</option>
</select>
</div>
</div>
<!-- SELECT APP STATIC-->
<div class="form-group">
<label class="col-md-3 control-label" for="App">App</label>
<div class="col-md-8" >
<select id="App" name="App" onchange="" class=" form-control">
<option value="SAP">SAP</option>
<option value="JAP">JAP</option>
</select>
</div>
</div>
</div>
</div>
</form> <!--END OF FORM ^^-->
You can set both divs to display: inline-block.
.form-group {
display: inline-block;
}

Preserving Column Order on Inline Form Inputs with RTL CSS in Bootstrap

I have 3 columns in my form for inputting the user's phone:
<div class="col-md-5">
<label class="control-label">Phone</label>
<div class="row">
<div class="col-md-4">
<label for="phone_code" class="sr-only"><fmt:message key="phoneCode"/></label>
<select class="form-control" name="phoneCode" id="phone_code">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<span class="col-md-2 text-center">-</span>
<div class="col-md-6">
<label for="phone_number" class="sr-only">phone number</label>
<input type="tel" class="form-control" name="phoneNumber" id="phone_number" dir="LTR" value="${phoneNumber}">
</div>
</div>
</div>
http://www.bootply.com/jgFqaA4r6o
When I include the bootstrap css for rtl:
https://github.com/morteza/bootstrap-rtl
this flips the order of the columns, which in most cases is the desired result. However, I would like the phone input columns to remain in the same order (unaltered).
Including the pull-left class to the first two columns fixes the problem but causes errors when resizing (specifically, shrinking) the screen.
I have tried using/learning the col--pull-/col--push- classes but I couldn't figure out how to make them work here.
Does anybody have any suggestions?
I am also open to changing the general layout if there are improvements on that as well.
Thank you.
I changed the html and used a small "hack" to solve this.
There is still probably a better solution out there. This is my html:
<div class="col-md-5">
<div class="col-sm-4 col-xs-12 pull-left">
<label for="phone_code" class="control-label">phone code</label>
<input type="text" class="form-control">
</div>
<div class="col-sm-8 col-xs-12">
<label for="phone_number" class="control-label">phone number</label>
<input type="tel" class="form-control">
</div>
</div>
http://www.bootply.com/tIW6xBHVGB
The "hack" is the "col-xs-12" class added to the <div> elements. If not added, the divs don't expand to take up the entire row as they should due to the "pull-left" class.
I'm open to hearing other suggestions.

Can't style certain div with css

I'm styling this page and yet I can't seem to access either .4thForm or .3rdForm to style. These elements move responsively when screensize drops below 1024px so it's cruitial that I access these elements.
I've tested the #media call and I can change the colour .frontbannertitle with it so I know it's not the media call. Using inspector I can code the element to achieve what I would like, but it will not let me generate a css element to style it.
I need to edit this div to provide it with a negative margin-top value, as that cannot be achieved by targeting the select within the div.
Jsfiddle: http://jsfiddle.net/P49ja/
<form class="frontbannercontainer form-horizontal">
<fieldset class="frontbanner">
<h1 class="frontbannertitle">Enquire Now!</h1>
<div class="control-group">
<div class="controls">
<input id="textinput1" class="frontbannertext input-xlarge" type="text" name="textinput">
</div>
</div>
<div class="control-group">
<div class="controls">
<input id="textinput2" class="frontbannertext input-xlarge" type="text" name="textinput">
</div>
</div>
<div class="control-group">
<div class="controls 3rdForm">
<input id="textinput3" class="frontbannertext input-xlarge" type="text" name="textinput">
</div>
</div>
<div class="control-group">
<div class="controls 4thForm">
<select id="selectbasic" class="frontbannerselect input-xlarge" name="selectbasic">
<option selected="selected" disabled="disabled" value="0">Select Membership</option>
<option value="1">Individual Membership</option>
<option value="2">Corporate Membership</option>
</select>
</div>
</div>
<div id="SliderFormPhone">
<span id="ques">Enquire By Phone:</span>
<span id="ph">(02) 000 000</span>
</div>
<div class="control-group">
<div class="controls">
<button id="singlebutton" class="frontbannerbutton btn btn-primary" name="singlebutton">Apply!</button>
</div>
</div>
</fieldset>
</form>
Thanks!
DEMO
You can not start a class with a number in your case it's .4thForm
Change it to something like .Form4th
I think you cannot use "3rdForm" as a valid class selector.
The first character cannot be numeric.
Refer to this SO answer.
I added "thirdForm" as a class to your fiddle and was able to style it properly. So I'm assuming that is the issue.
you need to add special character "\3" to access this class like below..
.\34thform{
display:none;
margin-top:-7em;
}
sample jsfiddle below...
http://jsfiddle.net/P49ja/4/