I need to right align a hyperlink in a <div>, however the only way I can get it to move right is to use the <p> tag. This puts the hyperlink on a new line rather than the same line.
How can I get it on the same line, and also give some spacing? Right now it looks like a run on sentence
<div>
<label class="control-label" for="ddlProfile">Profile:</label>
<input type="text" data-ng-model="viewModel.Name" class="form-control" />
<button >New</button>
<button >Edit</button>
<p style="text-align:right; display:block; margin:auto"><a href="https://www.w3schools.com" >Open New Form</a>
Display Detail</p>
</div>
You can use flexbox for this. Wrap the content in two parts - one for the left side, and another for the right. Then use margin to position the right side as you want.
.flex {
display: flex;
}
.right {
margin-left: auto;
}
/* your second question */
.right a {
margin-left: 1em;
}
<div class="flex">
<div class="left">
<label class="control-label" for="ddlProfile">Profile:</label>
<input type="text" data-ng-model="viewModel.Name" class="form-control" />
<button>New</button>
<button>Edit</button>
</div>
<div class="right">
Open New Form
Display Detail
</div>
</div>
Why not just float the elements to the right? but you need to change the order of the elements.
.float-right{
float:right;
}
.right-space{
padding-right:10px;
}
<div>
<label class="control-label" for="ddlProfile">Profile:</label>
<input type="text" data-ng-model="viewModel.Name" class="form-control" />
<button>New</button>
<button>Edit</button>
<a class="float-right" href="https://www.w3schools.com">Display Detail</a>
<a class="float-right right-space" href="https://www.w3schools.com">Open New Form</a>
</div>
Related
I want to design a series of horizontal checkboxes where the checkboxes are located on the right side of the labels.
This is what I have written where the labels are located on the left side.
.add-margin {
margin-top: 10px !important;
}
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label>
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<span>{{opt}}</span><br/>
<span><i>{{descriptions[$index]}}</i></span>
</label>
</div>
</div>
How can I fix this?
Use the code like this
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label>
<span>{{opt}}</span>
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<br/>
<span><i>{{descriptions[$index]}}</i></span>
</label>
</div>
</div>
If I understand your question correctly, you want the checkbox on left and the text on right with opt and description on separate rows.
You need to add some styles like following and provide relevant classes. I hope this helps.
HTML
<div>
<div ng-init="loaded()" ng-class="{'add-margin': descriptionsAvailable}" class="checkbox-inline" ng-repeat="opt in options track by $index">
<label class="container">
<input ng-disabled="answer['none']" type="checkbox" ng-model="answer[opt]" ng-true-value="true" ng-false-value="false" name="checkbox-answer-input" display= inline-block >
<div class="description">
<span>{{opt}}</span><br/>
<span><i>{{descriptions[$index]}}</i></span>
</div>
</label>
</div>
</div>
CSS
.add-margin {
margin-top: 10px !important;
}
.container {
display: flex;
flex-direction: row-reverse;
}
.description {
margin-right: 8px;
}
Here is a screenshot of how I assume you want the data to show up. If you require a different layout, then let me know
In my project, I have a dialog div with four labels, four text input, one submit button and one shutdow button.
I want it appears like this:
AAAAAAAA:input text
BBBBBBBB:input text
CCCCCCCC:input text
DDDDDDDD:input text
submit shutdown
But acturally, it does not appear format, it likes this:
AAAAAAAA:input text
BBBBBBBB:
input text
CCCCCCCC:input text
DDDDDDDD:
submit input text
shutdown
It is ugly, I don't want it like that.
Here is my css and html code:
<style>
.addDiv{width:25%;height:20%;position:absolute;top:35%;left:35%;border:2px solid #ffffff;color:white;display:none;border-radius:15px;background:rgba(0,0,0,0.7);}
.firDiv{height:80%;width:100%}
.firDiv label{float:left;margin-left:10%;margin-top:2%;width:20%}
.firDiv input{float:right;border:1px solid #99ccff;background:rgba(0,0,0,0.35);margin-right:10%;
margin-top:2%;color:white;width:45%}
.secDiv{height:20%;text-align:center;width:100%;margin-top:5%}
</style>
<div id="addCnt" class="addDiv">
<form action="mng.php?act=add&table=IDC" method="POST">
<div class="firDiv">
<label>AAAAAAA:</label><input type="text" name="prdSty"><br />
<label>BBBBBBB:</label><input type="text" name="diffLvl"><br />
<label>CCCCCCC:</label><input type="text" name="repTm"><br />
<label>DDDDDDD:</label><input type="text" name="fixTm"><br />
</div>
<div class="secDiv">
<input type="submit" value="add" /><input id="sdnBt" type="button" value="shutdown" >
</div>
</form>
</div>
Who can help me?
may be something like this?
* {
box-sizing: border-box;
}
.firDiv label {
padding: 5px;
text-align: right;
float: left;
width: 17%;
}
.firDiv .control {
float: left;
width: 83%;
}
.form-group {
clear: both
}
.secDiv {
margin-left: 16%;
padding-top:10px;
}
<form action="mng.php?act=add&table=IDC" method="POST">
<div class="firDiv">
<div class='form-group'>
<label>AAAAAAA:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>BBBBBBB:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>CCCCCCCC:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
<div class='form-group'>
<label>DDDDDDDDD:</label>
<div class='control'><input type="text" name="prdSty"></div>
</div>
</div>
<div class="secDiv">
<input type="submit" value="add" />
<input id="sdnBt" type="button" value="shutdown">
</div>
</form>
Two things you need to do here. First you have to clear the floats after the first Div completed. Second is apply float left to your input fields.
.firDiv input{float:left;border:1px solid #99ccff;background:rgba(0,0,0,0.35);margin-right:10%;
margin-top:2%;color:white;width:45%;}
.secDiv{height:20%;text-align:center;width:100%;margin-top:10%; clear:both;}
I have applied clear:both in secDiv and float:left in firDiv.
DEMO
add this to your css fiddle
.secDiv input {
width: 50%;
}
Rather try adding each input and label to their own div, something like this:
https://jsfiddle.net/ba0cL61b/5/
What this does is adds a div .row inside your firDiv div and inside the .row adds a div for your label and one for your input. So it would look like this:
<div class="row">
<div class="label">
<label>AAAAAAA:</label>
</div>
<div class="input">
<input type="text" name="prdSty">
</div>
</div>
This is a bit easier to understand and style.
I have three elements inside a div. I want to position one on the left, one in the middle and the last one on the right. I have tried the following:
.search-form {
float: right;
}
.menu_icon:before {
content:url(/sites/all/themes/mytheme/images/hamburger.png);
}
.main_logo {
margin: 0% auto;
}
.main_logo:before {
content:url(/sites/all/themes/mytheme/images/logop.png);
}
.menu_icon {
float: left;
}
<div class="fixed">
<div class="fixed-container">
<form action="/search/node" method="post" id="search-form" class="search-form">
<div class="form-item">
<input type="text" class="input-text" value="Search the website" onFocus="this.value=''" onBlur="if(this.value=='') this.value='Search the website';" size="25" name="keys" />
<input type="submit" value="" name="op" alt="Search" />
<input type="hidden" value="<?php print drupal_get_token('search_form'); ?>" name="form_token" />
<input type="hidden" value="search_form" id="edit-search-form" name="form_id" />
<input type="hidden" name="type[your_content_type]" id="edit-type-your_content_type" value="your_content_type" />
</div>
</form>
</div>
</div>
Also I have tried to individually wrap those elements in divs and applying styles to those divs instead of elements. But the logo always sticks to the menu icon as it can be seen from the snippet below. Why it's not working?
Currently your a is displayed as inline, which makes it unable to be centered as a block.
Also, display:block does not work on its own with margin:0 auto, as blocks have an understood width of 100%. You also need a given width for it to work.
.first {
float:right;background:red;
}
.second{
float:left;background:blue;
}
.third{
margin:0% auto;background:gold;
display:block;width:10em;
/*Unnecessary but may be added*/text-align:center;
}
<div class="fixed">
<div class="fixed-container">
<span class="first">First</span>
<div class="second">Second</div>
<span class="third">Third</span>
</div>
</div>
I have the following code and I'm trying to get both of these inputs aligned centered. Where is the problem in the code?
<div class='form'>
<form class="form-inline" role="form">
<div class="text-center input-group input-group-lg">
<span class="input-group-addon">#</span>
<input class="text-center form-control" align="middle" placeholder="username" name="username" type="text">
</div>
<div class="text-center input-group input-group-lg">
<span class="input-group-addon">P</span>
<input class="text-center form-control" align="middle" placeholder="password" name="password" type="password">
</div>
</form>
</div>
<style>
.text-center {
width: 50%;
}
div {
text-align:center;
}
</style>
Both inputs are still aligned to the left.
Inputs are not text, and cannot be centered using text-align. Target the element directly in your css, like so:
input {
display: block;
margin: 0 auto;
}
This will center the inputs within the parent element.
I have some text in a link "title" and also a form box and I want the text on the left and the form on the right. However, whenever I try to do this what comes out is the line of text and then the form appears BELOW the text. I want them on the same horizontal line.
So I want with the dots: TEXT ................................. SIGN IN BOX
here is the code:
<div id="container">
<a href="index.php"><font size="6">Title</font><a>
<div id="topnav" class="topnav"> Have an account? <a href="login" class="signin">
<span>Sign in</span></a> </div>
<fieldset id="signin_menu">
<form method="post" id="signin">
<p>
<label for="username">Username or email</label>
<input id="username" name="username" value="" title="username" tabindex="4" type="text">
</p>
</form>
</fieldset>
</div>
Here is the CSS for the container:
#container {
margin:0 auto;
position:relative;
width:780px;
}
and topnav
#topnav {
font-size:11px;
line-height:23px;
padding:10px 0 12px;
text-align:right;
}
How do I accomplish the task? Thanks
DIV is a block element so will always do that. You need to make it a non-block element by setting float and display.
Besides the solution below you could use a table but that is frowned upon.
<div id="container">
<div class="titleDiv"><a href="index.php"><font size="6">Title</font><a></div>
<div id="topnav" class="topnav"> Have an account? <a href="login" class="signin">
<span>Sign in</span></a>
<fieldset id="signin_menu">
<form method="post" id="signin">
<p>
<label for="username">Username or email</label>
<input id="username" name="username" value="" title="username" tabindex="4" type="text">
</p>
</form>
</fieldset></div>
</div>
Then set your CSS to this:
#topnav {
font-size:11px;
line-height:23px;
padding:10px 0 12px;
text-align:right;
float:left; display:inline;
}
.titleDiv
{
float:left; display:inline;
}
so you want div.topnav appear on the left of the a ? Easiest would be to replace div with a non-block element such as span... otherwise see float css style