I have a JavaScript script that basically hides a box upon clicking the top two boxes. Upon clicking one of the boxes on top, one of the boxes on the bottom hides. How do I make the two boxes on the bottom stay centered?
Here is the landing page:
I want the divs on the bottom centered, once a box is hidden. I want the SharePoint and Teams boxes centered after the other box is hidden.
Center the bottom two div's after change ^
Code:
.margin-bottom-20 {
margin-bottom: 20px;
}
.collabProjects:hover, .collabFiles:hover, .collabSocially:hover {
box-shadow: 0 0 15px rgba(33,3,3,.2);
}
.decisionTreeBox {
background-color: #4B92DB;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
transition: box-shadow .3s;
}
#decisionTreeOneDrive {
background-color: #094AB2;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeSharePoint {
background-color: #008CE7;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeTeams {
background-color: #4A1EBD;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#innerBoxHeadings {
color: white!important;
text-align: center;
padding-top: 5px;
}
#columnMiddleBorderLeft, #pageTitle {
display:none!important;
}
<div class="outer-container">
<div class="row">
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareCollab" class="decisionTreeBox" style="font-size: x-large; float: right;">
Share and Collaborate</div>
</div>
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareExternally" class="decisionTreeBox" style="font-size: x-large;">
Share Externally</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />OneDrive</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />SharePoint</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Teams</h3>
</div>
</div>
</a>
</div>
</div>
</div>
<script>
function projectCollab() {
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToCange.length; i++) {
var d = divsToCange[i];
if (d.getAttribute('data-decision').includes(attr)) { /* Had: == attr) { */
d.parentNode.style.display = 'block';
} else {
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
</script>
There's an old technique of centering the content of the parent, then making the children display: inline-block;. You will have to account for the visibility of the white-space " " character — but that is pretty well documented (e.g. Remove Whitespace Between Inline-Block Elements). You'll have to play with margin to restore your spacing, AND remember to change the JS to reflect inline-block instead of block when restoring the elements.
In the interest of selector sanity, I added an example class to the containing row element in the code demo.
HTML
<div class="row centered-buttons">
CSS
.centered-buttons {
text-align: center;
}
.centered-buttons a {
display: inline-block;
vertical-align: middle;
}
.margin-bottom-20 {
margin-bottom: 20px;
}
.collabProjects:hover,
.collabFiles:hover,
.collabSocially:hover {
box-shadow: 0 0 15px rgba(33, 3, 3, .2);
}
.decisionTreeBox {
background-color: #4B92DB;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
transition: box-shadow .3s;
}
#decisionTreeOneDrive {
background-color: #094AB2;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeSharePoint {
background-color: #008CE7;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#decisionTreeTeams {
background-color: #4A1EBD;
color: white;
width: 300px;
height: 140px;
display: flex;
justify-content: center;
align-items: center;
}
#innerBoxHeadings {
color: white!important;
text-align: center;
padding-top: 5px;
}
#columnMiddleBorderLeft,
#pageTitle {
display: none!important;
}
.centered-buttons {
text-align: center;
}
.centered-buttons a {
display: inline-block;
vertical-align: middle;
}
<div class="outer-container">
<div class="row">
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareCollab" class="decisionTreeBox" style="font-size: x-large; float: right;">
Share and Collaborate</div>
</div>
<div class="col-md-6" style="text-align: center;">
<div data-collaborate="shareExternally" class="decisionTreeBox" style="font-size: x-large;">
Share Externally</div>
</div>
</div>
<hr />
<div class="container" style="padding: 0px;">
<div class="row centered-buttons">
<a href="/TrainingResourceCenter/O365Training/Pages/OneDrive.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/onedrive-logo.png" style="width: 65px; height: 65px; padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />OneDrive</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/SharePointOnline.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/SharePointDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />SharePoint</h3>
</div>
</div>
</a>
<a href="/TrainingResourceCenter/O365Training/Pages/Teams.aspx">
<div class="col-md-4 margin-bottom-20" style="text-align: center;">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings"><img src="/TrainingResourceCenter/O365Training/PublishingImages/TeamsDecisionTree.png" style="padding-bottom: 5px; padding-right: 10px; vertical-align: middle;" />Teams</h3>
</div>
</div>
</a>
</div>
</div>
</div>
<script>
function projectCollab() {
var divsToCange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToCange.length; i++) {
var d = divsToCange[i];
if (d.getAttribute('data-decision').includes(attr)) { /* Had: == attr) { */
d.parentNode.style.display = 'block';
} else {
d.parentNode.style.display = 'none';
}
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
</script>
In cases like this, I usually conditionally set the class of the content that changes depending on how many items are present. For example, imagine you're checking an array called items that is either 2 or 3 items long. Here is some pseudocode that shows you what I'm thinking.
let itemsClass;
if (items.length === 2) {
itemsClass = 'col-md-6';
} else {
itemsClass = 'col-md-4';
}
myElement.setClass(itemsClass);
You could set a click handler that would check after you click a button or whatever. In react, that could be part of your component render() method.
I don't know what you're using for JS so I won't try to write your code for you. But the gist of it is, decide the class name on the fly with JS and apply it to your elements.
edit: Sorry, I didn't read your entire code snippet. This is something you could add to the handler you already have. You'd just have to grab the elements and alter the classes at that time.
Add the following CSS to the row class:
<div class="container" style="padding: 0px;">
<div class="row" style="justify-content: center">
Since bootstrap uses flexbox system, this should work for you.
What you are asking for is built into BS. But you've muddied the framework by adding html where it ought not be. specifically wrapping BS cols with an anchor tag which breaks the BS grid system, specifically the rule that states only cols can be children of rows.
I've made your html substantially shorter for simplicity and altered your js somewhat to showcase the hiding part. I hope this a decent example that you can expand upon.
FIXES:
I've moved the anchor tab inside the col. This was breaking the alignment of the BS Grid And is also incorrect markup per the BS grid system.
I altered your JS to hide the col, not the anchor. This allows the BS flex grid to properly do it's alignment
In the javascript, consider adding a attribute to your markup such that you don't have to navigate the right number of parent levels. As it stands, if you add more layers to the col html, your JS will break.
function projectCollab() {
var divsToChange = document.querySelectorAll('[data-decision]'),
attr = this.getAttribute('data-collaborate');
for (var i = 0; i < divsToChange.length; i++) {
var d = divsToChange[i];
d.parentNode.parentNode.hidden = ! d.getAttribute('data-decision').includes(attr);
}
return false;
}
var divButtons = document.querySelectorAll('[data-collaborate]');
for (var i = 0; i < divButtons.length; i++) {
divButtons[i].addEventListener('click', projectCollab);
}
.collabProjects:hover,
.collabFiles:hover,
.collabSocially:hover {
box-shadow: 0 0 15px rgba(33, 3, 3, .2);
}
div[data-decision],
div[data-collaborate]{
color: white;
width: 200px;
height: 100px;
}
.decisionTreeBox {
background-color: #4B92DB;
}
#decisionTreeOneDrive {
background-color: #094AB2;
}
#decisionTreeSharePoint {
background-color: #008CE7;
}
#decisionTreeTeams {
background-color: #4A1EBD;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<div class="outer-container">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-4">
<div data-collaborate="shareCollab" class="decisionTreeBox">
Share and Collaborate</div>
</div>
<div class="col-4">
<div data-collaborate="shareExternally" class="decisionTreeBox">
Share Externally</div>
</div>
</div>
<hr />
<div class="row justify-content-center">
<div class="col-4">
<a href="#">
<div data-decision="shareExternally" id="decisionTreeOneDrive">
<h3 id="innerBoxHeadings">OneDrive</h3>
</div>
</a>
</div>
<div class="col-4">
<a href="#">
<div data-decision="shareCollab shareExternally" id="decisionTreeSharePoint">
<h3 id="innerBoxHeadings">SharePoint</h3>
</div>
</a>
</div>
<div class="col-4">
<a href="#">
<div data-decision="shareCollab" id="decisionTreeTeams">
<h3 id="innerBoxHeadings">Teams</h3>
</div>
</a>
</div>
</div>
</div>
</div>
Related
I have an issue where my text isn't moving onto a new line when it reaches the edge of its parent div, but stretches the parent div downwards to make space width-wise. Two pictures are shown below illustrating the issue.
The HTML and appropriate CSS will be shown below.
#import url('https://fonts.googleapis.com/css2?family=Raleway:wght#300&display=swap');
* {
font-family: Raleway;
}
.menu {
display: block;
overflow: hidden;
}
.section-one {
display: inline-block;
}
.section-two {
padding-left: 2em;
}
.block {
padding: 0.5em;
}
.button {
cursor: pointer;
}
.float-left {
float:left;
}
.float-right {
padding-left: 2em;
float:right;
}
.img-menu {
border-radius: 50%;
margin: auto;
display: inline-block;
}
.img-info {
display: inline-block;
}
.h {
padding-left:0.5em;
color: #777;
}
.h-primary {
margin-top: 0;
margin-bottom: 0.25em;
color: black;
}
.h-secondary {
margin-top: 0.25em;
}
.h-tertiary {
margin-top: 0.25em;
margin-bottom: 0;
overflow: auto;
}
<div className='menu'>
<div className='float-left'>
{details.reduce(
function(accumulator, currentValue, currentIndex, array) {
if (currentIndex % 2 === 0) {
var temp = array.slice(currentIndex, currentIndex + 2)
temp[0]['pair'] = true
temp[1]['pair'] = false
accumulator.push(temp)
}
return accumulator;
}, []).map((pair) =>
<div className='block'>
{pair.map((detail) =>
<div onclick="location.href='#';" className={['button', detail.pair ? 'float-left' : 'float-right'].join(' ')}>
<img src={detail.imgsrc} className='img-menu' />
<div className='img-info'>
<div>
<strong>
<h5 className='h h-primary'>
{detail.buttontitle}
</h5>
</strong>
</div>
<div>
<h5 className='h h-secondary'>
{detail.buttonsubtitle}
</h5>
</div>
</div>
</div>
)}
</div>
)}
</div>
<!-- Section with the issue! -->
<div className='section-two float-left'>
<div className='block'>
<div>
<strong>
<h5 className='h h-primary'>
Placeholder
</h5>
</strong>
</div>
<div>
<h5 className='h h-tertiary '>
Placeholder Placeholder Placeholder Placeholder Placeholder Placeholder
</h5>
</div>
</div>
<div className='block'>
<h5 className='h h-primary'>
PlaceholderButton
</h5>
</div>
</div>
</div>
Any help will be greatly appreciated!
I was trying to design table below. I tried to use a HTML table but I couldn't get the box shadow to apply properly as I had to round the corners of the first and last td cells and not the tr (as it doesn't support a border radius) but then applying a box shadow to the row didn't go round the curved edges, rather it stayed square.
I also tried display:grid & flex, however, I could find a way to get the box-shadow/border-radius and centre align the text within columns, it was a trade off.
So any advice would be much appreciated.
This is what I was trying to convert to HTML and CSS.
This is the react code is use to render the HTML for the table:
<div className="policy-container">
<div className="policy-table">
<div className="headings">
<span className="heading">Name</span>
<span className="heading">Last Updated</span>
<span className="heading">Actions</span>
</div>
{data.map((row, ri) => (
<div key={ri} className="policy">
<span>{row.name}</span>
<span>{row.lastUpdated.format("Do MMM YYYY")}</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
))}
</div>
</div>
I would do something like this, using flex:
body {
background-color: #eefbfb;
font-family: sans-serif;
font-size: 16px;
}
.policy-table {
color: grey;
text-align: center;
}
.headings, .policy {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
margin-bottom: 1em;
padding: 1em;
}
.heading {
flex-basis: 33.333%;
font-weight: bold;
}
.policy {
border-radius: 2em;
background-color: white;
margin-bottom: 20px;
-moz-box-shadow: 0 0 3px grey;
-webkit-box-shadow: 0 0 3px grey;
box-shadow: 0 0 5px grey;
}
span {
flex-basis: 33.333%;
}
a {
text-decoration: none;
color: #4c4c4c;
}
<div class="policy-container">
<div class="policy-table">
<div class="headings">
<span class="heading">Name</span>
<span class="heading">Last Updated</span>
<span class="heading">Actions</span>
</div>
<div class="policy">
<span>Name</span>
<span>DD MM YY</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
<div class="policy">
<span>Name</span>
<span>DD MM YY</span>
<span>
<a href={row.link}>view</a>
</span>
</div>
</div>
</div>
so I'm a beginner and I started this project by first writing CSS in styles.scss and then transforming the code inside of it using scss tools. I made an each loop to loop through a set of colors in my color map, placed in a mixin and put that mixin under [class^=btn].
I don't know why this doesn't work?
Here is my SCSS:
//colors
$base-grey: #808080;
$base-white: #ffffff;
$base-green: #71eeb8;
$base-blue: #2dcae6; //base-success: #33c052;
$base-red: #ff6666; //red
$base-orange: #ff751a; //warning
$base-purple: #8a54f7; //info
// grid base class
.grid {
// .grid__row
&__row {
padding: 1em 10px;
display: flex;
flex-direction: column;
// NOTE: replace with media query mixin if aiming for exceeds
#media (min-width: 768px) {
flex-direction: row;
}
}
// .grid__col
&__col {
// create grid columns dynamically
// loop through each column size
#for $i from 1 through 12 {
// concatenate CSS selector, ie when $i = 1,
// selector would be .grid__col--1
&--#{$i} {
// base styles applied to all grid columns
// NOTE: could be converted to a placeholder, along with margin
// from the media query
margin-top: 10px;
flex-basis: 100%;
border: 1px red solid;
// NOTE: replace with media query mixin if aiming for exceeds
#media (min-width: 768px) {
// base stlyes applied to all grid columns
margin-top: 0;
// make column width a percentage of the column number / total columns
flex-basis: #{$i / 12 * 100 + "%"} ;
}
}
}
}
}
// targets all elements with classes that begin with grid__col
[class^=grid__col] {
// grid__col + grid__col, targets two sibling columns
& + & {
// NOTE: replace with media query mixin if aiming for exceeds
#media (min-width: 768px) {
// add grid gutter
margin-left: 10px;
}
}
}
.grid {
&__row {
display: flex;
}
}
//BASE
.container {
text-align: left;
font-family: 'Arial Narrow', Arial,sans-serif;
color: $base-grey;
padding: 5px;
font-weight: 500;
}
p {
text-align: left;
line-height: 1.3;
}
a {
text-decoration: none;
}
//NAVIGATION
.nav {
list-style-type: none;
padding: 0;
text-align: center;
}
.nav__item a {
display: block;
color: inherit;
margin: 8px 0;
padding: 8px;
}
.nav__item a:hover {
color: $base-white;
background-color: $base-green;
}
//TYPOGRAPHY
//link
.link {
color: $base-blue;
font-weight: bold;
}
//blockquote
.blockquote {
border-left: $base-green 8px solid;
padding-left: 10px;
font-style: oblique;
font-size: 1.2em;
}
// headlines
#mixin h2-font-weight {
font-weight: 100;
}
.headline--primary {
color: $base-green;
margin-left: 10px;
}
.headline--secondary {
text-align: left;
#include h2-font-weight;
}
//FORM
.form {
display: flex;
flex-direction: column;
&__input {
border: none;
border-bottom: 2px solid $base-green;
margin-bottom: 15px;
}
&__label--hidden {
display: none;
}
& .headline--secondary {
#include h2-font-weight;
}
}
//BUTTONS
#mixin button-styles {
display: block;
width: 100%;
border: none;
margin-bottom: 15px;
padding: 10px;
color: $base-white;
text-transform: uppercase;
font-weight: bold;
}
$button-colors :(
default:$base-blue,
success:$base-green,
error:$base-red,
warning:$base-orange,
info:$base-purple
);
#mixin button-colors {
#each $button, $color in $button-colors {
.btn--#{$button} {
background-color: #{$color};
}
}
}
[class*=btn] {
#include button-styles;
}
//IMAGE
#mixin center-images {
display: block;
max-width: 100%;
margin: 0 auto;
padding: 8px;
}
[class^=img] {
#include center-images;
}
.img {
&--frame {
border: 2px solid $base-grey;
}
}
This is my HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Circles UI Kit</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/normalize.css">
</head>
<!--
List of classes used
Grid:
.container
.grid__row
.grid__col--1 *NOT USED HERE
.grid__col--2 *
.grid__col--3
.grid__col--4
.grid__col--5
.grid__col--6
.grid__col--7
.grid__col--8
.grid__col--9
.grid__col--10 *
.grid__col--11 *
.grid__col--12
.card
.centered
.theme__colors
(.grid__col--1, .grid__col--2, .grid__col--10, and .grid__col--11 are not used here in the HTML but would be good to include in the Sass)
Typography:
.container
.link
.blockquote
.headline--primary
.headline--secondary
Image:
.img--logo
.img--frame
.img--avatar
Navigation:
.nav
.nav__item
Buttons:
.btn--default
.btn--success
.btn--error
.btn--warning
.btn--info
.theme__colors
Forms:
.form
.form__label--hidden
.form__input
-->
<body class="container">
<div class="grid__row">
<div class="grid__col--3">
<a class="link" href="/">
<img class="img--logo" alt="circles logo" src="images/logo.png">
</a>
</div>
<div class="grid__col--9">
<nav role="navigation">
<ul class="nav">
<li class="nav__item">Typography</li>
<li class="nav__item">Buttons</li>
<li class="nav__item">Form</li>
<li class="nav__item">Images</li>
<li class="nav__item">Grid</li>
</ul>
</nav>
</div>
</div>
<div class="grid__row">
<div class="grid__col--12">
<div class="card">
<p>This is what the navigation menu looks like when the screen is at 769px or higher. When the screen is less
than 769px,
the menu will be displayed vertically.</p>
</div>
</div>
</div>
<div class="grid__row">
<div class="grid__col--8">
<div class="card">
<h4 id="type" class="headline--secondary">Typography</h4>
<h1 class="headline--primary">Take a look at this amazing headline</h1>
<p>This is a typical paragraph for the UI Kit. Here is what a link might look like.
The
typical font family for this kit is Helvetica Neue. This kit is intended for clean and refreshing web layouts.
No jazz hands here, just the essentials to make dreams come true, with minimal clean web design. The kit comes
fully equipped with everything from full responsive media styling to buttons to form fields. <em>I enjoy using
italics as well from time to time</em>.
Fell free to create the most amazing designs ever with this kit. I truly hope you enjoy not only the kit but
this
amazing paragraph as well. :)</p>
<blockquote class="blockquote">You know what really gets me going? A really nice set of block quotes. That's
right, block quotes that say, "Hey,
I'm an article you want to read and nurture."</blockquote>
</div>
</div>
<div class="grid__col--4">
<form class="form">
<legend id="forms" class="headline--secondary">Form Elements</legend>
<img class="img--avatar" src="images/avatar.png" alt="Avatar">
<label class="form__label--hidden" for="username">Username:</label>
<input class="form__input" type="text" id="username" placeholder="Username">
<label class="form__label--hidden" for="password">Password:</label>
<input class="form__input" type="password" id="password" placeholder="Password">
<button class="btn--default theme__colors" type="submit" value="Login">Login</button>
</form>
</div>
</div>
<h4 id="images" class="headline--secondary">Images</h4>
<div class="grid__row">
<div class="grid__col--6">
<img class="img--frame" src="images/image.png" alt="sample image">
</div>
<div class="grid__col--6">
<img class="img--avatar" src="images/avatar.png" alt="Avatar">
</div>
</div>
<h4 id="buttons" class="headline--secondary">Buttons</h4>
<div class="grid__row">
<div class="grid__col--12">
<button class="btn--default theme__colors">default</button>
<button class="btn--success theme__colors">success</button>
<button class="btn--error theme__colors">error</button>
<button class="btn--warning theme__colors">warning</button>
<button class="btn--info theme__colors">info</button>
</div>
</div>
<h4 id="grid" class="headline--secondary">Grid System</h4>
<div class="grid__row">
<div class="grid__col--12 theme__colors">.grid__col--12</div>
</div>
<div class="grid__row">
<div class="grid__col--6 theme__colors">.grid__col--6</div>
<div class="grid__col--6 theme__colors">.grid__col--6</div>
</div>
<div class="grid__row">
<div class="grid__col--4 theme__colors">.grid__col--4</div>
<div class="grid__col--4 theme__colors">.grid__col--4</div>
<div class="grid__col--4 theme__colors">.grid__col--4</div>
</div>
<div class="grid__row">
<div class="grid__col--3 theme__colors">.grid__col--3</div>
<div class="grid__col--3 theme__colors">.grid__col--3</div>
<div class="grid__col--3 theme__colors">.grid__col--3</div>
<div class="grid__col--3 theme__colors">.grid__col--3</div>
</div>
<div class="grid__row">
<div class="grid__col--5 theme__colors">.grid__col--5</div>
<div class="grid__col--7 theme__colors">.grid__col--7</div>
</div>
<div class="grid__row">
<div class="grid__col--8 theme__colors">.grid__col--8</div>
<div class="grid__col--4 theme__colors">.grid__col--4</div>
</div>
<div class="grid__row">
<div class="grid__col--7 theme__colors centered">.centered .grid__col--7</div>
</div>
</body>
</html>
You are missing two things:
The mixin of button colours need to be:
#mixin button-colors {
#each $button, $color in $button-colors {
&.btn--#{$button} {
background-color: #{$color};
}
}
}
with & before .btn.
You didn't call your mixin. You need to write:
[class*=btn] {
#include button-styles();
#include button-colors();
}
This is my HTML:
<div class="row trolibelanja">
<div class="col-md-3">
<img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
</div>
<div class="col-md-4">
<p class="detailnama">Mie Ayam Bakso</p>
<p class="detailtoko">Toko Bu Lastri</p>
</div>
<div class="col-md-2">
<p class="detailharga">Rp. 30.000</p>
</div>
<div class="col-md-2">
<div class="input-group">
<span class="input-group-btn">
<button class="btnjumlah" type="button">-</button>
</span>
<input type="text" class="form-control jumlah" value="1">
<span class="input-group-btn">
<button class="btnjumlah" type="button">+</button>
</span>
</div>
</div>
<div class="col-md-1">
</div>
</div>
This is my css:
body{
background-color: #661f61 !important;
font-family: 'Saira Extra Condensed', sans-serif !important;
}
.container-fluid.keranjang {
background-color: #e9e9e9;
flex: 1;
}
.container.keranjang {
}
.row.trolibelanja {
background-color: #e1e1e1;
position: relative;
padding-top: 10px;
padding-bottom: 23px;
}
.row.trolibelanja:after{
background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
position: absolute;
content: " ";
width: 100%;
height: 15px;
bottom: 0;
}
.detailfoto {
width: 100%;
height: 110px;
border: 6px solid white;
}
.detailnama{
font-size: 20px;
font-weight: bold;
}
.detailtoko{
line-height: 20px;
margin: -17px 0px;
}
.detailharga{
font-size: 20px;
font-weight: bold;
text-align: center;
}
.input-group .jumlah {
width: 50%;
text-align: center;
}
.input-group .btnjumlah {
background-color: #e27f31;
color: white;
border: 0;
font-size: 20px;
font-weight: bold;
padding: 0px 10px;
height: 100%;
}
I am trying to put text and form next to photo using bootstrap, as in photo below:
enter image description here
My code result:
enter image description here
Please let me know what am I missing? I tried each combination of display that i know, but they wouldn't work. Thank you
Arrange your columns properly. And you will be good. put image in one column (col-md-3 in this case) and rest of the content in another (col-md-9), then put all rest of the content in a new row. I would suggest that you have a better understanding of the rows and columns from bootstrap website.
https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
<div class="row trolibelanja">
<div class="col-md-3">
<img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<p class="detailnama">Mie Ayam Bakso</p>
<p class="detailtoko">Toko Bu Lastri</p>
</div>
<div class="col-md-2">
<p class="detailharga">Rp. 30.000</p>
</div>
<div class="col-md-2">
<div class="input-group">
<span class="input-group-btn">
<button class="btnjumlah" type="button">-</button>
</span>
<input type="text" class="form-control jumlah" value="1">
<span class="input-group-btn">
<button class="btnjumlah" type="button">+</button>
</span>
</div>
</div>
</div>
</div>
</div>
Add flex-wrap: nowrap; to your .row.trolibelanja like this:
.row.trolibelanja {
background-color: #e1e1e1;
position: relative;
padding-top: 10px;
padding-bottom: 23px;
flex-wrap: nowrap;
}
I made codepen example with your code: https://codepen.io/anon/pen/wPZoXX
i ran your code on bootsnipp and found everything is placed side by side to each other, except for the fact that you did not add img-responsive to the image class. and that the below code is distorting your design.
.row.trolibelanja:after{
background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
position: absolute;
content: " ";
width: 100%;
height: 15px;
bottom: 0;
}
dont you what you intent designing with that, but i think you need to run a check that css code .
when i added your css to it, it distort the whole code.
first review your CSS is well written , targeting the right class.
second add img-responsive to the img class and i think you are good
to go.
Please help me. I need 3 li element like in image those I downloaded (icon+text), but they have wrong behavior.
I need like this
.icon-equipment {
background-image: url('http://infocem.info/wp-content/uploads/2017/05/1.png');
background-position: left center;
background-repeat: no-repeat;
padding-left: 20px; /* Adjust according to image size to push text across. */
}
ul {
list-style: none;
}
.advantages {
display: flex;
flex-flow: row wrap;
border: 1px solid purple;
height: 123px;
margin: 0;
padding: 0;
}
.advantages > * {
margin-left: 92px;
}
<ul class="advantages">
<li class="icon-equipment">Поставка оборудования<br> и запчастей<br><span>От 11 ведущих производителей</span><li>
<li class="icon-payment">Рассрочка платежа<br><span>До 45 дней с оформления заказа</span></li>
<li class="icon-delivery">Доставка товаров<br><span>Международная и междугородняя<br>в срок до 10 дней</span></li>
</ul>
The main thing to understand here is how to set-up a good hierarchy, so that you may have control over it. What I mean is, you have to separate your item into sections, which can be arranged easily using your model of choice (flexbox in this case).
Just take a look at the html that I have provided, see how it is structured. You have a container, within that container you have two elements, a left-side element (icon) and a right-side element (texts).
Styles are also a thing to notice, you will need some prefixing as well.
Since this is your first time on stackoverflow, I will give you this code ready for use. Usually you have to provide some code that you have been working on, and then seek assisstance for it. Whatever you do, please DO NOT expect this for future problems that you post here on Stack. Read the rules, follow the rules.
html {
font-family: 'Helvetica Neue', Arial, sans-serif;
}
.icon-equipment {
background-image: url('http://infocem.info/wp-content/uploads/2017/05/1.png');
background-position: left center;
background-repeat: no-repeat;
/* Adjust according to image size to push text across. */
}
ul {
list-style: none;
}
.advantages {
display: flex;
flex-flow: row wrap;
margin: 0;
padding: 0;
}
.advantages .advantages-item {
display: flex;
align-items: flex-start;
background: #000;
color: #fff;
padding: 1rem;
max-width: 300px;
margin-right: 1rem;
margin-bottom: 1rem;
}
.advantages .advantages-item:last-of-type {
margin-right: 0;
}
.advantages .advantages-item .item-right {
display: flex;
flex-direction: column;
padding-left: 1rem;
}
.advantages .advantages-item .item-right .right-text {
font-weight: bold;
text-transform: uppercase;
margin: 0;
margin-bottom: 1rem;
}
<ul class="advantages">
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
<li class="advantages-item">
<div class="item-left">
<div class="top-icon">
<img src="http://infocem.info/wp-content/uploads/2017/05/1.png" alt="" class="icon">
</div>
</div>
<div class="item-right">
<p class="right-text">Поставка оборудования и запчастей</p>
<span>От 11 ведущих производителей</span>
</div>
<li>
</ul>