Responsive Div Height Bootstrap 4 - html

I am trying to make replica of one wordpress page using bootstrap. Original Page is looking like this
However my page is looking like this
I want remove unnecessary white space below form. My code is like below
<div class="container-login100">
<div class="wrap-login100 ">
<span class="login100-form-title p-b-32">
Make Fast Cash Anywhere
</span>
<span class="login100-form-sub-title p-b-32">
Begin Your Fast Start Steps Below...
</span>
<div class="test-progress" style="background-color:#ebebeb;">
<div class="progress-bar progress-bar-success progress-bar-animated" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:4%; background-color:#00c479;"><span id="progress"> 0% </span></div>
</div>
<form class="login100-form">
<div id="quiz">
<div class="question">
<h3>
<span id="question"> Are you looking for a way to make money online?</span>
</h3>
</div>
<ul class="text-center" style="list-style-position: inside">
<li>
<input type="radio" id="a-option" name="selector" value="1">
<label for="a-option" class="element-animation">Yes</label>
<div class="check"></div>
</li>
<li>
<input type="radio" id="b-option" name="selector" value="3">
<label for="b-option" class="element-animation">No</label>
<div class="check"><div class="inside"></div></div>
</li>
<li id="lic" style="display:none">
<input type="radio" id="c-option" name="selector" value="3">
<label for="c-option" class="element-animation">C</label>
<div class="check"><div class="inside"></div></div>
</li>
<li id="lid" style="display:none">
<input type="radio" id="d-option" name="selector" value="3">
<label for="d-option" class="element-animation">D</label>
<div class="check"><div class="inside"></div></div>
</li>
</ul>
</div>
</form>
</div>
</div>
and css code is like below
.limiter {
width: 100%;
margin: 0 auto;
background-color: #000000;
}
.container-login100 {
width: 100%;
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: top;
padding: 10px;
background-image: url("../images/dollar-2.jpg");
background-color: #ebebeb;
}
.wrap-login100 {
width: 570px;
background: #fff;
border-radius: 10px;
position: relative;
}
I am using bootstrap 4 and I am looking for responsive height for wrap-login100 instead of full height. Let me know if here anyone can help me for same. Thanks!
Edit: if I remove min-height: 100vh; from container-login100, its getting responsive but my background getting cut and getting visible in half screen only.

Add height:max-content to .wrap-login100 in css
.limiter {
width: 100%;
margin: 0 auto;
background-color: #000000;
}
.container-login100 {
width: 100%;
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: top;
padding: 10px;
background-image: url("../images/dollar-2.jpg");
background-color: #ebebeb;
}
.wrap-login100 {
width: 570px;
background: #fff;
border-radius: 10px;
position: relative;
height: max-content;
}
<div class="container-login100">
<div class="wrap-login100 ">
<span class="login100-form-title p-b-32">
Make Fast Cash Anywhere
</span>
<span class="login100-form-sub-title p-b-32">
Begin Your Fast Start Steps Below...
</span>
<div class="test-progress" style="background-color:#ebebeb;">
<div class="progress-bar progress-bar-success progress-bar-animated" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:4%; background-color:#00c479;"><span id="progress"> 0% </span></div>
</div>
<form class="login100-form">
<div id="quiz">
<div class="question">
<h3>
<span id="question"> Are you looking for a way to make money online?</span>
</h3>
</div>
<ul class="text-center" style="list-style-position: inside">
<li>
<input type="radio" id="a-option" name="selector" value="1">
<label for="a-option" class="element-animation">Yes</label>
<div class="check"></div>
</li>
<li>
<input type="radio" id="b-option" name="selector" value="3">
<label for="b-option" class="element-animation">No</label>
<div class="check">
<div class="inside"></div>
</div>
</li>
<li id="lic" style="display:none">
<input type="radio" id="c-option" name="selector" value="3">
<label for="c-option" class="element-animation">C</label>
<div class="check">
<div class="inside"></div>
</div>
</li>
<li id="lid" style="display:none">
<input type="radio" id="d-option" name="selector" value="3">
<label for="d-option" class="element-animation">D</label>
<div class="check">
<div class="inside"></div>
</div>
</li>
</ul>
</div>
</form>
</div>
</div>

Related

Scrollable div/panel in flexbox layout

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>

How can I widen my input element within a flex container?

I'm trying to make a login page (username and password). So far, I have managed to construct it, but one problem I'm now facing is that the username input and password input, as well as the login button are only at half the width of the table I put them in. How can I make them go to the maximum width of the table, and still scale according to the size of the client's screen?
Here are my codes:
.login_table {
display: flex;
padding: 0.5em;
border: 2px solid #46a7e0;
width: 50%;
}
.login_row {
display: flex;
}
.login_cell {
display: flex;
padding: 0.5em;
}
<form action="/Login/Login" method="POST">
<div style="text-align:center">
<div class="login_table">
<div class="login_row">
<div class="login_cell">
Username:
</div>
<div class="login_cell">
<input class="form-control" name="username" />
</div>
</div>
<div class="login_row">
<div class="login_cell">
Password:
</div>
<div class="login_cell">
<input class="form-control" name="password" />
</div>
</div>
<div class="login_row">
<div class="login_cell"></div>
<div class="login_cell" style="text-align: right">
<input type="submit" value="Login" class="btn btn-primary" />
</div>
</div>
</div>
</div>
</form>
Use flex: 1;, or flex-grow: 1;. You can run the code below to see the result.
.login_table {
display: flex;
flex-direction: column;
padding: 0.5em;
border: 2px solid #46a7e0;
}
.login_row {
display: flex;
padding: 0.5em;
}
.login_row .login_cell:first-of-type {
width: 90px;
text-align: left;
padding: 0 .5em;
}
.login_row .login_cell:last-of-type {
flex: 1;
display: flex;
}
input {
width: 100%;
}
<form action="/Login/Login" method="POST">
<div style="text-align:center">
<div class="login_table">
<div class="login_row">
<div class="login_cell"> Username:</div>
<div class="login_cell">
<input class="form-control" name="username" />
</div>
</div>
<div class="login_row">
<div class="login_cell">Password:</div>
<div class="login_cell">
<input class="form-control" name="password" />
</div>
</div>
<div class="login_row">
<div class="login_cell"></div>
<div class="login_cell">
<input type="submit" value="Login" class="btn btn-primary" />
</div>
</div>
</div>
</div>
</form>
1) Remove the width: 50% in .login_table
.login_table {
width: 50%; // Remove this to get full width
}
2) You can either use media queries for small screens or flex-wrap: wrap to wrap element when they don't fit in the container.
.login_table {
display: flex;
flex-wrap: wrap;
padding: 0.5em;
border: 2px solid #46a7e0;
}
.login_row {
display: flex;
}
.login_cell {
display: flex;
padding: 0.5em;
}
<form action="/Login/Login" method="POST">
<div style="text-align:center">
<div class="login_table">
<div class="login_row">
<div class="login_cell">
Username:
</div>
<div class="login_cell">
<input class="form-control" name="username" />
</div>
</div>
<div class="login_row">
<div class="login_cell">
Password:
</div>
<div class="login_cell">
<input class="form-control" name="password" />
</div>
</div>
<div class="login_row">
<div class="login_cell"></div>
<div class="login_cell" style="text-align: right">
<input type="submit" value="Login" class="btn btn-primary" />
</div>
</div>
</div>
</div>
</form>
When you use flex, by default all the child element will forcefully take horizontal position. As you want your username, password and login button full width and show them in row. So you must you flex-direction: column;
Have a look at the this code and run it.
.login_table {
--gap: 1em;
display: flex;
padding: 0.5em;
border: 2px solid #46a7e0;
flex-direction: column;
box-sizing: border-box;
row-gap: var(--gap);
}
.login_table :is(input, button){
display: block;
width: 100%;
}
.login_table :is(input, button) {
display: block;
width: 100%;
box-sizing: border-box;
}
.login_row {
display: grid;
column-gap: var(--gap);
align-items: center;
grid-template-columns: 75px 1fr;
}
<form action="/Login/Login" method="POST">
<div style="text-align:center">
<div class="login_table">
<div class="login_row">
<div class="login_cell"> Username:</div>
<div class="login_cell">
<input class="form-control" name="username" />
</div>
</div>
<div class="login_row">
<div class="login_cell">Password:</div>
<div class="login_cell">
<input class="form-control" name="password" />
</div>
</div>
<div class="login_row">
<div class="login_cell"></div>
<div class="login_cell">
<input type="submit" value="Login" class="btn btn-primary" />
</div>
</div>
</div>
</div>
</form>

HTML Radio buttons like Bar Graphs and Corresponding Labels right bellow them like X-axis names

I want to achieve HTML bars using radio buttons and also make their labels appear under x-axis.
I also want to maintain the lock/unlock icons as shown in the code below.
I have tried to look at these answers
Creating interactive bar chart with only HTML and CSS and How to style a radio button to look like a regular Learn More Button But couldn't get the whole solution even after I tried.
This is the code I have written and the expected results. When checked, the button color should change to green. I am using bootstrap.
Someone assist me, please.
.team-bar {
/*list-style-type:none;
margin:25px 0 0 0;
padding:0; */
}
.team-bar .teama {
float: left;
margin: 0;
width: 150px;
height: 350px;
position:relative;
}
.team-bar .lock-unlock-img, .team-bar input {
display: block;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.team-bar input[type="radio"] {
opacity:0.011;
z-index:100;
}
/*.team-bar .checked{
background:yellow;
}*/
.team-bar .lock-unlock-img {
padding:5px;
border:1px solid #CCC;
cursor:pointer;
z-index:90;
}
.team-bar .lock-unlock-img:hover {
background:#DDD;
}
<!-- Google Font: Source Sans Pro -->
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
<!-- Font Awesome -->
<link rel="stylesheet" href="//adminlte.io/themes/v3/plugins/fontawesome-free/css/all.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="//adminlte.io/themes/v3/dist/css/adminlte.min.css">
<div class="container">
<div class="row">
<div class="team-bar">
<div class="col-md-1 center teama" style="display: inline !important;">
<div class="inner text-center">
<p class="radios" style="display: inline !important;">
<input id="radio" type="radio" class="radio-inline" value="" name="assetvalue">
<div class="lock-unlock-img">
<b class="float-left" alt="left"> <i class="fa fa-lock text-danger"></i></b>
<b class="float-right" alt="left"> <i class="fa fa-unlock text-success"></i></b>
</div>
<label class="radio bg-primary1 text-center" for="radio" style="display: inline-block !important;"> Team 1</label>
</p>
</div>
</div>
<div class="col-md-1 center teama" style="display: inline !important;">
<div class="inner text-center">
<p class="radios" style="display: inline !important;">
<input id="radio" type="radio" class="radio-inline" value="" name="assetvalue">
<div class="lock-unlock-img">
<b class="float-left" alt="left"> <i class="fa fa-lock text-danger"></i></b>
<b class="float-right" alt="left"> <i class="fa fa-unlock text-success"></i></b>
</div>
<label class="radio bg-primary1 text-center" for="radio" style="display: inline-block !important;"> Team 2</label>
</p>
</div>
</div>
<div class="col-md-1 center teama btn-success" style="display: inline !important;">
<div class="inner text-center">
<p class="radios" style="display: inline !important;">
<input id="radio" type="radio" class="radio-inline" value="" name="assetvalue">
<div class="lock-unlock-img">
<b class="float-left" alt="left"> <i class="fa fa-lock text-danger"></i></b>
<b class="float-right" alt="left"> <i class="fa fa-unlock text-success"></i></b>
</div>
<label class="radio bg-primary1 text-center" for="radio" style="display: inline-block !important;"> Team 3</label>
</p>
</div>
</div>
<div class="col-md-1 center teama" style="display: inline !important;">
<div class="inner text-center">
<p class="radios" style="display: inline !important;">
<input id="radio" type="radio" class="radio-inline" value="" name="assetvalue">
<div class="lock-unlock-img">
<b class="float-left" alt="left"> <i class="fa fa-lock text-danger"></i></b>
<b class="float-right" alt="left"> <i class="fa fa-unlock text-success"></i></b>
</div>
<label class="radio bg-primary1 text-center" for="radio" style="display: inline-block !important;"> Team 4</label>
</p>
</div>
</div>
<div class="col-md-1 center teama" style="display: inline !important;">
<div class="inner text-center">
<p class="radios" style="display: inline !important;">
<input id="radio" type="radio" class="radio-inline" value="" name="assetvalue">
<div class="lock-unlock-img">
<b class="float-left" alt="left"> <i class="fa fa-lock text-danger"></i></b>
<b class="float-right" alt="left"> <i class="fa fa-unlock text-success"></i></b>
</div>
<label class="radio bg-primary1 text-center" for="radio" style="display: inline-block !important;"> Team 5</label>
</p>
</div>
</div>
</div>
</div>
</div>
I created a style for each radio button to achieve what you want.
Each Radio Button
container: the label is used as the container in order to make the entire area clickable
element1: the input itself
element2: the icons line of each bar
element3: the bar colored rectangle
element4: the bar's label
I wasn't sure about the logic of the colors so I tried to keep it the same as in your image.
<label for="team1" class="bar">
<input type="radio"
id="team1"
name="team"
value="team1"
checked
>
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 1</div>
</label>
Styling
Based on if the input is checked or not, I'm changing the bar's height.
In my solution, I use the same height for all the bars, but this can be easily changed. just like how I defined colors for each bar, you can do the same for the bar's height based on the selected state.
The important part is using the ~ selector which is the Subsequent-sibling combinator
The general sibling combinator is made of the "tilde" (U+007E, ~) character that separates two sequences of simple selectors. The elements represented by the two sequences share the same parent in the document tree and the element represented by the first sequence precedes (not necessarily immediately) the element represented by the second one.
input:checked ~ .chart-value {
height: 100%;
}
html,
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
}
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background: #f5f5dc;
}
.kb-checkbox-as-chart {
--chart-height: 250px;
--chart-color1: hsl(141, 53%, 53%);
--chart-color2: hsl(141, 53%, 53%);
--chart-color3: hsl(141, 53%, 53%);
--chart-color4: hsl(141, 53%, 53%);
--chart-color5: hsl(141, 53%, 53%);
--lock-color: hsl(348, 100%, 61%);
--unlock-color: hsl(141, 53%, 53%);
--unlock-selected-color: hsl(48, 100%, 67%);
display: flex;
height: var(--chart-height);
padding-bottom: 1em;
border: 1px solid grey;
}
.kb-checkbox-as-chart .bar {
margin: 0 0.3em;
padding: 0.5em 0.5em 0;
height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
position: relative;
cursor: pointer;
}
.kb-checkbox-as-chart .bar .legend {
font-weight: bold;
}
.kb-checkbox-as-chart .bar .icons-bar {
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
position: absolute;
padding: 0.8em;
}
.kb-checkbox-as-chart .bar .icons-bar .fa-lock {
color: var(--lock-color);
}
.kb-checkbox-as-chart .bar .icons-bar .fa-unlock {
color: var(--unlock-color);
}
.kb-checkbox-as-chart .bar .chart-value {
height: 20px;
width: 95%;
background: var(--chart-color1);
transition: height 250ms;
}
.kb-checkbox-as-chart input:checked~.icons-bar .fa-unlock {
color: var(--unlock-selected-color);
}
.kb-checkbox-as-chart input:checked~.chart-value {
height: 100%;
}
.kb-checkbox-as-chart input#team2~.chart-value {
background-color: var(--chart-color2);
}
.kb-checkbox-as-chart input#team3~.chart-value {
background-color: var(--chart-color3);
}
.kb-checkbox-as-chart input#team4~.chart-value {
background-color: var(--chart-color4);
}
.kb-checkbox-as-chart input#team5~.chart-value {
background-color: var(--chart-color5);
}
.kb-checkbox-as-chart input[type=radio] {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
<link href="https://pro.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet" />
<div class="kb-checkbox-as-chart">
<label for="team1" class="bar">
<input type="radio" id="team1" name="team" value="team1"
checked>
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 1</div>
</label>
<label for="team2" class="bar">
<input type="radio" id="team2" name="team" value="team2">
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 2</div>
</label>
<label for="team3" class="bar">
<input type="radio" id="team3" name="team" value="team3">
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 3</div>
</label>
<label for="team4" class="bar">
<input type="radio" id="team4" name="team" value="team4">
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 4</div>
</label>
<label for="team5" class="bar">
<input type="radio" id="team5" name="team" value="team5">
<div class="icons-bar">
<i class="fa fa-lock text-danger"></i>
<i class="fa fa-unlock text-success"></i>
</div>
<div class="chart-value"></div>
<div class="legend">Team 5</div>
</label>
</div>

Centering multiple divs (not grouped) within div

I'm simply trying to center a block of divs (within a div) but I cannot seem to center it. I've tried solutions from here, but none of them work for me?
Structure:
<div id="content" class="email-prefs">
<div class="item"><!-- content -- ></div>
<div class="item"><!-- content -- ></div>
<div class="item"><!-- content -- ></div>
....
</div>
Any help would be appreciated! P.s. I'm trying to center the .item div
#content {
text-align: center;
text-align: center;
width: 100%;
height: auto;
border: 1px solid red;
}
.email-prefs .item {
width: 27.0%;
float: left;
margin: 0;
line-height: 25px;
color: #36383d;
font-family: Helvetica, sans-serif;
padding: 10px;
display: inline-block;
margin: auto;
border: 1px solid blue;
}
.subscribe-options {
clear: both;
}
<div id="content" class="email-prefs">
<p class="header">Uncheck the types of emails you do not want to receive:</p>
<input type="hidden" name="subscription_ids" value="">
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_896974" type="checkbox" name="id_896974" checked="checked">
<span>Food for Thought instant blog notification</span>
</span>
</div>
<p>Be the first to read our new liveRES blog posts</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_1044442" type="checkbox" name="id_1044442" checked="checked">
<span>Food for Thought monthly blog roundup</span>
</span>
</div>
<p>Must-read moments from the liveRES blog</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_4811083" type="checkbox" name="id_4811083" checked="checked">
<span>Industry insights and research</span>
</span>
</div>
<p>Keep on top of the latest hospitality facts and figures</p>
</div>
</div>
<div class="subscribe-options" style="margin-right: 0">
<p class="header">Or check here to never receive any emails:</p>
<p>
<label for="globalunsub">
<input name="globalunsub" id="globalunsub" type="checkbox">
<span>
Unsubscribe me from all mailing lists.
</span>
</label>
</p>
</div>
<input type="submit" class="hs-button primary" id="submitbutton" value="Update email preferences">
<div class="clearer"></div>
</div>
You need to wrap .item in a wrapper and set text-align: center to that wrapper
Remove float from .item and set vertical-align: top
#content {
text-align: center;
text-align: center;
width: 100%;
height: auto;
border: 1px solid red;
}
.item-wrapper {
text-align: center;
}
.email-prefs .item {
width: 27.0%;
/* float: left; */
/* margin: 0; */
line-height: 25px;
color: #36383d;
font-family: Helvetica, sans-serif;
padding: 10px;
display: inline-block;
margin: auto;
border: 1px solid blue;
vertical-align: top;
}
.subscribe-options {
clear: both;
}
<div id="content" class="email-prefs">
<p class="header">Uncheck the types of emails you do not want to receive:</p>
<input type="hidden" name="subscription_ids" value="">
<div class="item-wrapper">
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_896974" type="checkbox" name="id_896974" checked="checked">
<span>Food for Thought instant blog notification</span>
</span>
</div>
<p>Be the first to read our new liveRES blog posts</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_1044442" type="checkbox" name="id_1044442" checked="checked">
<span>Food for Thought monthly blog roundup</span>
</span>
</div>
<p>Must-read moments from the liveRES blog</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_4811083" type="checkbox" name="id_4811083" checked="checked">
<span>Industry insights and research</span>
</span>
</div>
<p>Keep on top of the latest hospitality facts and figures</p>
</div>
</div>
</div>
<div class="subscribe-options" style="margin-right: 0">
<p class="header">Or check here to never receive any emails:</p>
<p>
<label for="globalunsub">
<input name="globalunsub" id="globalunsub" type="checkbox">
<span>
Unsubscribe me from all mailing lists.
</span>
</label>
</p>
</div>
<input type="submit" class="hs-button primary" id="submitbutton" value="Update email preferences">
<div class="clearer"></div>
</div>
Create a common div with class flex for all the three items and add the following styling for it
.flex{
display:inline-flex;
justify-content: center
}
and Remove the following css from email-prefs .item class
.email-prefs .item {
/*margin: auto;Remove this line*/
}
#content {
text-align: center;
text-align: center;
width: 100%;
height: auto;
border: 1px solid red;
}
.flex{
display:inline-flex;
justify-content: center
}
.email-prefs .item {
width: 27.0%;
float: left;
margin: 0;
line-height: 25px;
color: #36383d;
font-family: Helvetica, sans-serif;
padding: 10px;
display: inline-block;
/*margin: auto;Remove this line*/
border: 1px solid blue;
}
.subscribe-options {
clear: both;
}
<div id="content" class="email-prefs">
<p class="header">Uncheck the types of emails you do not want to receive:</p>
<input type="hidden" name="subscription_ids" value="">
<div class="flex">
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_896974" type="checkbox" name="id_896974" checked="checked">
<span>Food for Thought instant blog notification</span>
</span>
</div>
<p>Be the first to read our new liveRES blog posts</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_1044442" type="checkbox" name="id_1044442" checked="checked">
<span>Food for Thought monthly blog roundup</span>
</span>
</div>
<p>Must-read moments from the liveRES blog</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_4811083" type="checkbox" name="id_4811083" checked="checked">
<span>Industry insights and research</span>
</span>
</div>
<p>Keep on top of the latest hospitality facts and figures</p>
</div>
</div>
</div>
<div class="subscribe-options" style="margin-right: 0">
<p class="header">Or check here to never receive any emails:</p>
<p>
<label for="globalunsub">
<input name="globalunsub" id="globalunsub" type="checkbox">
<span>
Unsubscribe me from all mailing lists.
</span>
</label>
</p>
</div>
<input type="submit" class="hs-button primary" id="submitbutton" value="Update email preferences">
<div class="clearer"></div>
</div>
You want it like this?
Just removed float:left;
#content {
text-align: center;
text-align: center;
width: 100%;
height: auto;
border: 1px solid red;
}
.email-prefs .item {
width: 27.0%;
margin: 0;
line-height: 25px;
color: #36383d;
font-family: Helvetica, sans-serif;
padding: 10px;
display: inline-block;
margin: auto;
border: 1px solid blue;
}
.subscribe-options {
clear: both;
}
<div id="content" class="email-prefs">
<p class="header">Uncheck the types of emails you do not want to receive:</p>
<input type="hidden" name="subscription_ids" value="">
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_896974" type="checkbox" name="id_896974" checked="checked">
<span>Food for Thought instant blog notification</span>
</span>
</div>
<p>Be the first to read our new liveRES blog posts</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_1044442" type="checkbox" name="id_1044442" checked="checked">
<span>Food for Thought monthly blog roundup</span>
</span>
</div>
<p>Must-read moments from the liveRES blog</p>
</div>
</div>
<div class="item">
<div class="item-inner selected">
<div class="checkbox-row">
<span class="fakelabel">
<input id="id_4811083" type="checkbox" name="id_4811083" checked="checked">
<span>Industry insights and research</span>
</span>
</div>
<p>Keep on top of the latest hospitality facts and figures</p>
</div>
</div>
<div class="subscribe-options" style="margin-right: 0">
<p class="header">Or check here to never receive any emails:</p>
<p>
<label for="globalunsub">
<input name="globalunsub" id="globalunsub" type="checkbox">
<span>
Unsubscribe me from all mailing lists.
</span>
</label>
</p>
</div>
<input type="submit" class="hs-button primary" id="submitbutton" value="Update email preferences">
<div class="clearer"></div>
</div>

Same width with Flexbox

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>