I have 2 spans in the same line with several elements in each one.
How can I add css styles to my 2 spans and make one be centered, the other one in the same line shouldn't move the previous one (centered), but it should bind to its right corner.
HTML
<span><!-- should be centered-->
<a id="3"></a><span id="2"> ..... </span>
<a id="1">...</a>
</span>
<span><!-- left corner of this span should meet the right corner of the previous span -->
<label>something</label><input type="text" id="5">
<input type="button" />
</span>
<span class="mrRight"><!-- float right here --> ...... </span>
You need to set the first spans margin-left to 48%. Or if you want to be precise, margin-left: calc(50% - x), where x is half of the width of the first span.
fiddle
Note: the gradient is there just to show you where the center is :)
.center { margin-left: calc(50% - 26px) }
To achieve this firstly you need to add a wrapper around the spans like so
HTML
<div class="span_wrapper">
<span>
<a id="3"></a><span id="2"> center </span>
<a id="1">center</a>
</span>
<span>
<label>something</label>
<input type="text" id="5"> <input type="button" />
</span>
<span class="mrRight"> right </span>
</div>
Now the appropriate CSS should be
.span_wrapper {
text-align: center;
}
.span_wrapper .mrRight{
float: right;
}
.span_wrapper {
text-align: center;
}
.span_wrapper .mrRight{
float: right;
}
<div class="span_wrapper">
<span>
<a id="3"></a><span id="2"> center </span>
<a id="1">center</a>
</span>
<span>
<label>something</label>
<input type="text" id="5"> <input type="button" />
</span>
<span class="mrRight"> right </span>
</div>
Related
I have 2 big buttons and a text field between them. At the moment, it looks like this:
But I am trying to get it to look like this:
Here is my code:
.input-group-btn {
width: 90%;
height: 90%;
}
#quantity {
font-size: 40px;
width: 5%;
height: 90%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.1/css/all.css">
<div class="col-md-12 offset-md-4">
<div>
<span> <button type="button" class="quantity-left-minus btn btn-danger btn-number" style="font-size: 50px;" data-type="minus" data-field=""> <span class="fa fa-minus-circle"></span> </button>
</span>
<span><input type="text" id="quantity" name="quantity" class="input-number" value="1" min="1" max="100"></span>
<span><button type="button" class="quantity-right-plus btn btn-success btn-number" style="font-size: 50px;" data-type="plus" data-field=""> <span class="fa fa-plus-circle"></span> </button>
</span>
</div>
<br>
<br>
<span>STAMPA</span>
</div>
I added .buttons-wrapper { display: flex; align-items: center; } to make it aligned vertically, and some padding to the text input,
Check this code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div class="col-md-12 offset-md-4">
<div class="buttons-wrapper">
<span>
<button type="button" class="quantity-left-minus btn btn-danger btn-number" style="font-size: 50px;"
data-type="minus" data-field="">
<span class="fa fa-minus-circle"></span> </button> </span>
<span>
<input type="text" id="quantity" name="quantity" class="input-number" value="1" min="1" max="100">
</span>
<span>
<button type="button" class="quantity-right-plus btn btn-success btn-number" style="font-size: 50px;"
data-type="plus" data-field=""> <span class="fa fa-plus-circle"></span> </button></span>
</div>
<br>
<br>
<span><a href="" class="btn btn-primary btn-lg active" role="button" aria-pressed="true" style=" font-size: 50px;"
id="printLabel" onclick="dowloadFileJS()">STAMPA</a></span>
</div>
<style>
.input-group-btn {
width: 90%;
height: 90%;
}
.buttons-wrapper {
display: flex;
align-items: center;
}
#quantity {
font-size: 40px;
width: 65px;
padding: 12.5px 0;
margin: 0 10px;
}
</style>
Why did you wrap your elements in <span> ?
Personally I would get rid of all the unnecessary <span>, and if I need to wrap any element I would use <div>.
Sizes in percentag refer to the parent's size.
The parents of .input-group-btn and #quantity are <span> elements.
<span> is an inline element. That means it cannot have a fixed size (height, width, margin cannot be defined). They match to their children's size.
Since your <input> and <button> do not have a fixed size defined, they are sized to default. So the parent inline element (<span>) also sizes to that default.
Then your height: 90% is computed. Relating to the parent that has no fixed size.
That means your <input> and <button> are just scaled down to 90% from their default height.
Hint: It is always tricky to use percentage values for sizing and is therefore not recommended for every case.
See also:
CSS – why doesn’t percentage height work?
Percentage Height HTML 5/CSS
I've added some padding to the text input box to increase the height and added some offset from the top to align. This is of course if you must keep the span elements. https://jsfiddle.net/31v0aupc/1/.
#quantity{
font-size: 40px;
width:5%;
height:85%;
padding: 18px 0;
position: relative;
top:10px;
}
If you can, try using inline-flex.
div {
display: inline-flex;
align-items: center;
}
I have the following html structure
<div class="search">
<div class="input-group">
<div class="input-group-btn" ng-show="categoryEnabled === true">
<div isteven-multi-select
input-model="categories"
output-model="chosenCategories">
</div>
</div>
<div class="typeahead-search">
<input type="text" ng-model="searchData.searchTerm"
placeholder="{{searchPlaceHolder}}"
class="form-control typeahead"
focus-on="categoryComplete" typeahead-min-length="2"
uib-typeahead="item.DisplaySearchText as
item.DisplaySearchText for item in
getProductsForTypeahead($viewValue)">
</div>
<span class="input-group-btn">
<button class="btn btn-default btn-search">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
I set the width of typeahead-search div to 100%.
But the width of the typeahead is bigger than the div.
Upon inspection, the typeahead's width of 100% takes it from the topmost div (class="search")
How do I make it the same width as the input?
Thanks in advance.
NM
Since .dropdown-menu is positioned absolute, adding position: relative; to the div wrapping around your uib-typeahead input field and setting width: 100%; to your .dropdown-menu will fix it.
Your CSS would look something like this:
.typeahead-search {
position: relative;
}
.dropdown-menu {
width: 100%;
}
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 :)
Given the following example, what would be a good approach to position the Search button in line with the date input controls?
I gave it a shot with Bootstrap (2 rows, 3 columns) but the layout should stick to the left and keep the 3 logical columns together. And maybe there's an easier solution I am overlooking.
JS Bin HTML
Note: based on the simplified output from Telerik's Kendo UI combined with ASP.NET MVC.
Flexbox requires IE10+
Here is the solution that works everywhere and won't break bootstrap's responsiveness http://output.jsbin.com/ladezahija/1/
Idea is to apply to elements (blocks with date and search button) next rule:
.element {
display: inline-block;
vertical-align: bottom;
}
In an example I had to use float: none to redefine previously added property by bootstrap.
Also make sure you add a separate class for container and inner elements you work on.
I would go with CSS Flex.
using this CSS would align them for you. (you will need some vendor prefixes)
$("#datepicker").kendoDatePicker();
$("#grid").kendoGrid({
dataSource: [
{ foo: "foo", bar: "bar" }
]
});
.container-fluid {
display: flex;
justify-content: space-around;
}
.container-fluid > div {
align-self: flex-end;
}
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<div class="container-fluid">
<div style="margin: 20px; float: left;">
<h4>
<label for="StartDate">From</label>
</h4>
<span class="k-widget k-datepicker k-header">
<span class="k-picker-wrap k-state-default">
<input name="startDate" class="k-input" id="startDate" role="combobox" aria-disabled="false" aria-expanded="false" aria-readonly="false" aria-owns="startDate_dateview" style="width: 100%;" type="text" value="1-11-2015" data-val="true" data-role="datepicker" />
<span class="k-select" role="button" unselectable="on">
<span class="k-icon k-i-calendar" unselectable="on">select</span>
</span>
</span>
</span>
</div>
<div style="margin: 20px; float: left;">
<h4>
<label for="EndDate">To</label>
</h4>
<span class="k-widget k-datepicker k-header">
<span class="k-picker-wrap k-state-default">
<input name="endDate" class="k-input" id="endDate" role="combobox" aria-disabled="false" aria-expanded="false" aria-readonly="false" aria-owns="endDate_dateview" style="width: 100%;" type="text" value="24-12-2015" data-val="true" data-role="datepicker" />
<span class="k-select" role="button" unselectable="on">
<span class="k-icon k-i-calendar" unselectable="on">select</span>
</span>
</span>
</span>
</div>
<div style="margin: 20px; float: left;">
<button tabindex="0" class="k-button" id="applyFilters" role="button" aria-disabled="false" data-role="button">Search</button>
</div>
</div>
You didn't used bootstrap properly. Anyway I have two solution.
First Solution:=> Add a blank h4 <h4> </h4> into last div.
Second Solution:=> Use margin-top:60px to k-button.
I'm currently trying to edit the RES userbar for my subreddit. It looks like this:
It also collapses.
I want to float almost all of the elements to the right so that they are lined up vertically. The html for the bar is:
<div id="header-bottom-right" class="res-navTop">
<div id="userbarToggle" title="Toggle Userbar" class="userbarHide">»</div>
<span class="user">
<a href="http://www.reddit.com/user/snowe2010/" style="margin-right: 2px;">
snowe2010
</a>
<span id="RESAccountSwitcherIcon"></span>
(
<span class="userkarma" title="">
<a title="link karma" href="/user/snowe2010/submitted/">9</a>
·
<a title="comment karma" href="/user/snowe2010/comments/">
2170
</a>
</span>
)
</span>
<span class="separator">|</span>
<a title="no new mail" href="http://www.reddit.com/message/inbox/" class="nohavemail" id="mail"></a>
<a id="mailCount" href="/message/unread/"></a>
<span class="separator">|</span>
<a title="no new mod mail" href="http://www.reddit.com/message/moderator/" class="nohavemail" id="modmail">mod messages</a>
<span class="separator">|</span>
<ul class="flat-list hover">
<li>
preferences</li>
</ul>
<span class="separator">|</span>
<span id="openRESPrefs">
<span id="RESSettingsButton" title="RES Settings" class="gearIcon newNotification">
</span>
</span>
<span class="separator">|</span>
<form method="post" action="/logout" class="logout hover">
<input type="hidden" name="uh" value="zoimwqbhhl59526448277e691374c3d0bc47706bb35d0045b9">
<input type="hidden" name="top" value="off">
logout
</form>
</div>
I've currently tried setting each element to a block and then floating right, but that isn't working. I've also tried setting them to display: table-cell; and aligning it, but that isn't working either.
Can anybody help me with this?
#header-bottom-right a {
display: block;
float: right;
}
#header-bottom-right .separator { display: none; }
This is a pretty unrefined approach, but it's a starter. There's plenty of room for smoothing out the rough edges if you want to continue with this approach.