CSS - objects aren't in one row - html

I want to have these objects in one row
My HTML code looks like this:
<input type="button" class="formreturn" value="Copy Url" onclick="Copy();" />
<label><input type="text" class="txtfilename" id="op-text-filename" placeholder="type file name"/>.txt</label>
<button type="button" class="formreturn" onclick="saveURLtoTXTfile();"><span class="glyphicon glyphicon-download"></span>.TXT</button>
<button class="excelsubmit" onclick="exportData()"><span class="glyphicon glyphicon-download"></span>.CSV</button>
<button id="btnExport" class="excelsubmit" onclick="fnExcelReport();"><span class="glyphicon glyphicon-download"></span>.XLS </button>
and CSS
.formreturn {
font-weight:700;
text-decoration: none;
display:inline-block;
color:black;
background:#c6e2f2;
padding: 9px;
border-radius: 3px;
}
.copyurltext {
font-weight: bold;
margin-left: 30px;
}
.txtfilename {
display: inline-block;
float: left;
padding: 5px;
}
.excelsubmit {
font-weight:700;
float: right;
padding: 8px;
background:#c6e2f2;
}
If I place the float:left in my formreturn, then everything is fine, but the order is wrong, as the .txt button goes next to the "Copy Url" button. I want to have the order as you see below, but with everything lined up properly.
I tried something like here:
http://jsfiddle.net/A9Ap7/1/
codeproject.com/Questions/5280800/How-do-I-put-everything-in-one-line
and here
css everything on same line
but it didn't work for me
How can I fix this?

Try this:
<div class="container">
<div classs="btns-left">
<input type="button" class="formreturn" value="Copy Url" onclick="Copy();" />
<label><input type="text" class="txtfilename" id="op-text-filename" placeholder="type file name"/>.txt</label>
<button type="button" class="formreturn" onclick="saveURLtoTXTfile();"><span class="glyphicon glyphicon-download"></span>.TXT</button>
</div>
<div class="btns-right">
<button class="excelsubmit" onclick="exportData()"><span class="glyphicon glyphicon-download"></span>.CSV</button>
<button id="btnExport" class="excelsubmit" onclick="fnExcelReport();"><span class="glyphicon glyphicon-download"></span>.XLS </button>
</div>
</div>
.container {
display: flex;
justify-content: space-between;
}
.btns-left,
.btns-right {
display: flex;
}
Also, you can use properties for align elements by horizontal axis, as an example align-items: flex-start.
Or:
float: left; for btns-left and float: right; for btns-right and display: inline-block; for every element without display: flex; anywhere.
Also, can try, float for every element without any wrappers (left properties for left side, right ones for right side)
Grid layout, but it's more complicated. The best solution is applying flexbox layout for positioning elements. Better avoid floats, cause it might voke some troubles with clearing flow in future.

Try to give all elements a display: inline-block for starters (so, the button input, label and three buttons), float: left is not recommended and bad practice.

You want it all to be next to each other? Maybe start using css grid, it's useful for making things in line.
Then there's always the option of setting all these things in a navigation bar, so it's always at the top of your screen in line.
Perhaps try and create a container that holds all the buttons in place?

Related

How to add a line break into a submit input

I was looking for a way to display the value of an
<input type="submit">
on 2 lines, so potentially add a line break in it, but i tried multiple stuff such as :
<br>
\r\n
\n
The result should be like this (On the right side of the picture) :
Nothing works. Anyone got a clue on this ?
Add this to your css:
A white-space property will allow to have input in multiple lines
input[type="submit"] {
white-space: normal;
width: 150px;
float:right;
text-align: right;
}
<input type="submit" value="J'essaie gratuitement 30 jours" />
Two other methods are
<button type="submit">Multiple line<br/>input</button>
and
using
carriage return in between the input value as:
<input type="button" value="Multiple line
input" style="text-align:center;">
The last method however doesn't work in IE10
Use button instead of input:
.right-aligned {
text-align: right;
}
<button type="submit" class="right-aligned">Text <br /> broken </button>
Buttons can accept a variety of other tags inside, such as <br />, <span>.
Then, you can style it with CSS however you wish (see the CSS class and rules in the code snippet).
I think you try this in HTML:
Just as example help for you:
<input type="button" value="Really
Tall
Button">
This is working for me:
div.full {
width:500px;
background-color:grey;
}
div.left {
float:left;
width:60%
}
button {
width:40%;
text-align:right;
cursor:pointer;
}
div.underline {
width:100%;
}
<div class='full'>
<div class='left'>
there is a part of text
</div>
<button>J'essaie gratuitement
<div class='underline'>30 jours</div>
</button>
</div>
I just added some CSS to keep the size of the button. and line breaks are not a very good practice. You'd better do it with css.
Alternatively, use a standard <a> or <span> tag.
var submits = document.getElementsByClassName('submit');
for (var i = 0; i < submits.length; i++) {
submits[i].addEventListener('click', function() {
alert('submit!');
document.getElementById('form_to_submit').submit();
});
}
.submit {
text-decoration: inherit;
color: inherit;
display: inline-block;
border: 1px solid #222;
border-radius: 2px;
padding: 2px 4px;
background: #eee;
cursor:pointer;
text-align:right;
}
<p>J'essaie gratuitement<br>30 jours</p>
<p><span class="submit">J'essaie gratuitement<br>30 jours</span></p>

How to set width of a button bootstrap

How to set custom width of a bootstrap button.
My problem is that I don't know how to shrink width of button to like on the image (it's a submit button). Left part is input text. My problem is button is too wide. Here is the code:
<div class="col-xs-5 col-xs-offset-3">
<div class="input-group input-group-lg">
<input type="text" class="form-control input-lg input-forme" id="Text" placeholder="Text">
<span class="input-group-btn tipka">
<button type="submit" class="btn btn-group-small" id="form-submit">Submit</button>
</span>
</div>
</div>
You can change width and padding : https://jsfiddle.net/wz8ac5d4/
.btn {
width:0px;
padding:5px;
}
Also you can add a class to your btn, it is a better practice.
HTML:
<button type="submit" class="btn btn-group-small my-small-btn" id="form-submit">Submit</button>
CSS :
.my-small-btn {
width:0px;
padding:5px;
}
The classes that define the different sizes are:
.btn-lg
.btn-md
.btn-sm
.btn-xs
refer this link
http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
You can increase its size with this:
.btn {
width: 100%;
padding: 5px;
}
I used max-width with padding.
HTML
<button type="submit" class="btn custom-btn" id="form-submit">Submit</button>
CSS
.custom-btn {
max-width: 100%;
padding-left:25px;
padding-right:25px;
}
You can also just shortcut the padding.
.custom-btn {
max-width: 100%;
padding: 6px 25px;
}
Just adjust the 25px to whatever length you want to get the appropriate size.
Please note that 6px is the standard top and bottom padding for a medium bootstrap button. You will have to adjust accordingly for large and small buttons.

Centering an element with an adjacent element

I basically have a button that I need to align center. Next to that button I need to display something (a checkmark for example). I have been trying to do this but have run into a problem that:
1) if i use display:inline I can't center it
2) if i use display:block I can't add another element next to it
I have been trying to figure it out with display:inline-block to no avail
JFiddle: https://jsfiddle.net/2x5a5zdx/
code:
<input type="button" class='btn btn-md btn-primary' value="Submit Responses" id="submitBttn"/>
<span class="green-success" id="surveySuccess" >&#10004</span>
<span class="red-danger" id="surveyFailure" >&#10006</span>
And then the css
#submitBttn {
margin:auto;
display:inline-block;
}
#surveySuccess, #surveyFailure {
}
Thank you
As you have pointed out, margin: auto will not center an inline element.
Since inline/inline-block level elements respect the text-align property, you could simply add text-align: center to the parent element. In doing so, the children elements will be centered since they are inline by default.
Updated Example
.parent-element {
text-align: center;
}
.parent-element > span,
.parent-element > input {
display: inline-block; /* Added for example purposes */
vertical-align: middle;
}
Alternatively, in supported browsers, you could also utilize flexbox layouts and set the display of the parent element to flex and add justify-content: center for horizontal centering:
Updated Example
.parent-element {
display: flex;
justify-content: center;
}
To display the button and icons horizontally centered on the page, wrap them both in a div and set it's text-align property to center.
<div id="wrapper">
<input type="button" class='btn btn-md btn-primary' value="Submit Responses" id="submitBttn"/>
<span class="green-success" id="surveySuccess" >&#10004</span>
<span class="red-danger" id="surveyFailure" >&#10006</span>
</div>
#wrapper {
text-align: center;
}
Basic
If you want to center the button and the checks together, as a whole, centering is simple. You just need to add text-align: center to the parent element (which you may have to introduce).
.container {
text-align: center;
}
<div class="container">
<input type="button" class='btn btn-md btn-primary' value="Submit Responses" id="submitBttn" />
<span class="green-success" id="surveySuccess">&#10004</span>
<span class="red-danger" id="surveyFailure">&#10006 This content <i>does</i> affect centering.</span>
</div>
Or, if you want the button itself to be centered, regardless of the labels, you can use position: absolute to pull the labels out of the flow. This is especially useful if you want to display only one label at a time. If you display both, they will be on top of each other, so you'd have to solve that.
.container {
text-align: center;
}
#surveySuccess, #surveyFailure {
position: absolute;
margin-left: 5px;
}
#surveyFailure {
display: none;
}
<div class="container">
<input type="button" class='btn btn-md btn-primary' value="Submit Responses" id="submitBttn" />
<span class="green-success" id="surveySuccess">&#10004 Button is not moved</span>
<span class="red-danger" id="surveyFailure">&#10006 Button is not moved</span>
</div>
Personally, I'd like to show labels like that through CSS mainly, so this code is slightly altered again, adding a feedback text in the span (if you like), but adding the check or cross (and color too) in CSS by setting a class of the span. By simply adding the class success or failure you can change the way symbol and the color of the single 'surveyResult' span you have now:
.container {
text-align: center;
}
#surveyResult {
position: absolute;
margin-left: 5px;
}
#surveyResult.success {
color: green;
}
#surveyResult.success::before {
/* \2714 is the CSS (hexadecimal) notation of ✔ */
content: '\2714 ';
}
#surveyResult.failure {
color: red;
}
#surveyResult.failure::before {
content: '\2716 ';
}
<div class="container">
<input type="button" class='btn btn-md btn-primary' value="Submit Responses" id="submitBttn" />
<span class="success" id="surveyResult">You did great!</span>
</div>

Aligning html input and submit

I am having a ridiculous problem where my input text field and submit buttons are not lining up and I really can't figure out an elegant solution of how to fix it. As you can see in the image below, the input text field (labeled "Enter Keywords" in the upper right") is 2px higher than the "Search" submit button:
Here is the HTML:
<div id="search">
<form action="#" method="POST" id="search_form">
<div id="search_inputs">
<input type="text" placeholder="Enter Keywords" name="keywords" />
<input class="button" type="submit" name="search" value="SEARCH" />
</div>
</form>
</div>
Here is the css code:
#search_form .button {
background: black;
color: white;
padding: 3px 15px;
border: none;
font-size: 7pt;
height: 18px;
}
#search_form input[name="keywords"] {
width: 175px;
}
#search {
margin-top: 7px;
float: right;
}
I'm pretty sure setting the font-size to 7pt is messing it up, but I'm not sure why and I don't know how to deal with this because that's the font size of my other buttons in the area.
Thanks for any help!
adding a float: left; to the #search_form input[name="keywords"] style align's their tops correctly, then adding some margin-right should get you good to go.
Fiddle
The issue stems from the float: right on the search button. The input box has a natural display: inline-block to it, which causes the slight drop. Normally when you float right the fix to this is to move that element upwards in the DOM. This won't work in this case. By changing the input to a floated element you are also forcing it to be display: inline.
Though I'm not sure why you can't just add a display: inline to the element.

CSS need inline element to appear next to { display: block; } element

I'm trying to introduce a checkbox next to another element. The problem is that the a element has been made a "block" by the CSS so that it appears at the correct height and width. Being a block, I can't simply put another element next to it and hope it shows up there -- it shows up just below it.
A self-contained sample is shown below.
<html>
<head>
<style type='text/css'>
/* I don't have control over this */
a.btn {
background-color: #B35905;
color: #E6D389;
text-decoration: none;
font-weight: bold;
text-align: center;
display: block;
border: none;
cursor: pointer;
}
.normal{
line-height: 20px;
font-size: 12px;
height: 20px;
width: 125px;
padding: 0px;
margin: 0px;
}
</style>
</head>
<body>
<!-- I have some control over this -->
<a class="btn normal">Push Me</a><input type="checkbox">
<br>
<a class="btn normal">Push Me Too</a>
</body>
</html>
So what I'm looking for is the checkbox to appear immediately to the right of the element, but without having to completely muck up the styling of the button. Absolute positioning of the checkbox using the (known) size of the button seems wrong and dirty.
Suggestions?
<a class="btn normal" style="float: left;">Push Me</a><input type="checkbox">
<br style="clear: both;">
<a class="btn normal">Push Me Too</a>
If you must keep the anchor a block element, set float: left to it. Don't forget to add
<div style="clear: both;"></div>
after the checkbox.
Add in two more css classes
.floatingButton{
float:left;
}
.aCheckbox {
xclear:left;
}
Then
<a class="btn normal floatingButton">Push Me</a><input class="aCheckbox" type="checkbox">
<br>
<a class="btn normal">Push Me Too</a>
Should do the trick
Can you do something like this with the access that you do have?
<div style="width: 150px;">
<input type="checkbox" style="float: right;">
<a class="btn normal">Push Me</a>
</div>
Just apply a float: left to the first a tag.
The easiest possible way to get the checkbox beside the button while preserving the button's block styling would be to set the button's display property to inline-block. Surprisingly, using display: inline-block in this scenario will work in all modern browsers and IE 6 and above. inline-block is a little-known but highly useful property.