How to styles labels only within fieldsets using CSS? - css

I have tried all the possible ways mentioned on CSS Selectors, but I have not managed to change the style of the labels that are only inside fieldset element. Could you please inform me what I did wrong?
View:
<div class="container">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-8 portfolio-item">
<fieldset>
<legend>Details</legend>
<div class="col-md-4 portfolio-item" >
#Html.LabelFor(m => m.ID):
#Html.DisplayFor(m => m.ID)
<br />
#Html.LabelFor(m => m.Name):
#Html.DisplayFor(m => m.Name)
<br />
#Html.LabelFor(m => m.Surname):
#Html.DisplayFor(m => m.Surname)
<br />
</div>
<div class="col-md-8 portfolio-item" >
#Html.LabelFor(m => m.Department):
#Html.DisplayFor(m => m.Department)
<br />
#Html.LabelFor(m => m.Address):
#Html.DisplayFor(m => m.Address)
<br />
#Html.LabelFor(m => m.City):
#Html.DisplayFor(m => m.City)
<br />
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
I tried lots of different combinations of CSS Selectors in order to apply the styles only the labels inside fieldset elements as below:
Css:
fieldset > label {
text-align: left !important;
}
fieldset + label {
text-align: left !important;
}
div.row fieldset > label {
text-align: left !important;
}
Update : Here is rendered Html code
<div class="container">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-8 portfolio-item">
<fieldset>
<legend>Details</legend>
<div class="col-md-4 portfolio-item">
<label for="ID">ID</label>:
200
<br>
<label for="Name">Name</label>:
Smith
<br>
<label for="Surname">Surname</label>:
Boyton
<br>
</div>
<!-- removed for brevity -->
</fieldset>
</div>
</div>
</div>
</div>
</div>

It's as simple as
fieldset label {
text-align: left;
}
The reason why your css wasn't working is because you were targetting the wrong elements. What you want is a general descendant for the fieldset. So any level of children will be affected.
You simplified HTML is:
<fieldset>
<legend />
<div>
<label/>
</div>
</fieldset>
fieldset > label is finding a label that is the direct child of the fieldset. But since you have wrapped it in a div, this is not true.
fieldset + label is looking for a label that is a sibling of the fieldset (on the same level). The label is a child of the fieldset so this rule doesn't target what you want.
For more info on selectors in CSS take a quick read of https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors.
Small tip: in general you want to avoid using the !important declaration as it could override any changes you want to make in the future.

It should be just:
fieldset label {
text-align: left;
}
The '>' symbol is the direct child selector i.e. theres a DIV between your fieldset and label which would be the direct child of fieldset
Also the '+' symbol is the next sibling selector which is why that won't work

Related

How to align the div in same row in angular 5 using bootstrap classes

// here is input field with the label, "WLC Name" I want to align in the same row.
<div class="form-group row">
<label class="col-md-2 col-form-label text-right">WLC Name</label>
<div class="col-lg-2 col-sm-11">
<input type="text"value="BSNL-WLCXXX" class="form-control" formControlName="wlc_name" id="wlc_name" #wlcname>
// I want to put below div in the same row, but it is not coming.
<div>
<app-right-tooltip [toolTipText]="getToolTipText('system_basic_wlc_name')"></app-right-tooltip>
</div>
</div>
// html code for the tag : app-right-tooltip
<div>
<span class="glyphicon glyphicon-question-sign blue" style="font-size: 15px " aria-hidden="true" [popover]="getData()"
popoverPlacement="right"
[popoverOnHover]="false"
[popoverCloseOnMouseOutside]="false">
</span>
</div>
snapshot
You need to float app-right-tooltip
<app-right-tooltip style="float:right"></app-right-tooltip>
Otherwise, you need to have some structure to wrap this component
<div class="row">
<div class="md-2">...</div>
<div class="md-10"><app-right-tooltip /></div>
</div>
Try this
css
.exampleClass {
dispaly: inline-block;
}
Html
<div class="exampleClass">
<app-right-tooltip [toolTipText]="getToolTipText('system_basic_wlc_name')"></app-right-tooltip>
</div>

Tabular layout of content without using a float [duplicate]

This question already has answers here:
Div side by side without float
(6 answers)
Closed 6 years ago.
This code is layed out in 1 column. I want to get a tabular 2 column layout.
<span id="col1">
<div>Filter by</div>
<div>
<input type="text" value="hello" />
</div>
</span>
<span id="col2">
<div>Search</div>
<div>
<input type="text" value="hello" />
</div>
</span>
How can I achieve this without using float?
fiddle
You can use the flexbox for that:
.container {
display: flex;
}
<div class="container">
<div id="col1">
<div>Filter by</div>
<div>
<input type="text" value="hello" />
</div>
</div>
<div id="col2">
<div>Search</div>
<div>
<input type="text" value="hello" />
</div>
</div>
</div>
Note that I changed your span to div elements (since span are inline and should not contain block elements).
I also wrapped the entire block with div.container so I'll be able to set that container as the flexbox.
Assuming you want the columns to be able to be shown/hidden, you could do this:
<head>
<script>
$('.next').click(function() {
var next = $('.col').next();
var curr = $('.col');
next.addClass('col-active');
curr.removeClass('col-active');
});
</script>
<style>
.col {
display: none;
}
.col-active {
display: block !important;
}
</style>
</head>
<body>
<span id="col1" class="col col-active">
<div>Filter by</div>
<div>
<input type="text" value="hello" />
</div>
</span>
<span id="col2" class="col">
<div>Search</div>
<div>
<input type="text" value="hello" />
</div>
</span>
<a class="next">Next Page</a>
</body>
This essentially shows and hides the columns based on the <a> being clicked. I use this quite a lot when having sliders/tabulated pages.
Hope this helps :)

Margin after automic line break will be ignored

The margin takes only affect for the first line (after automatic line break (depends on the size) will be ignored).
The HTML:
<div class="BWForm_form-group">
<div class="col-md-3 BWTextLeft">
<label class="control-label" for="ContactPersonName">Name des Ansprechpartners<span style="color:red; display: inline-block;"> *</span></label>
</div>
<div class="col-md-5">
<div class="col-md-12">
<input class="text-box single-line input-validation-error" data-val="true" data-val-required="The Name of contact person field is required." id="ContactPersonName" name="ContactPersonName" value="" type="text">
</div>
</div>
<div class="col-md-4">
<span class="field-validation-error" data-valmsg-for="ContactPersonName" data-valmsg-replace="true"><span class="" for="ContactPersonName">The Name of contact person field is required.</span></span>
</div>
</div>
The css:
.field-validation-error {
color: #B94A48;
font-weight: bold;
margin: 15px;
}
The "BWForm_form-group" is inherited by the bootstrap class form-group."BWTextLeft" will only align:left.
What can I do to fix it ?
It looks like that click (the problem is right to my green arrow and vertical line)
Ty for helping
oh ok remove the margin left from field-validation-error and then add a new class like to the container
<div class="col-md-12 custom">
and the css looks like the below
custom {
margin:15px;
}
demo example here
if you dont want to mess with the margins of the col-md-12 then you should add a surrounding div like this
<div class="col-md-12">
<div class="custom">
<div class="field-validation-error">

CSS Issue - Can't make <div> appear inline

I have the following HTML:
#using (Html.BeginForm("Create", "BicycleSellerListing", FormMethod.Post, new { enctype = "multipart/form-data" })) {
#Html.ValidationSummary(true)
<fieldset style="margin:5px;">
<legend>List a Bicycle for Sale</legend>
<div style="display: inline">
<div style="display: inline">
#Html.LabelFor(model => model.BicycleManfacturer)
</div>
<div style="display: inline">
#Html.DropDownList("ManufacturerList")
</div>
<div style="display: inline">
#Html.LabelFor(model => model.BicycleType)
</div>
<div style="display: inline">
#Html.DropDownList("TypeList")
</div>
<div style="display: inline">
#Html.LabelFor(model => model.BicycleModel)
</div>
<div style="display: inline">
#Html.EditorFor(model => model.BicycleModel)
#Html.ValidationMessageFor(model => model.BicycleModel)
</div>
....
....
I cannot make the labels and the edit field appear next to each other (by using inline). The edit fields always appear below the label. Anyone know what I might be doing wrong?
Inline style means that if space permits than the div will align inline. Now on the parent div you haven't given any width. So it will take up space according to its Child. Now lets suppose first child is inserted. The parent div will take up it's Child's space. Now you want to insert another Child. Even though the next Child has display inline, it will not find any space next to its sibling because the sibling and the parent div are taking same space. Hence it will render in the next line.
Try doing this:
#using (Html.BeginForm("Create", "BicycleSellerListing", FormMethod.Post, new { enctype = "multipart/form-data" })) {
#Html.ValidationSummary(true)
<fieldset style="margin:5px;">
<legend>List a Bicycle for Sale</legend>
<div style="display: inline; width: 1000px;">
<div style="display: inline">
#Html.LabelFor(model => model.BicycleManfacturer)
</div>
<div style="display: inline">
#Html.DropDownList("ManufacturerList")
</div>
...

Trouble with content overlapping horizontal form using responsive Twitter Bootstrap

I have spent more time than I ever care to admit trying to fix this stupid bug. I have a form that displays to the left of some content. It looks okay on a wide and narrow screen, but on a tablet width (it overlays between 770 and 950 or so) the content to the right overlaps the form fields.
Am I missing something in my markup to use Twitter Bootstrap properly or do I need to add some custom styles using breakpoints to fix it? It appears that the fixed pixel width is causing the issue defined in bootstrap.css. Shouldn't these width properties use % since I'm using a fluid responsive layout?
<div class="container-narrow">
<div class="content">
<div class="row-fluid">
<div class="span5">
<form class="form-horizontal" id="applies-Step1-form" action="/" method="post">
<div class="control-group">
<label class="control-label required" for="Step1_email">Email <span class="required">*</span></label>
<div class="controls">
<input size="60" maxlength="255" name="Step1[email]" id="Step1_email" type="text" />
</div>
</div>
<div class="control-group">
<label class="control-label required" for="Step1_home_zip">Home Zip <span class="required">*</span></label>
<div class="controls">
<input size="5" maxlength="5" name="Step1[home_zip]" id="Step1_home_zip" type="text" />
</div>
</div>
</form>
</div>
<div class="span7">
<div class="promo-btm">
<h2>Heading 2</h2>
<ul class="checks">
<li>Bullet One</li>
<li>Bullet Two</li>
</ul>
</div>
</div>
</div>
</div>
</div>
See the attached screenshot for the bug or you can reproduce it yourself using my fiddle.
If someone could help point out a way to fix this I would be extremely appreciative!
Just add a width to your input elements so they can adapt responsively with all of your screen sizes. You can use something like .span12 as a width on your input elements and that should fix the issue:
HTML
<div class="container-narrow">
<div class="content">
<div class="row-fluid">
<div class="span5">
<form class="form-horizontal" id="applies-Step1-form" action="/" method="post">
<div class="control-group">
<label class="control-label required" for="Step1_email">Email <span class="required">*</span></label>
<div class="controls">
<input class="span12" size="60" maxlength="255" name="Step1[email]" id="Step1_email" type="text" />
</div>
</div>
<div class="control-group">
<label class="control-label required" for="Step1_home_zip">Home Zip <span class="required">*</span></label>
<div class="controls">
<input class="span12" size="5" maxlength="5" name="Step1[home_zip]" id="Step1_home_zip" type="text" />
</div>
</div>
</form>
</div>
<div class="span7">
<h2>Heading 2</h2>
<ul class="checks">
<li>Bullet One</li>
</ul>
</div>
</div>
</div>
</div>
Demo: http://jsfiddle.net/yR7Ap/18/
The other posts have pinpointed the root cause of the problem, that your form is too wide for the span5 div with the default bootstrap css
It's not too difficult to make it fit though. See if this helps : http://jsfiddle.net/panchroma/FXXaZ/
I have tightened up your form with this CSS:
/* pull control label left */
.form-horizontal .control-label {
width:70px; /* default 160 */
}
/* pull input box left */
.form-horizontal .controls {
margin-left: 90px; /* defaul 180 */
}
/* shorten input box */
input, textarea, .uneditable-input {
width: 180px; /* default 206 */
}
Good luck!
Your form is too wide for the .span5 column. Try adding this above:
<div class="row-fluid">
<div class="span5">hello</div>
<div class="span7">world</div>
</div>
and add the following style:
.row-fluid > div { outline: 5px solid green; }
and you'll see what I mean.

Resources