I need to make panels/divs scrollable, but they have dynamic heights. So far, the only solutions I found are using arbitrary heights in various units, which I would like to avoid. I’m trying to go the Flex route but I’m missing something...
.app {
width: 100%;
height: 100vh;
background-color: #f4f3ef;
display: flex;
flex-direction: column;
border: 2px solid red;
.topbar {
border: 2px solid lightblue;
padding: 8px;
}
.container {
display: flex;
border: 2px dashed lightpink;
.panel {
border: 2px solid lightgreen;
background-color: #f4f3efbb;
padding: 8px;
flex: 1;
.tabs {
display: flex;
justify-content: center;
border-bottom: 1px solid lightgray;
padding-bottom: 8px;
& > button:not(:first-child) {
margin-left: 20px;
}
}
.input-container {
padding: 8px;
display: flex;
justify-content: space-between;
border-bottom: 1px solid lightgray;
}
.scrollable {
overflow-y: auto;
p.message {
color: salmon;
font-weight: 500;
}
}
}
}
}
.note {
text-align: center;
}
<p class="note">The red border represents the viewport</note>
<div class="app">
<div class="topbar">Lorem ...</div>
<div class="container">
<div class="panel left-side">
<div class="tabs">
<button>Tab 1</button>
<button>Tab 2</button>
</div>
<div class="body">
<div class="input-container">
<input placeholder="Type something" />
<button>Send</button>
</div>
<divp class="scrollable">
<p class="message">This panel should be scrollable if it overflows</p>Lorem ...
Lorem ...
Lorem ...
</divp>
</div>
</div>
<div class="panel center-side">
<divp class="scrollable">
<p class="message">This panel should be scrollable if it overflows</p>Lorem ...
Lorem ...
</divp>
</div>
<div class="panel right-side">
<div class="tabs">
<button>Tab 1</button>
<button>Tab 2</button>
<button>Tab 3</button>
<button>Tab 4</button>
</div>
<div class="scrollable">
<p class="message">This panel should be scrollable if it overflows</p>Lorem...
</div>
</div>
</div>
</div>
Here’s a CodePen of a simplified version of my app: https://codepen.io/hubchau/pen/qBPqJRd
I set my content flexbox with min-height: 100%; and overflow: auto;:
https://codepen.io/logany-hi/pen/PoKLzWp?editors=1100
body {
overflow: hidden;
}
.body{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
}
/* SIDEBAR --------------------------------*/
.sidebar {
width: 340px;
color: #fff;
background: #021334;
}
.sidebar header {
text-align: center;
line-height: 50px;
border-bottom: 1px solid #fff;
background: #283562;
}
.sidebar ul {
list-style: none;
overflow: auto;
padding-left: 0;
height: calc(100vh - 50px);
margin-top: 2px;
}
.sidebar ul li.menuHeader {
padding: 15px;
color: rgba(255, 255, 255, 0.5);
border-top: 1px solid #021334;
border-bottom: 1px solid #021334;
}
.sidebar ul a {
position: relative;
display: block;
text-decoration: none;
padding: 15px 15px 17px 50px;
color: #fff;
border-bottom: 1px solid #283652;
}
.sidebar ul a:hover,
.sidebar ul a:active {
text-decoration: none;
background: #283652;
}
/* CONTENT ------------------------------------ */
.main {
flex: 1;
display: flex;
flex-direction: column;
}
.breadcrumbs {
border-bottom: 1px solid #b6bcc6;
}
.breadcrumbs ul {
list-style: none;
margin: 0;
padding: 0;
}
.breadcrumbs ul li {
line-height: 50px;
display: inline-block;
vertical-align: text-top;
}
.content {
flex: 1;
display: flex;
overflow: auto;
}
.box {
min-height: -webkit-min-content;
width:100%;
}
.page-content {
padding: 20px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<main class="body">
<nav class="sidebar">
<header>
Ortund
</header>
<ul>
<li class="menuHeader">Basics</li>
<li>Home</li>
<li>Products</li>
<li>Services</li>
<li>About</li>
<li>Contact Us</li>
<li class="menuHeader">Admin</li>
<li>Manage KPAs</li>
</nav>
<div class="main">
<div class="page-header breadcrumbs">
<ul>
<li>Home</li>
<li>.::.</li>
<li>KPAs</li>
</ul>
</div>
<div class="content">
<div class="box">
<div class="page-content">
<div style="margin-top: 5px;">
<h3>Add KPAs</h3>
</div>
<div style="padding: 20px 0;">
<div class="card" style="width: 800px; margin-bottom: 50px;">
<div class="card-body">
<form id="createForm" method="post">
<div class="form-group row pb-2">
<label class="col-sm-4" for="KPA_Evaluation_Id">Evaluation</label>
<div class="col-sm-8">
<select class="form-control" id="KPA_Evaluation_Id" name="KPA.Evaluation.Id">
<option value="">No evaluation</option>
</select>
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Name">KPA 1</label>
<div class="col-sm-8">
<input class="form-control" type="text" id="item_Name" name="item.Name" value="" />
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Description">Description</label>
<div class="col-sm-8">
<textarea class="form-control" id="item_Description" name="item.Description">
</textarea>
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Name">KPA 2</label>
<div class="col-sm-8">
<input class="form-control" type="text" id="item_Name" name="item.Name" value="" />
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Description">Description</label>
<div class="col-sm-8">
<textarea class="form-control" id="item_Description" name="item.Description">
</textarea>
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Name">KPA 3</label>
<div class="col-sm-8">
<input class="form-control" type="text" id="item_Name" name="item.Name" value="" />
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Description">Description</label>
<div class="col-sm-8">
<textarea class="form-control" id="item_Description" name="item.Description">
</textarea>
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Name">KPA 4</label>
<div class="col-sm-8">
<input class="form-control" type="text" id="item_Name" name="item.Name" value="" />
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Description">Description</label>
<div class="col-sm-8">
<textarea class="form-control" id="item_Description" name="item.Description">
</textarea>
</div>
</div>
<div class="form-group row pb-2">
<label class="col-sm-4" for="item_Name">KPA 5</label>
<div class="col-sm-8">
<input class="form-control" type="text" id="item_Name" name="item.Name" value="" />
</div>
</div>
<div class="form-group row">
<label class="col-sm-4" for="item_Description">Description</label>
<div class="col-sm-8">
<textarea class="form-control" id="item_Description" name="item.Description">
</textarea>
</div>
</div>
<div class="fixed-bottom border-top p-3 bg-white" style="left: 340px;">
<button type="submit" class="btn btn-primary btn-sm ly-button text-white save">Create</button>
<a onclick="window.history.go(-1); return false;"
class="btn btn-outline-secondary btn-sm ly-button"
style="margin-left:10px; cursor:pointer;">Cancel</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
Related
I want to do something like this
So I did the following
.page-account-box {
width: 100%;
margin-top: 70px;
}
.page-account-box .ds-userlogin .account-box {
width: 100%;
height: auto;
padding: 0;
border: 1px solid #e2efef;
position: relative;
margin: 70px auto 30px;
display: table;
background: #fff;
border-radius: 20px;
}
.page-account-box .ds-userlogin .account-box .picture_account {
display: inline;
width: 50%;
}
.page-account-box .ds-userlogin .account-box .account-box-content {
min-height: 50%;
padding: 15px 30px;
text-align: center;
border-radius: 20px;
display: inline;
}
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="container">
<div class="row">
<div class="page-account-box">
<div class="col-lg-8 col-md-8 col-xs-12 mx-auto">
<div class="ds-userlogin">
<div class="account-box">
<div class="picture_account"><img src="https://via.placeholder.com/200.jpg" class="imgFormat" /></div>
<div class="account-box-content">
<form method="post" class="form-account form-inline ">
<div class="form-account-title">
<input type="text" style="border:solid" id="FullName">
<label for="email-phone">Fullname</label>
</div>
<div class="form-account-title">
<input type="password" style="border:solid" id="Password">
<label for="password">Password</label>
</div>
<div class="form-row-account">
<a onclick="Registeruser()" class="btn btn-primary btn-register">Register </a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
but the result would be like this
how can I make the forms be inline with the picture?
how can I make the forms be inline with the picture?
Remove your CSS and in your HTML replace account-box:
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="account-box row">
<div class="account-box-content col">
<form method="post" class="form-account form-inline ">
<div class="form-account-title">
<input type="text" style="border:solid" id="FullName">
<label for="email-phone">Fullname</label>
</div>
<div class="form-account-title">
<input type="password" style="border:solid" id="Password">
<label for="password">Password</label>
</div>
<div class="form-row-account">
<a onclick="Registeruser()" class="btn btn-primary btn-register">Register </a>
</div>
</form>
</div>
<div class="picture_account col">
<img src="https://via.placeholder.com/200.jpg" class="imgFormat" />
</div>
</div>
The class of row to turn the container holding your image and form into a row, and the class of col on both your form and image to put them on separate columns. Also your image is now below the form in the markup so it appears on the left visually.
You can try adding the following to your account-box-content class:
float: left;
Here's a fiddle you can see it working on: https://jsfiddle.net/gx3y8ksc/
.page-account-box {
width: 100%;
margin-top: 70px;
}
.page-account-box .ds-userlogin .account-box {
width: 100%;
height: auto;
padding: 0;
border: 1px solid #e2efef;
position: relative;
margin: 70px auto 30px;
display: table;
background: #fff;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.page-account-box .ds-userlogin .account-box .picture_account {
display: inline;
border-radius: 0 20px 20px 0;
overflow: hidden;
}
.page-account-box .ds-userlogin .account-box .account-box-content {
width: 100%;
max-width: 250px;
margin-right: auto;
padding: 15px;
text-align: center;
border-radius: 20px;
display: inline;
}
.page-account-box .ds-userlogin .account-box .account-box-content form {
width: 100%;
}
.page-account-box
.ds-userlogin
.account-box
.account-box-content
form
.form-account-title {
width: 100%;
margin: 0 0 10px 0;
}
.page-account-box
.ds-userlogin
.account-box
.account-box-content
form
.form-account-title
input {
width: 100%;
}
<!-- Bootstrap-4 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="container">
<div class="row">
<div class="page-account-box">
<div class="col-lg-8 col-md-8 col-xs-12 mx-auto">
<div class="ds-userlogin">
<div class="account-box">
<div class="account-box-content">
<form method="post" class="form-account form-inline ">
<div class="form-account-title">
<input type="text" style="border:solid" id="FullName">
<label for="email-phone">Fullname</label>
</div>
<div class="form-account-title">
<input type="password" style="border:solid" id="Password">
<label for="password">Password</label>
</div>
<div class="form-row-account d-flex justify-content-center w-100">
<a onclick="Registeruser()" class="btn btn-primary btn-register">Register </a>
</div>
</form>
</div>
<div class="picture_account"><img src="https://via.placeholder.com/200.jpg" class="imgFormat" /></div>
</div>
</div>
</div>
</div>
</div>
</div>
I'm using Bootstrap 4 and want to make a grid view. The problem is that my columns don't have the same width. Also, the height of the columns are not the same as you can see on the borders.
I've read that the columns in Bootstrap 4 should have the same height and width natively, but somehow it seems not to work for me. I'd be glad if someone could help me.
Here's the code of my grid.
.grid-header {
background-color: #002f5a;
color: white;
height: 70px;
font-weight: bold;
font-size: 14pt;
}
.grid-header .col-sm {
border: 1px solid white;
padding: 10px 20px 10px 20px;
}
.grid-row {
border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray;
border-left: 1px solid lightgray;
}
.grid-column-value {
padding: 10px 10px 10px 10px;
border-right: 1px solid lightgray;
}
.grid-filter {
padding: 10px 0 10px 0;
border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray;
border-left: 1px solid lightgray;
}
.grid-filter-column {}
.grid-edit-form {
padding: 10px 0 10px 0;
}
.grid-edit-row {
padding: 0 15px 0 15px;
border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray;
border-left: 1px solid lightgray;
}
.grid-row.selected,
.grid-row:hover {
background-color: #002f5a;
color: white;
}
.grid-action-column {
float: right;
}
.grid-action-column>.btn {
margin-right: 10px;
}
.grid-edit-btn {
background-color: yellow;
}
.grid-edit-btn:hover {
background-color: #ebd234;
}
.grid-delete-btn {
background-color: red;
color: white;
}
.grid-delete-btn:hover {
background-color: darkred;
color: white;
}
.grid-edit-form-buttons {
float: right;
}
.grid-edit-form-buttons>.btn {
margin-left: 10px;
}
<div class="container-fluid">
<div class="grid-header row align-items-center">
<div class="col">Identifier</div>
<div class="col">Der Name</div>
<div class="col">Beschreibung</div>
<div class="col">E-Mail</div>
<div class="col">Link</div>
<div class="col">Erstellt am: </div>
<div class="col"></div>
</div>
<div class="grid-filter row">
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="number" class="form-control" id="inlineFormInputGroup-Id-filter">
</div>
</div>
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="text" class="form-control" id="inlineFormInputGroup-Name-filter">
</div>
</div>
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="" class="form-control" id="inlineFormInputGroup-Description-filter">
</div>
</div>
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="" class="form-control" id="inlineFormInputGroup-EmailAddress-filter">
</div>
</div>
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="" class="form-control" id="inlineFormInputGroup-TestUrl-filter">
</div>
</div>
<div class="col grid-filter-column">
<div class="input-group">
<div class="input-group-prepend"><i class="input-group-text fas fa-filter"></i></div>
<input type="date" class="form-control" id="inlineFormInputGroup-CreatedAt-filter">
</div>
</div>
<div class="col grid-filter-column"></div>
</div>
<div class="grid-row row align-items-center" id="grid-row-1">
<div class="col grid-column-value">1</div>
<div class="col grid-column-value">Hans</div>
<div class="col grid-column-value">This is some cool description</div>
<div class="col grid-column-value">hans.peter#example.net</div>
<div class="col grid-column-value">https://www.google.de/</div>
<div class="col grid-column-value">05.08.2020 13:53:25</div>
<div class="col grid-action-column"><button class="btn grid-edit-btn" onclick="ShowEditRow('http://localhost:5005/Home/CallApi?Id=1', '1');"><i class="fas fa-edit"></i></button><i class="fas fa-trash"></i></div>
</div>
<div class="grid-row row align-items-center" id="grid-row-2">
<div class="col grid-column-value">2</div>
<div class="col grid-column-value">Laura</div>
<div class="col grid-column-value">This is another cool description</div>
<div class="col grid-column-value">laura.g#example.net</div>
<div class="col grid-column-value">https://www.google.de/</div>
<div class="col grid-column-value">05.08.2020 13:53:25</div>
<div class="col grid-action-column"><button class="btn grid-edit-btn" onclick="ShowEditRow('http://localhost:5005/Home/CallApi?Id=2', '2');"><i class="fas fa-edit"></i></button><i class="fas fa-trash"></i></div>
</div>
</div>
Edit: I noticed that this problem is only occuring, if the content of my columns is too long. E.g. if the description is displayed in two lines. I don't want to use "text-truncate", because the content won't be fully shown then.
Insert a w-100 after each row to make them equal.
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="w-100"></div>
<div class="col">col</div>
<div class="col">col</div>
</div>
After some time I've found an answer.
The problem with the width was that the "emails" were too long and because they were "one word" (no spaces in-between) they could not got broken. So I added the following line to my css:
.grid-column-value {
...
word-break: break-word;
...
}
You can solve this problem with different solutions like the .text-truncate class from Bootstrap. It depends on your needs and preferences.
For the height I got problems because I added the class .align-items-center to my row. To solve this I removed the class from it and added following lines to my css:
.grid-column-value {
...
display: flex;
align-items: center;
}
.grid-action-column {
...
display: flex;
align-items: center;
}
This basically does the same as .align-items-center but directly targets the columns instead of the whole row.
The whole grid now looks like this:
I have the following part. I already tried to do it, but so far without any success.
.container {
width: 600px;
}
.row {
margin-bottom: 10px;
}
.item {
width: 100%;
border: 1px solid silver;
margin-bottom: 0;
display: flex;
justify-content: space-between;
min-height: 60px;
flex: 1 1 0;
}
.item > .selector {
display: flex;
align-items: center;
padding-left: 20px;
}
.item > .label-text {
background-color: silver;
color: white;
padding: 0 10px;
display: flex;
align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 1</span>
</div>
<span class="label-text">Small Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 2</span>
</div>
<span class="label-text">longer Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 3</span>
</div>
<span class="label-text">Soo long Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 4</span>
</div>
<span class="label-text">Text</span>
</label>
</div>
</div>
</div>
Sadly I'm not able to modify the structure. There are sooo much JS using the structure. But I can edit the CSS. I'm absolutely not experienced with flex box.
The text in the span.label-text elements can be any long but can't be longer than the half of it's parent width.
Its a plugin and its used in many parts. I can't just define a fix width.
Is it possible to make all span.label-text elements as wide as the one with the longest text without modifying the html or using JS for it?
Here is jQuery example with check label-text max width in all items and apply width to all label-text.
var width =0
jQuery('.item').each(function() {
if(width <= jQuery(this).children(".label-text").outerWidth())
{
width = jQuery(this).children(".label-text").outerWidth();
}
});
jQuery(".label-text").css('width',Math.ceil(width));
body { margin:0; padding:0;}
.container {
width: 600px;
}
.row {
margin-bottom: 10px;
}
.item {
width: 100%;
border: 1px solid silver;
margin-bottom: 0;
display: flex;
justify-content: space-between;
min-height: 60px;
flex: 1 1 0;
}
.item > .selector {
display: flex;
align-items: center;
padding-left: 20px;
}
.item > .label-text {
background-color: silver;
color: white;
padding: 0 10px;
display: flex;
align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 1</span>
</div>
<span class="label-text">Small Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 2</span>
</div>
<span class="label-text">longer Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 3</span>
</div>
<span class="label-text">Soo long Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 4</span>
</div>
<span class="label-text">Text</span>
</label>
</div>
</div>
</div>
Since you're using Flexbox, you can play around with the flex values of both flex-items of the .item element, e.g.:
.container {
width: 600px;
}
.row {
margin-bottom: 10px;
}
.item {
width: 100%;
border: 1px solid silver;
margin-bottom: 0;
display: flex;
justify-content: space-between;
min-height: 60px;
flex: 1 1 0;
}
.item > .selector {
display: flex;
flex: 2; /* added; makes it twice as wide as the .label-text */
align-items: center;
padding-left: 20px;
}
.item > .label-text {
background-color: silver;
color: white;
padding: 0 10px;
display: flex;
flex: 1; /* added */
align-items: center;
justify-content: center; /* added */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 1</span>
</div>
<span class="label-text">Small Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 2</span>
</div>
<span class="label-text">longer Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 3</span>
</div>
<span class="label-text">Soo long Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 4</span>
</div>
<span class="label-text">Text</span>
</label>
</div>
</div>
</div>
You can define a width for that label-text.
.container {
width: 600px;
}
.label-text {
width: 150px;
}
.row {
margin-bottom: 10px;
}
.item {
width: 100%;
border: 1px solid silver;
margin-bottom: 0;
display: flex;
justify-content: space-between;
min-height: 60px;
flex: 1 1 0;
}
.item > .selector {
display: flex;
align-items: center;
padding-left: 20px;
}
.item > .label-text {
background-color: silver;
color: white;
padding: 0 10px;
display: flex;
align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 1</span>
</div>
<span class="label-text">Small Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 2</span>
</div>
<span class="label-text">longer Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 3</span>
</div>
<span class="label-text">Soo long Text</span>
</label>
</div>
</div>
<div class="row">
<div class="col-sm-7 col-xs-12">
<label class="item">
<div class="selector">
<input type="radio" />
<span>Option 4</span>
</div>
<span class="label-text">Text</span>
</label>
</div>
</div>
</div>
I am using bootstrap for my application and I observe that it adds 15px padding. I looked up at the possible errors and it doesnt seem as if I am making any of these errors (like putting a container inside a row etc)
This is my code.
<div class="container-fluid">
<header id="topheader">
<div class="row">
<div class="col-md-3">
<h3 id="logo"><span id="d1">D</span> <span id="two">2</span> <span id="d2">D</span></h3>
</div>
<div class="col-md-9">
<form id="fullform">
<div id="formdiv" class="row">
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div style="" class="col-md-3 login">
<label for="email"></label>
<input class="login_input" type="text" name="email" placeholder="Type your email here">
</div>
<div style="" class="col-md-3 login">
<input class="login_input" type="password" name="password" placeholder="Type your password here">
</div>
</div>
</form>
</div>
</div>
</header>
</div>
I am adding my css too :
body html {
padding: 0;
margin: 0;
/*background-color: black;*/
}
.container-fluid {
padding-right:0px;
padding-left:0px;
margin-right:auto;
margin-left:auto;
}
#topheader {
position: relative;
background-color: #563d7c;
box-shadow: 8px 6px 2px black;
}
#logo {
position: relative;
left: 6vw;
/*top: -3vh;*/
color: white;
}
.login {
position: relative;
/*top: 4vh;*/
height: 12vh;
}
.login_input {
position: absolute;
top: 3vh;
}
#formdiv {
left: 5vw;
}
#d1 {
position: relative;
font-size: 5vh;
transform: rotate(40deg);
}
input{
/*background: #ecf0f1;*/
width: 15vw;
padding: 10px;
font-family: "Open Sans";
color: #7f8c8d;
border-style: solid;
border-width: 0;
border-bottom-width: 3px;
border-color: #bdc3c7;
outline: none;
border-radius: 5px 0px 5px 0px;
-webkit-transition: 0.1s ease-in-out;
}
input:focus{
border-color: #3498db;
color: #34495e;
}
#media screen and (max-width: 989px) {
#logo {
left: 35vw;
}
.login {
position: relative;
/*top: 4vh;*/
height: 7vh;
}
.login_input {
top: -1vh;
left: 25vw;
}
input {
width: 50vw;
}
}
Bootstrap immediately expects row after container-fluid class. And you are adding header tag there. Remove header tag and you can add id="topheader" to the div. row class minus 15 px. Try the following:
<div class="container-fluid">
<div class="row" id="topheader">
<div class="col-md-3">
<h3 id="logo"><span id="d1">D</span> <span id="two">2</span> <span id="d2">D</span></h3>
</div>
<div class="col-md-9">
<form id="fullform">
<div id="formdiv" class="row">
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div style="" class="col-md-3 login">
<label for="email"></label>
<input class="login_input" type="text" name="email" placeholder="Type your email here">
</div>
<div style="" class="col-md-3 login">
<input class="login_input" type="password" name="password" placeholder="Type your password here">
</div>
</div>
</form>
</div>
</div>
</div>
If you dont want to remove header tag. Then wrap your container-fluid div into header tag. This will works as well like:
<header id="topheader">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<h3 id="logo"><span id="d1">D</span> <span id="two">2</span> <span id="d2">D</span></h3>
</div>
<div class="col-md-9">
<form id="fullform">
<div id="formdiv" class="row">
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div style="" class="col-md-3 login">
<label for="email"></label>
<input class="login_input" type="text" name="email" placeholder="Type your email here">
</div>
<div style="" class="col-md-3 login">
<input class="login_input" type="password" name="password" placeholder="Type your password here">
</div>
</div>
</form>
</div>
</div>
</div>
</header>
Do you asking for this 15px padding that is property of container-fluid class
In that case just over ride the container-fluid class and put padding-left:0 and padding-right:0;
like this,
.container-fluid{
padding-left:0;
padding-right:0;
}
put it in the other file don't change the bootstrap's css file
I'm trying to design a form, with a button inside a text-box. I want that button to be inside the text-box. This is how I tried:
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
my css:
.buttonwrapper {
display:inline-block;
}
input,
button {
background-color:transparent;
border:0;
}
But, the problem is, the Go button is placed below the text-box. What should I do to place it inside the text-box?
I want that "Go" button to be inside the text-box.
Please try this. Remove the outline for the input in active and focus state, and add a border for the input container.
Edit: Im adding the flex-box implementation as well.
Display inline-block implementation
.input-container{
width: 250px;
border: 1px solid #a9a9a9;
display: inline-block;
}
.input-container input:focus, .input-container input:active {
outline: none;
}
.input-container input {
width: 80%;
border: none;
}
.input-container button {
float: right;
}
<div class="input-container">
<input type="text" class="input-field"/>
<button class="input-button">Ok</button>
</div>
Display flex implementation
.input-container {
display: flex;
width: 250px;
border: 1px solid #a9a9a9;
justify-content: space-between;
}
.input-container input:focus, .input-container input:active {
outline: none;
}
.input-container input {
border: none;
}
<div class="input-container">
<input type="text" class="input-field"/>
<button class="input-button">Ok</button>
</div>
.buttonwrapper {
display: inline-block;
}
input{
background-color: transparent;
border: 2px solid black;
}
button {
margin-left: -50%;
border: none;
background-color: transparent;
}
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
You need give position: absolute; to the button & position it inside using top. Add these styles to your button
button {
position: absolute;
top: 6px;
}
Codepen
.buttonwrapper {
display:inline-block;
}
input,
button {
background-color:transparent;
border:0;
}
button {
position: absolute;
top: 6px;
}
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
You can use position:absolute feature here,
HTML
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<div class="button-container">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
CSS
.button-container button { line-height: 28px; position: absolute; right: 0; top: 0;}
.button-container {position:relative;}
.button-container input {padding-right:40px;}
What you need to do is put both the input field and the button in one container, you set that container to be positioned relatively and you set the button to be positioned absolutely. It's important that the container is positioned relatively, so to make sure the button stays within the input field.
Like so:
.buttonwrapper {
display:inline-block;
position: relative;
}
input,
button {
background-color:transparent;
border:0;
}
button {
position: absolute;
/* Adjust these two to your liking */
top: 6px;
right: 3px;
}
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4">
<div class="buttonwrapper">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
for Simple purpose use this method,
Set fixed width for both text box and button.. for eg: text width is 200px, button will be 40px and add margin-left:-40px(based on your need) so it will be fixed between 160-200px of input text box..
.buttonwrapper {
display:inline-block;
}
input,
button {
background-color:transparent;
border:1 solid black;
}
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<input type="text" style="width:200px" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button style="width:40px;margin-left: -43px">GO</button>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>
Twitter Bootstrap does something like this very easily. They call it the Input Group.
If you are looking to do the same without the whole Bootstrap'ness, try this fiddle.
Here's the markup
<span>
<input type="text" value="Some text">
<button onclick="alert('Hello!');">Click</button>
</span>
and the associated CSS
span {
border: 1px solid red;
padding: 2px;
font-size: 0px;
display: inline-block;
background: white;
}
input,
button {
display: inline-block;
margin: 0px;
font-size: 12px;
background: white;
border-style: none;
}
All the above answers are correct. But, there is a very simple way to achieve it. That is as follows:
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Add</button>
</span>
</div>
</div>
</div>
</div>
This does the trick. No need to write extra css properties. Thank you all for your answers.
.buttonwrapper {
display: inline-block;
}
input{
background-color: transparent;
border: 2px solid black;
}
button {
margin-left: 200px;
border: none;
background-color: transparent;
}
<div class="row">
<div class="col-sm-6">
<div class="form-group required">
<label for="PickList_Options" class="col-sm-4 control-label">Options</label>
<div class="col-sm-4 buttonwrapper">
<input type="text" class="form-control" id="PickList_Options" name="PickList_Options" value='' />
<button>GO</button>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="result" id="mydiv"></div>
</div>
</div>