Unable to center text for <a> - css

In the following code, I have a bootstrap navigation. On the right, I have a login form and a sign up form. On successful login, the form and sign up disappears and profile and signout are displayed
login is a <button>, signup, profile and signout are <a>
Following is the css I am applying to both <button> and <a>
.content-div__button--blue{
background-color: #4da3f8;
border:none;
color:white;
border-radius: 8px;
width:100px; /* sets the width of the content area to 200 px */
height: 40px;
box-sizing: border-box;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
}
My issue is that the text within <a> is not in the center but it is for the <button>. If I change the <a> to <button> then the text gets in the center. Why is the text not getting centrally aligned when I use <a>?
<ul class="navbar-nav navbar-right">
<ng-container *ngIf = "userNotloggedIn">
<li >
<form class="form-inline" [formGroup]="loginForm" (ngSubmit)="signInUser()" novalidate>
<label for="username" class="control-label required sr-only">Username</label>
<input type="text" id="username" class="form-control" placeholder="username" formControlName="userName" [ngClass]="validateField('userName')" required>
<app-show-errors [control]="loginForm.controls.userName"></app-show-errors>
<label for="password" class="control-label required sr-only">Password</label>
<input type="password" id="password" class="form-control" placeholder="password" formControlName="password" [ngClass]="validateField('password')" required>
<app-show-errors [control]="loginForm.controls.password"></app-show-errors>
<button type="submit" id="login-button" class="btn content-div__button--blue btn-sm">Sign In</button>
</form>
</li>
<li class="nav-item" >
<a class="nav-link" [routerLink]="signupRouterLink" id="signup-link" class="btn content-div__button--blue btn-sm">Sign Up</a> <!-- Sign Up is not in center but if I change <a> to button then the text comes in center -->
</li>
</ng-container>
<ng-container *ngIf="!userNotloggedIn" >
<li class="nav-item" >
<a id="profile-link" [routerLink]="" (click)="onProfileClick()" class="btn content-div__button--blue btn-sm">My Profile</a> <!-- My Profile is not in center but if I change <a> to button then the text comes in center -->
</li>
<li class="nav-item" >
<a [routerLink]="" id="signout-link" (click)="onSignoutClick()" class="btn content-div__button--blue btn-sm">Sign out</a> <!-- Sign Out is not in center but if I change <a> to button then the text comes in center -->
</li>
</ng-container>
</ul>

a is an inline-element where centering won't have any effect since it's only as wide as its contents (regardless if there's a widthsetting or not). Add display: inline-block to that CSS rule, that should solve your problem by making the a tag an inline-block which takes on the defined width.

Related

How to make a span with glyphicon as a hyperlink?

I have some form with glyphicon question mark for field inline tooltip on right:
<div class="form-group required">
<label for="username" class="col-sm-2 control-label">User Name:</label>
<div class="col-sm-3 tooltip-box">
<input id="username" type="text" class="form-control" placeholder="username"/>
<div class="row tooltip-block"><a href="#" data-toggle="popover" data-trigger="hover" data-placement="auto right" data-content="Test tooltip.">
<span class="glyphicon glyphicon-question-sign"></span></a>
</div>
</div>
</div>
In full screen it looks as I need:
But on mobile devices or small screens it works only with hovering some very small area within my glyphicon mark and the tooltip overlays it:
Also when I inspect the corresponding a element in Chrome's developer tools, it points to some area outside the span element:
Here is the fiddle: https://jsfiddle.net/r2cm9c9u/
How is it possible to make the whole span with glyphicon as a hyperlink for tooltip?
I would move the positioning to the actual link and make the link and glyphicon a block element:
I have added a class to the link below
<div class="form-group required">
<label for="username" class="col-sm-2 control-label">User Name:</label>
<div class="col-sm-3 tooltip-box">
<input id="username" type="text" class="form-control" placeholder="username" />
<div class="row tooltip-block">
<a href="#" data-toggle="popover" data-trigger="hover" data-placement="auto right" data-content="Test tooltip." class="glyphicon-holder">
<span class="glyphicon glyphicon-question-sign"></span></a>
</div>
</div>
</div>
And changed your classes:
.tooltip-box .glyphicon-holder {
position: absolute;
top: 8px;
right: 22px;
font-size: 1.25em;
display: block;
}
.tooltip-box .glyphicon-holder:hover {
text-decoration: none;
}
.glyphicon.glyphicon-question-sign {
color: gray;
display: block;
}
Updated fiddle
You can do it with pure css.
If you have:
<div class="col-sm-3 tooltip-box">
<input id="username" type="text" class="form-control" placeholder="username"/>
<div class="row tooltip-block"><a href="#" data-toggle="popover" data-trigger="hover" data-placement="auto right" data-content="Test tooltip.">
<span class="glyphicon glyphicon-question-sign"></span></a>
</div>
</div>
You don't need 'a' first of all. What you can do with CSS is:
.tooltip-block span {
display: none;
}
.tooltip-block:hover + span {
display: block;
}
Whats gonna happen is, when you hover over .tooltip-block following span element will display block. Definitely don't need javascript for a thing like this.
Then if you want that tooltip to be clickable you can use javascript for that.
<div class="col-sm-3 tooltip-box">
<input id="username" type="text" class="form-control" placeholder="username"/>
<div class="row tooltip-block" onclick="doSomething()"><a href="#" data-toggle="popover" data-trigger="hover" data-placement="auto right" data-content="Test tooltip.">
<span class="glyphicon glyphicon-question-sign"></span></a>
</div>
</div>

Two-column unordered list - keeping each li's content in one column

Best described by example.
I have two issues that I couldn't solve after hours of researching.
1) Stop HTML separating a single li content. For example, we can see that Group C heading in rendered in the first column, and the rest is rendered in the second.
2) Render the OK button so that it is out of the ul - in the left or right corner of the drop-down room.
<div>
<span style='cursor:pointer; float:right'>
<div class="btn-group pull-right">
<button id = 'majic' type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-cog"></span>
</button>
<ul style='padding:10px; width:auto' class="dropdown-menu zeon-search-settings-dropdwown-menu zeon-two-columns-ul">
<li class="dropdown-submenu zeon-dropdown-submenu">
<div class='section-heading-3'>Group A</div>
<div>
<label class='zeon-input-label'>
<input id="white_agreements_filter" type="checkbox" name="vehicle" checked class='zeon-checkbox' />Choice</label>
</div>
<div>
<label class='zeon-input-label'>
<input id="black_agreements_filter" type="checkbox" name="vehicle" checked class='zeon-checkbox' />Choice</label>
</div>
</li>
<li class="dropdown-submenu zeon-dropdown-submenu">
<div class='section-heading-3'>Group B</div>
<div>
<label class='zeon-input-label'>
<input id="cash_payment_filter" type="checkbox" name="vehicle" checked class='zeon-checkbox' />Choice</label>
</div>
<li class="dropdown-submenu zeon-dropdown-submenu">
<div class='section-heading-3'>Group C</div>
<div class="row">
<div class="col-sm-1">
</div>
<div class="col-sm-7">
<form>
<label class="radio-inline">
<input type="radio" name="optradio">
< </label>
<label class="radio-inline">
<input type="radio" name="optradio">=
</label>
<label class="radio-inline">
<input type="radio" name="optradio">>
</label>
</form>
</div>
<div class="col-sm-4">
<input class="form-control input-sm" id="inputsm" type="text" placeholder='количетсво дней'>
</div>
</div>
</li>
<li class="dropdown-submenu">
<div class='section-heading-3'>Group D</div>
<div>
<label class='zeon-input-label'>
<input id="full_package_filter" type="checkbox" name="vehicle" checked class='zeon-checkbox' />Choice</label>
</div>
<div>
<label class='zeon-input-label'>
<input id="not_full_package_filter" type="checkbox" name="vehicle" checked class='zeon-checkbox' />Choice</label>
</div>
</li>
<li class="dropdown-submenu">
<button id='vendor_list_filter_ok_button' type="button" class="next btn btn-default btn-sm pull-left">ОК</button>
</li>
</ul>
</div>
</span>
</div>
You can use flexbox for that (You can play with the height of the ul.dropdown-menu, if you add more height the group-c block will move to the left column)
This is the added css:
.open>ul.dropdown-menu {
display: flex;
width: 400px !important;
flex-wrap: wrap;
flex-direction: column;
height: 250px;
}
ul.dropdown-menu li {
width: 50%;
}
Here is the working jsfiddle:
https://jsfiddle.net/p6yf17du/
Update
If you don't care (or if you can change the markup) about the order of the elements you can use:
.open>ul.dropdown-menu {
display: flex;
width: 400px !important;
flex-wrap: wrap;
}
This will change the order of your elements from
A | C
B | D
to
A | B
C | D
However, this way you don't need to set the height of the menu (only the width, which makes sense to me).
You can check here:
https://jsfiddle.net/m0rg1uoe/
You can try to solve this issue adding to last <li> element the column-span property. Applying this rule with value all it will force the last <li> element to cover all the columns.
For example see the following code:
HTML:
...
<li class="dropdown-submenu btn-confirm">
<button id='vendor_list_filter_ok_button' type="button" class="next btn btn-default btn-sm pull-left">ОК</button>
</li>
...
CSS:
.btn-confirm {
-webkit-column-span: all;
column-span: all;
}
Once that last element cover both columns, also Group C heading will displayed correctly.
You can find a live demo here.
Attention: column and column-span properties have some issues in different browsers. See caniuse website and check browsers support.
Try This
.zeon-dropdown-submenu {
margin-top: 10px;
min-height: 100px;
}

jQuery Mobile: Blue focus halo gets clipped when placing controls inside ui-grid

Im trying to group text fields together on the same line using "ui-grid-a".
But the blue halo gets clipped on the left and right side of the fields.
<ul data-role="listview" data-inset="true">
<li>
<label>Label A</label>
<input data-id="name" type="text" value="" placeholder="" title="">
</li>
<li>
<div class="ui-grid-a">
<div class="ui-block-a">
<label>Label B</label>
<input data-id="email" type="text" value="" placeholder="" title="">
</div>
<div class="ui-block-b">
<label>Label C</label>
<input data-id="phone" type="text" value="" placeholder="" title="">
</div>
</div>
</li>
</ul>
Sample here: http://jsfiddle.net/N8ZUt/1/
Set focus to "label a" and then "label b" and you should see the difference.
You just need to add a little padding:
li .ui-block-a, li .ui-block-b {
padding-right: 4px;
padding-left: 4px;
}
Also, to keep things aligned, I have put your first list item in a ui-grid-solo with the same padding.
Here is your updated fiddle: http://jsfiddle.net/ezanker/N8ZUt/4/

Wrap a contact form around background image

How do I wrap a contact form around a backgroud image (eg. a desktop screen). For further clarification, please visit this link. Scroll down to the bottom of the page and you'll see a mac screen background wraped inside of a login page.
<div id="new_div_3">
<form class="contact_form" action="#" method="post" name="contact_form">
<ul>
<li>
<h2>Contact Us</h2>
<span class="required_notification">* Denotes Required Field</span>
</li>
<li>
<label for="name">Name:</label>
<input type="text" placeholder="John Doe" required />
</li>
<li>
<label for="email">Email:</label>
<input type="email" name="email" placeholder="john_doe#example.com" required />
<span class="form_hint">Proper format "name#something.com"</span>
</li>
<li>
<label for="website">Website:</label>
<input type="url" name="website" placeholder="http://johndoe.com" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Submit Form</button>
</li>
</ul>
</form>
</div>
This is what i currently have in my new_div_3.
#new_div_3 {
margin:0 auto;
width: 500px;
background:#ECF0F1 url('img/email-screen.png') 0 0 no-repeat;
background-size: 1040px 878px;
padding: 38px 38px 267px;
}
Is there a way of making the background appear correctly, in the center of the div with the addition of the contact form appearing in the center too?
I think you're looking for something like:
background:#ECF0F1 url('img/email-screen.png') no-repeat center center;
If you are using firefox or chrome, you can use inspect element to see how it has been setup in the example you provided.

Center a div that contains a contact form

How do I center a contact form which is inside a div. I have tried margin:0 auto; and it didn't work.
<div id="new_div_3">
<form class="contact_form" action="#" method="post" name="contact_form">
<ul>
<li>
<h2>Contact Us</h2>
<span class="required_notification">* Denotes Required Field</span>
</li>
<li>
<label for="name">Name:</label>
<input type="text" placeholder="John Doe" required />
</li>
<li>
<label for="email">Email:</label>
<input type="email" name="email" placeholder="john_doe#example.com" required />
<span class="form_hint">Proper format "name#something.com"</span>
</li>
<li>
<label for="website">Website:</label>
<input type="url" name="website" placeholder="http://johndoe.com" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Submit Form</button>
</li>
</ul>
</form>
</div>
I have tried using various methods and none of them seem to work to center the div. I even tried centering the contact form itself and it just moved the input fields to the center of the contact form, rather than the div.
In order to get margin: 0 auto; work you need to set width.
#new_div_3 {
width: 500px;
margin: 0 auto;
}
Check the fiddle:
http://jsfiddle.net/9cMAC/
#new_div_3 {
width:100%;
display:block;
margin:auto;
}
Should be all you need.
Here you go:
#new_div_3 {
margin: 0 auto;
position: relative;
width: 60%;
}
check fiddle

Resources