I made a simple page using Bootstrap 4 with a contact form and would like the button to be aligned to the bottom right, rather than bottom middle, of it. How can I accomplish this?
Here's the HTML of the form:
<div class="row">
<div class="col center-block">
<div class="contact">
<h2>Contact</h2>
<form action="mailto:test#test.com" method="post" enctype="text/plain">
<div class="form-group">
<input type="text" class="form-control" id="contact-name" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="contact-email" aria-describedby="emailinfo" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="contact-message" placeholder="Your message" required>
</div>
<button type="submit" class="btn btn-dark">Send</button>
</form>
</div>
</div>
</div>
And the CSS applied to buttons and form elements:
.form-control {
width: 50%;
margin: 0 auto;
border-bottom: 1px solid #888;
border-top: 0px;
border-left: 0px;
border-right: 0px;
border-radius: 0;
padding: 10px 0px;
}
input[type=text], input[type=email] {
background-color: WhiteSmoke;
}
button {
margin-top: 1em;
margin-bottom: 2em;
}
Use this code for button:
<div class="bt-btn">
<button type="submit" class="btn btn-dark">Send</button>
</div>
CSS:
.bt-btn {
margin: 0 auto;
text-align: right;
width: 50%;
}
button {
margin-top: 1em;
margin-bottom: 2em;
float: right;
margin-right: 25%;
}
#contact { max-width: 960px; margin: 0 auto; }
form { padding: 75px 25px; }
I would also recommend adding a container around it and give it a max-width of 960px. The whole form area.
You just use d-flex class nothing else and no need to use inline CSS
<div class="d-flex flex-row-reverse">
<button type="submit" class="btn btn-dark" >Send</button>
</div>
That's it.
<div class="form-group col-md-12 text-right mt-2">
<button type="submit" class="btn btn-primary pl-4 pr-4">Submit</button>
</div>
You could do something like.
button {
margin-right: 25%;
float : right;
}
Working example:
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-family: "Playfair Display", serif;
padding-top: 0.5em;
}
h2, h5 {
text-transform: uppercase;
/* Padding used instead of margins because whereas margins add space beyond element's box and therefore won't be colored, the inverse is true for padding */
padding: 0.5em 0;
margin: 0;
}
.about p {
padding: 0 4em 2em 4em;
margin: 0;
text-align: left;
}
.nav-link {
text-transform: uppercase;
color: white;
}
.nav-link:hover {
color: white;
}
.hero-image {
background-image: url(https://image.ibb.co/jEN7CS/workspace.jpg);
/* Set a specific height */
height: 100%;
/* Position and center the image to scale nicely on all screens */
background-position: center;
background-repeat: no-repeat;
/* Resizes background image to fill entire container */
background-size: cover;
position: relative;
}
.about {
background-color: WhiteSmoke;
}
.portfolio {
background-color: LightGrey;
}
.contact {
background-color: WhiteSmoke;
}
/* Removes white space from sides of each column */
.col {
padding: 0;
}
.footer {
position: bottom;
right: 0;
bottom: 0;
left: 0;
width: 100%;
padding: 0.75rem;
background-color: grey;
}
.footer-tag {
color: white;
text-align: left;
padding: 15px;
}
.fab {
float: right;
padding: 10px;
color: white;
}
.fab:hover {
color: #4d4d4d;
}
.form-control {
width: 50%;
margin: 0 auto;
border-bottom: 1px solid #888;
border-top: 0px;
border-left: 0px;
border-right: 0px;
border-radius: 0;
padding: 10px 0px;
}
input[type=text], input[type=email] {
background-color: WhiteSmoke;
}
button {
margin-top: 1em;
margin-bottom: 2em;
margin-right: 25%;
float : right;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- Grey horizontal navbar that becomes vertical on small screens -->
<nav class="navbar sticky-top navbar-expand-sm bg-dark">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="hero-image">
<div class="hero-text text-white">
<h1>Name</h1>
<h5>Web developer</h5>
<form action="mailto:test#test.com" method="post" enctype="text/plain">
<button class="btn btn-dark">Contact Me</button>
</form>
</div>
</div>
</div>
</div>
<section id="about">
<div class="row">
<div class="col">
<div class="about">
<h2>About</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut hendrerit arcu quis lectus auctor, nec laoreet augue ornare. Proin vehicula id purus ac accumsan. Aliquam eu rutrum orci. Aliquam rhoncus ipsum sed nisi porta mattis. Cras euismod sed justo a vehicula. Maecenas nibh magna, auctor nec erat in, hendrerit blandit turpis. Curabitur laoreet viverra mi at consequat. Donec mollis tortor sem, vel pharetra magna mattis quis. Praesent erat dolor, lacinia at euismod quis, sodales eu orci. Fusce ut nibh dolor. Suspendisse potenti. Proin fermentum eros condimentum hendrerit mattis. Morbi libero nibh, tempus aliquam leo sed, elementum rutrum turpis. Pellentesque et pharetra sapien. Nulla sed quam vel ex dictum egestas in tempus risus. Donec lacus magna, feugiat sed lobortis finibus, bibendum vel magna.</p>
</div>
</div>
</div>
</section>
<section id="portfolio">
<div class="row">
<div class="col">
<div class="portfolio">
<h2>Portfolio</h2>
</div>
</div>
</div>
</section>
<section id="contact">
<div class="row">
<div class="col center-block">
<div class="contact">
<h2>Contact</h2>
<form action="mailto:test#test.com" method="post" enctype="text/plain">
<div class="form-group">
<input type="text" class="form-control" id="contact-name" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="contact-email" aria-describedby="emailinfo" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="contact-message" placeholder="Your message" required>
</div>
<button type="submit" class="btn btn-dark">Send</button>
</form>
</div>
</div>
</div>
</section>
</div> <!-- End of container-fluid -->
<div class="footer">
<i class="fab fa-linkedin fa-2x"></i>
<i class="fab fa-github fa-2x"></i>
<i class="fab fa-codepen fa-2x"></i>
<div class="footer-tag">
<p>Created by Name.</p>
</div>
you need to make the width of your form 50% with margin:auto to keep it centered , and the inputs inside it 100% to fill the width of the form, wrap you button in a form-group and add text-align:right to it, this will keep the responsiveness ,
here's a fiddle : https://jsfiddle.net/takius/j730vdmp/21/
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-family: "Playfair Display", serif;
padding-top: 0.5em;
}
h2,
h5 {
text-transform: uppercase;
/* Padding used instead of margins because whereas margins add space beyond element's box and therefore won't be colored, the inverse is true for padding */
padding: 0.5em 0;
margin: 0;
}
.about p {
padding: 0 4em 2em 4em;
margin: 0;
text-align: left;
}
.nav-link {
text-transform: uppercase;
color: white;
}
.nav-link:hover {
color: white;
}
.hero-image {
background-image: url(https://image.ibb.co/jEN7CS/workspace.jpg);
/* Set a specific height */
height: 100%;
/* Position and center the image to scale nicely on all screens */
background-position: center;
background-repeat: no-repeat;
/* Resizes background image to fill entire container */
background-size: cover;
position: relative;
}
.about {
background-color: WhiteSmoke;
}
.portfolio {
background-color: LightGrey;
}
.contact {
background-color: WhiteSmoke;
}
/* Removes white space from sides of each column */
.col {
padding: 0;
}
.footer {
position: bottom;
right: 0;
bottom: 0;
left: 0;
width: 100%;
padding: 0.75rem;
background-color: grey;
}
.footer-tag {
color: white;
text-align: left;
padding: 15px;
}
.fab {
float: right;
padding: 10px;
color: white;
}
.fab:hover {
color: #4d4d4d;
}
.form-control {
width: 100%;
margin: 0 auto;
border-bottom: 1px solid #888;
border-top: 0px;
border-left: 0px;
border-right: 0px;
border-radius: 0;
padding: 10px 0px;
}
input[type=text],
input[type=email] {
background-color: WhiteSmoke;
}
button {
margin-top: 1em;
margin-bottom: 2em;
}
form {
width: 50%;
margin: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Grey horizontal navbar that becomes vertical on small screens -->
<nav class="navbar sticky-top navbar-expand-sm bg-dark">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="hero-image">
<div class="hero-text text-white">
<h1>Name</h1>
<h5>Web developer</h5>
<form action="mailto:test#test.com" method="post" enctype="text/plain">
<button class="btn btn-dark">Contact Me</button>
</form>
</div>
</div>
</div>
</div>
<section id="about">
<div class="row">
<div class="col">
<div class="about">
<h2>About</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut hendrerit arcu quis lectus auctor, nec laoreet augue ornare. Proin vehicula id purus ac accumsan. Aliquam eu rutrum orci. Aliquam rhoncus ipsum sed nisi porta mattis. Cras euismod sed
justo a vehicula. Maecenas nibh magna, auctor nec erat in, hendrerit blandit turpis. Curabitur laoreet viverra mi at consequat. Donec mollis tortor sem, vel pharetra magna mattis quis. Praesent erat dolor, lacinia at euismod quis, sodales
eu orci. Fusce ut nibh dolor. Suspendisse potenti. Proin fermentum eros condimentum hendrerit mattis. Morbi libero nibh, tempus aliquam leo sed, elementum rutrum turpis. Pellentesque et pharetra sapien. Nulla sed quam vel ex dictum egestas
in tempus risus. Donec lacus magna, feugiat sed lobortis finibus, bibendum vel magna.</p>
</div>
</div>
</div>
</section>
<section id="portfolio">
<div class="row">
<div class="col">
<div class="portfolio">
<h2>Portfolio</h2>
</div>
</div>
</div>
</section>
<section id="contact">
<div class="row">
<div class="col center-block">
<div class="contact">
<h2>Contact</h2>
<form action="mailto:test#test.com" method="post" enctype="text/plain">
<div class="form-group">
<input type="text" class="form-control" id="contact-name" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="contact-email" aria-describedby="emailinfo" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="contact-message" placeholder="Your message" required>
</div>
<div class="form-group" style="text-align:right;">
<button type="submit" class="btn btn-dark">Send</button>
</div>
</form>
</div>
</div>
</div>
</section>
</div>
<!-- End of container-fluid -->
<div class="footer">
<i class="fab fa-linkedin fa-2x"></i>
<i class="fab fa-github fa-2x"></i>
<i class="fab fa-codepen fa-2x"></i>
<div class="footer-tag">
<p>Created by Name.</p>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
Related
I am building a stepper component using a CSS grid.
The grid has two rows and its column count is based on the number of steps in the stepper.
Each step has a header and a body.
Each step header lives in row 1 and takes exactly one column of the grid.
I've made each step header to be as big as its content and to stretch until it reaches the min-width of its siblings.
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
The body of each step starts at row 2 and spans the number of columns in the first row, only the body of the selected step is visible, all others are hidden.
THE PROBLEM:
If the step body has short content the grid auto columns are working as expected, but if the body has a huge amount of content like in step 3 in example 1, all the columns in the grid look the same size, it's like the columns no longer respect the auto in the minmax() function and behave like they are all set to 1fr.
THE FIX:
The only fix I found is to explicitly set the width of the step body container to match the width of the entire stepper. I really want to avoid that, since the content of the step headers can be changed at runtime.
Example 1 - step with big body content
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sapien arcu, imperdiet sed augue ut, rhoncus elementum urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut id ultricies libero, ac interdum
justo. Donec auctor quam in neque commodo, eget auctor turpis condimentum. Integer blandit urna vitae nisi bibendum luctus. Ut a laoreet purus, vel dictum nibh. Vestibulum non faucibus mi, eu tempor lectus. Mauris in varius lacus. Nullam pretium
at felis nec pharetra. Suspendisse dui ex, ullamcorper ac scelerisque ut, fermentum at urna. Aliquam efficitur, leo et egestas convallis, sapien tortor tincidunt velit, a faucibus ligula dui ac eros. Nunc sed sagittis orci. Fusce quam est, convallis
ac commodo eget, tincidunt non erat.</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
Example 2 - step with small body content
#charset "UTF-8";
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>step 3 short content</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
As #MichaelBenjamin said, it's related to the content of the body. When it exceed a certain size the calculation of the column size behave differently.
I will try to grab the detail of such calculation but a solution is to make sure the body doesn't contribute to the grid size calculation by using width:0;min-width:100%;
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
width: 0;
min-width: 100%;
box-sizing: border-box;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sapien arcu, imperdiet sed augue ut, rhoncus elementum urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut id ultricies libero, ac interdum
justo. Donec auctor quam in neque commodo, eget auctor turpis condimentum. Integer blandit urna vitae nisi bibendum luctus. Ut a laoreet purus, vel dictum nibh. Vestibulum non faucibus mi, eu tempor lectus. Mauris in varius lacus. Nullam pretium
at felis nec pharetra. Suspendisse dui ex, ullamcorper ac scelerisque ut, fermentum at urna. Aliquam efficitur, leo et egestas convallis, sapien tortor tincidunt velit, a faucibus ligula dui ac eros. Nunc sed sagittis orci. Fusce quam est, convallis
ac commodo eget, tincidunt non erat.</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
width:0 will disable the size contribution and min-width:100% will make sure that your content fill all the available space (defined by the other content)
Few observations:
The columns break when the body content wraps. It's not just "a huge amount content" causing the problem, it's the wrap.
The body of the stepper preserves the column width until the moment the content wraps. The columns then start shrinking, and continue to shrink as more content is added, until the columns reach equal width.
Like you said, they "behave like they are all set to 1fr".
The problem is the auto value in the minmax argument in grid-template-columns. For some reason (I don't have time to look into this at the moment), the auto value resizes the columns on wrap.
Perhaps switch from auto to min-content.
(I'll ping #TemaniAfif. Maybe he can help.)
I have a main container with an aside. The aside has a fixed width, and I am using CSS Grid to draw this container. Inside the main container, there is a series of columns with dynamic data that automatically flow and align and shift data from one column to the other as needed. This column setup uses CSS Multi Columns, but the columns change width based on the user browser screen size. I would like to find a CSS solution that keeps these columns to a set width. Is there a way to auto expand the last drawn column? OR Is there a way to keep a dynamic multi-column count from expanding? I tried align-items:start, but don't see an effect. Could there be a way through a container to keep the columns to their set width?
#charset "UTF-8";
/* https://stackoverflow.com/questions/7785374/how-to-prevent-column-break-within-an-element */
html, body {
padding: 0;
margin: 0;
}
section {
padding: 3px;
}
input {
width: 100%;
box-sizing: border-box;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
font-family: "Miriam Libre";
font-size: 10px;
color: #213C3A;
}
.Cols {
margin: 0;
padding: 0;
columns: 40ch;
column-count: auto;
column-fill: auto;
column-rule: 1px dotted #3DB199;
height: 100vh;
/* ↓ columns defined by width */
overflow: auto;
}
li {
width: 100%;
display: inline-block;
padding: 3px;
border-bottom: 1px solid #D36B66;
}
.G {
display: grid;
}
.G-wAside {
grid-template-columns: 1fr minmax(0, 10vw) 10vw;
gap: 1vw;
}
.G-23 {
grid-template-columns: 66.66% 33.33%;
}
.HVpZ {
height: 100%;
}
.WVpZ {
width: 100%;
}
.filler {
background: #CCE0E2;
}
.fieldset {
margin: 5px 3px;
}
.fieldset > * {
margin: 1px 0;
}
.fieldset label {
margin-right: 3px;
}
.placeholder-uploader {
height: 320px;
width: 100%;
background: #FAF9E9;
}
.placeholder-grid {
width: 640px;
height: 230px;
background: #FAF9E9;
position: absolute;
}
.col-container {
overflow: hidden;
position: relative;
height: 100px;
grid-row-start: span 2;
}
<main class="G HVpZ WVpZ G-wAside">
<section>
<ul class="Cols">
<li>
<div class="fieldset">
<label>New List Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
<div class="G G-23">
<div class="fieldset">
<label>Grid Label DIV Name</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Longest Of All</label>
<input type="text"></input>
</div>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</li>
<li>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
</li>
<li>
<p>Praesent vestibulum semper erat ut varius. Donec sed erat ac odio ultricies bibendum et sit amet lectus. In placerat consequat mi, sed commodo mauris ornare non. Integer nibh leo, dignissim in purus at, pretium porta nibh. Nulla vestibulum imperdiet
sollicitudin. Morbi euismod justo metus, quis imperdiet nunc eleifend ultrices. Donec nec maximus lacus. Aenean tincidunt mattis nisi, eget molestie dolor iaculis vel. Praesent faucibus risus vel arcu tincidunt, id varius orci bibendum. Duis
posuere est in diam luctus ultrices id in sapien. Fusce bibendum pharetra velit, sit amet commodo diam pharetra ac.</p>
</li>
</ul>
</section>
<section class="filler">← How to auto-fill this space to keep css multi columns in previous grid item to set width of 40ch? →</section>
<section class="bg">Aside</section>
</main>
I don't know if this will fulfill your needs and perhaps it can be combined with the previous answer.
Since the input column appears fixed in size, why not use a table layout JUST for this section? Probably needs some other CSS changes for the responsive nature of your design.
#charset "UTF-8";
/* https://stackoverflow.com/questions/7785374/how-to-prevent-column-break-within-an-element */
html,
body {
padding: 0;
margin: 0;
}
section {
padding: 3px;
}
input {
width: 100%;
box-sizing: border-box;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
font-family: "Miriam Libre";
font-size: 10px;
color: #213C3A;
}
.Cols {
margin: 0;
padding: 0;
columns: 40ch;
column-count: auto;
column-fill: auto;
column-rule: 1px dotted #3DB199;
height: 100vh;
/* ↓ columns defined by width */
overflow: scroll;
}
li {
width: 100%;
display: inline-block;
padding: 3px;
border-bottom: 1px solid #D36B66;
}
.G {
display: grid;
}
.G-wAside {
grid-template-columns: 1fr minmax(0, 10vw) 10vw;
gap: 1vw;
}
.G-23 {
grid-template-columns: 66.66% 33.33%;
}
.HVpZ {
height: 100%;
}
.WVpZ {
width: 100%;
}
.filler {
background: #CCE0E2;
}
.fieldset {
margin: 5px 3px;
}
.fieldset>* {
margin: 1px 0;
}
.fieldset label {
margin-right: 3px;
}
.placeholder-uploader {
height: 320px;
width: 100%;
background: #FAF9E9;
}
.placeholder-grid {
width: 640px;
height: 230px;
background: #FAF9E9;
position: absolute;
}
.col-container {
overflow: hidden;
position: relative;
height: 100px;
grid-row-start: span 2;
}
#tbl {
table-layout: fixed;
}
#tbl td {
min-width: 25em;
max-width: 25em;
}
#tbl2 {
table-layout: fixed;
}
#tbl2 td {
min-width: 25em;
}
ul {
list-style-type: none;
cursor: pointer;
}
li {
display: inline-block;
}
/* default is vertical display */
<main class="G HVpZ WVpZ G-wAside">
<section>
<ul class="Cols">
<li>
<table id="tbl" border="1">
<tr>
<td>
<div class="fieldset">
<label>New List Is Just Long</label>
<input type="text"></input>
</div>
</td>
</tr>
<tr>
<td>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</td>
</tr>
<tr>
<td>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</td>
</tr>
<tr>
<td>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
</td>
</tr>
<tr>
<td>
<div class="G G-23">
<div class="fieldset">
<label>Grid Label DIV Name</label>
<input type="text"></input>
</div>
<div class="fieldset">
<label>Label Is Just Longest Of All</label>
<input type="text"></input>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text"></input>
</div>
</td>
</tr>
</table>
</li>
<!--
<li>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
</li>
// -->
<li>
<table id="tbl2" border="1">
<tr>
<td>
<p>Praesent vestibulum semper erat ut varius. Donec sed erat ac odio ultricies bibendum et sit amet lectus. In placerat consequat mi, sed commodo mauris ornare non. Integer nibh leo, dignissim in purus at, pretium porta nibh. Nulla vestibulum
imperdiet sollicitudin. Morbi euismod justo metus, quis imperdiet nunc eleifend ultrices. Donec nec maximus lacus. Aenean tincidunt mattis nisi, eget molestie dolor iaculis vel. Praesent faucibus risus vel arcu tincidunt, id varius orci
bibendum. Duis posuere est in diam luctus ultrices id in sapien. Fusce bibendum pharetra velit, sit amet commodo diam pharetra ac.</p>
</td>
</tr>
</table>
</li>
</ul>
</section>
<section class="filler">
← How to auto-fill this space to keep css multi columns in previous grid item to set width of 40ch? →
</section>
<section class="bg">Aside</section>
</main>
So if I understand you correctly you have two questions:
I would like to find a CSS solution that keeps these columns to a set width.
Is there a way to auto expand the last drawn column? OR Is there a way to keep a dynamic multi-column count from expanding?
Answer to #1, #2:
If you want a fixed size for a column in your grid then use absolute units for your grid-template-columns property.
Instead of this:
grid-template-columns: 1fr minmax(0, 10vw) 10vw;
Use this:
/*Sets the minimal
width to 0 and
fills in the rest
of the available
space.
↓ */
grid-template-columns: 40ch minmax(0, 1fr);
/* ↑
Sets a fixed
width to your
first column */
This way your first column is exactly 40ch in width and the second one (the aside) fills up the rest of the space, which essentially answers your question #2 too.
At the end it looks like this:
#charset "UTF-8";
/* https://stackoverflow.com/questions/7785374/how-to-prevent-column-break-within-an-element */
html,
body {
padding: 0;
margin: 0;
}
input {
width: 100%;
box-sizing: border-box;
}
label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
font-family: "Miriam Libre";
font-size: 10px;
color: #213C3A;
}
.Cols {
margin: 0;
padding: 0;
columns: 40ch;
column-count: auto;
column-fill: auto;
column-rule: 1px dotted #3DB199;
height: 100vH;
/* ↓ columns defined by width */
overflow: auto;
}
li {
width: 100%;
display: inline-block;
padding: 3px;
border-bottom: 1px solid #D36B66;
}
.G {
display: grid;
}
.G-wAside {
grid-template-columns: 40ch minmax(0, 1fr);
gap: 1vw;
}
.G-23 {
grid-template-columns: 66.66% 33.33%;
}
.HVpZ {
height: 100%;
}
.WVpZ {
width: 100%;
}
.filler {
background: #CCE0E2;
}
.fieldset {
margin: 5px 3px;
}
.fieldset>* {
margin: 1px 0;
}
.fieldset label {
margin-right: 3px;
}
.placeholder-uploader {
height: 320px;
width: 100%;
background: #FAF9E9;
}
.placeholder-grid {
width: 640px;
height: 230px;
background: #FAF9E9;
position: absolute;
}
.col-container {
overflow: hidden;
position: relative;
height: 100px;
grid-row-start: span 2;
}
<main class="G HVpZ WVpZ G-wAside">
<section>
<ul class="Cols">
<li>
<div class="fieldset">
<label>New List Is Just Long</label>
<input type="text">
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text">
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text">
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text">
</div>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
<div class="G G-23">
<div class="fieldset">
<label>Grid Label DIV Name</label>
<input type="text">
</div>
<div class="fieldset">
<label>Label Is Just Longest Of All</label>
<input type="text">
</div>
</div>
<div class="fieldset">
<label>Label Is Just Long</label>
<input type="text">
</div>
</li>
<li>
<div class="col-container">
<div class="placeholder-grid"></div>
</div>
</li>
<li>
<p>Praesent vestibulum semper erat ut varius. Donec sed erat ac odio ultricies bibendum et sit amet lectus. In placerat consequat mi, sed commodo mauris ornare non. Integer nibh leo, dignissim in purus at, pretium porta nibh. Nulla vestibulum imperdiet
sollicitudin. Morbi euismod justo metus, quis imperdiet nunc eleifend ultrices. Donec nec maximus lacus. Aenean tincidunt mattis nisi, eget molestie dolor iaculis vel. Praesent faucibus risus vel arcu tincidunt, id varius orci bibendum. Duis
posuere est in diam luctus ultrices id in sapien. Fusce bibendum pharetra velit, sit amet commodo diam pharetra ac.</p>
</li>
</ul>
</section>
<section class="filler">← How to auto-fill this space to keep css multi columns in previous grid item to set width of 40ch? →</section>
</main>
PS:
In your code you are closing your <input> tags. This is not necessary and a syntax error. Therefore, I fixed it in my example code.
Edit #1
Hi #Aaron3219. Thanks for your answer. My question is: "Is there a way to keep a dynamic multi-column count from expanding?" And the main issue is in .Cols {} where I have a set width columns: 40ch and column-count: auto. I want to make sure that when these columns display, whether it's one or 10, that they have, strictly, a set width of 40ch that does not respond when the viewport width changes.
As far as I am concerned, no there isn't. The column-width property (which you are using in columns in a shorthand) is a suggestion for the browser for a minimal column width and not an absolute width.
Or, as w3schools put it:
The column-width property specifies the column width.
The number of columns will be the minimum number of columns needed to show all the content across the element.
column-width is a flexible property. Think of column-width as a minimum width suggestion for the browser. Once the browser cannot fit at least two columns at your specified width then the columns will stop and drop into a single column.
But there are, of course, ways to achieve the structure you intend for example with a flexbox or a grid. I am sure that using columns is an approach not suitable for what you intend to do.
this is my first time posting, I hope I respected all the guidelines. If not, I'm sorry!
I'm trying to create a responsive website design with the following specs:
1. Large background image, that does not change
2. set of (not yet determined amount) radio(?) buttons below
-> buttons need to be mutually exclusive
3. image overlay with some text, that changes when the respective radio button is pressed
4. when in mobile mode only two buttons should be shown at the same time and two arrows appear to cycle between all possible buttons.
My problem starts at 4):
- I dont have the faintest idea where to start
- I dont know if there is a name for this type of behaviour, that I simply never heard of (which makes googleing a little hard^^)
I thought about Flex-boxes, but all I could manage was to wrap the buttons, but thats not really the same as hiding them.
I also thought about making the buttons simply disappear (display:none), but I'm not so sure on how to do that. (maybe putting additional rules for the bootstrap classes?)
On top of it all, the design needs to be laid out in such a way, that the customer can decide how many buttons there will be, e.g. I have no way of knowing beforehand how many there are, nor can I group them by adding specific classes.
My Question alas is this: can I dynamically embed the radio buttons on slider pages, which i can scroll through, but only if it is in a small screen? (my guess is, this is not a simple css matter)
edit: specified question
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/styles.css">
<script src="https://kit.fontawesome.com/82bfdd8cdc.js"></script>
</head>
<body>
<div class="">
<div class="bg-screen">
<img src="img/test.jfif" alt=" " class="bg-screen-img">
<div class="bg-screen-textarea">
</div>
<p class="bg-screen-text dummy"></p>
<div class="radio">
<label>
<input type="radio" name="radio" />
<div class="radio-box box-1">
<i class="fas fa-socks fa-3x"></i>
<span>Choice 1</span>
</div>
<div class="bg-screen-text text-1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Nulla at volutpat diam ut venenatis tellus. Odio ut sem nulla pharetra diam sit
amet. Phasellus egestas tellus rutrum tellus pellentesque eu tincidunt.</div>
</label>
<label>
<input type="radio" name="radio" />
<div class="radio-box box-2">
<i class="fas fa-user-tie fa-3x"></i>
<span>Choice 2</span>
</div>
<div class="bg-screen-text text-2">Sit amet facilisis magna etiam tempor orci eu lobortis. Consectetur lorem donec massa sapien faucibus et molestie ac feugiat.
</div>
</label>
<label>
<input type="radio" name="radio" />
<div class="radio-box box-3">
<i class="fas fa-building fa-3x"></i>
<span>Choice 3</span>
</div>
<p class="bg-screen-text text-3">Risus ultricies tristique nulla aliquet enim tortor at auctor urna.</p>
</label>
<label>
<input type="radio" name="radio" />
<div class="radio-box box-4">
<i class="fas fa-building fa-3x"></i>
<span>Choice 4</span>
</div>
<p class="bg-screen-text text-4">Fringilla ut morbi tincidunt augue. Velit euismod in pellentesque massa placerat duis ultricies lacus. </p>
</label>
<label>
<input type="radio" name="radio" />
<div class="radio-box box-5">
<i class="fas fa-building fa-3x"></i>
<span>Choice 5</span>
</div>
<p class="bg-screen-text text-5">Ut enim blandit volutpat maecenas volutpat blandit aliquam etiam.</p>
</label>
</div>
</div>
</div>
</body>
</html>
input {
display: none;
}
input+div{
background: rgba(76, 175, 80, 0.3);
border: 1px solid grey;
}
input:checked+div {
background-color: green;
}
label {
display: inline-block;
margin: 0 1%;
}
/*removing clickability of text itself inside the labels for the radio-buttons*/
label span {
/* Firefox */
-moz-user-select: none;
/* Internet Explorer */
-ms-user-select: none;
/* KHTML browsers (e.g. Konqueror) */
-khtml-user-select: none;
/* Chrome, Safari, and Opera */
-webkit-user-select: none;
/* Disable Android and iOS callouts*/
-webkit-touch-callout: none;
}
label div i{
margin: 15% auto;
}
input:checked~.bg-screen-text {
display: inline-block;
margin: -25% 10%;
text-align: center;
color: white;
}
.bg-screen{
width: 100%;
text-align: center;
}
.bg-screen-img{
margin: 3% 7%;
height: 25%;
background-color: grey;
}
.bg-screen-text {
display: none;
position: absolute;
text-align: center;
left: 7%;
right:7%;
margin: 0 10%;
}
.radio {
position: relative;
top: -150px;
margin: 3% 7%;
text-align: center;
}
.radio-box {
position: relative;
height: 170px;
width: 170px;
display: inline-block;
text-align: center;
}
.radio-box span {
position: absolute;
transform: translate(0, 90px);
left: 0;
right: 0;
}
Thanks!
I got it working with the help of slick carousel. (https://github.com/kenwheeler/slick/)
This pretty much gave me all the functionality without having to code it myself.
This is my HTML page:
https://jsfiddle.net/62czmtvt/2/ (to actually see the HTML page working)
Code from JSFiddle:
:root {
background-color: #FFFACD;
}
div.infoguide {
width: 240px;
font-family: Arial, sans-serif;
font-size: 13px;
background-color: #F0FFF0;
}
div {
margin: 5;
padding: 0;
border: 0;
outline: 0;
}
A:link {
text-decoration: underline;
color: rgb(204, 51, 51);
}
A:visited {
text-decoration: underline;
color: rgb(204, 51, 51);
}
A:active {
text-decoration: underline;
color: rgb(204, 51, 51);
}
A:hover {
text-decoration: underline;
color: rgb(204, 51, 51);
}
body {
margin-left: 0px;
margin-top: 0px;
}
body,
td,
th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: rgb(46, 46, 46);
line-height: 16px;
}
h1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
font-weight: bold;
line-height: 20px;
margin-bottom: 0px;
}
h2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
font-weight: bold;
margin-bottom: 0px;
}
h3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
margin-bottom: 0px;
}
h3 A:link {
text-decoration: none;
color: rgb(204, 51, 51);
}
h3 A:visited {
text-decoration: none;
color: rgb(204, 51, 51);
}
h3 A:active {
text-decoration: none;
color: rgb(204, 51, 51);
}
h3 A:hover {
text-decoration: underline;
color: rgb(204, 51, 51);
}
ul {
margin-left: 1.5em;
padding-left: 0px;
}
.info_data {
border-color: rgb(137, 137, 137);
border-style: solid;
border-width: 1px;
font-size: 11px;
padding: 4px;
text-align: center;
}
.news_headline {
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
font-weight: bold;
line-height: 22px;
}
.red {
color: rgb(204, 51, 51);
}
.red_padded {
color: rgb(204, 51, 51);
padding: 4px 0px;
}
.redbg {
background-color: rgb(220, 6, 0);
}
<title>First Drive: 2017 Porsche Panamera - Autos.ca</title>
<div class="infoguide">
<H3>It works!</h3>
<p>It works!</p>
</div>
<div class="info_data">
</div>
<div class="infoguide">
<h2 class="red">A headline</h2>
<p>It works!</p>
</div>
It's a sandbox page for a blog-like layout of a magazine site, and I'm trying to achieve this sort of look:
Magazine article
but so far I haven't quite managed to get it to look the way I want to of being a three-column DIV with a header in a pseudo-blog-style layout.
I've been trying the :root element in my CSS file, is this encouraged or discouraged in a HTML5 page?
I would appreciate any advice or help with this!
In order to achieve three columns, you will need to alter your code a bit.
You need a wrapper/container around your three divs you are attempting to separate and give it a 100% width or whatever width you want.
You need to give the three divs a similar second class name and apply a float and a width to those divs. (There are other ways, but this is the clean way).
CSS:
<style>
.page-container {
width: 100%;
}
.infoguide {
float: left;
width: 30%;
}
</style>
HTML:
<title>First Drive: 2017 Porsche Panamera - Autos.ca</title>
<div class="page-container">
<div class="infoguide">
<H3>It works!</h3>
<p>It works!</p>
</div>
<div class="infoguide">
<h1>Test Content</h1>
</div>
<div class="infoguide">
<h2 class="red">A headline</h2>
<p>It works!</p>
</div>
</div>
I would also consider reading into flexbox if you're unfamiliar with it. It's a great way to make responsive webpages with many divs in column format.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You're going to have to make a couple of changes:
Wrap the divs that you want to be aside each other in another div (let's call it wrapper).
Float the contents of the wrapper div to the left and give them the desired widths to get the layout.
Make sure to include a clearfix to clear the floats.. or the content that comes after the wrapper div will sit beneath it.
Use media queries to adjust the layout for mobile devices.
This is a very basic example of how to do that. I set a width for container, float the elements, set a width for them and then using media queries, I adjust the layout so that they fill the full width when the viewport is below 500px.
Notice that the main and sidebar don't have any space between them. If you want to separate them with a bit of margin, check this answer of mine.
https://jsfiddle.net/63o6mfy8/2/
Also be sure to clear the floats like I did in the fiddle.
.page-container::after {
content: '';
display: table;
clear: both;
}
You should learn Bootstrap. With Bootstrap you can easily build whatever layout you want. For now you can start with the following snippet. For clear understanding start learning Bootstrap here.
/* These are demo CSS to show the output nicely, do not use these */
.header {
height: 100px;
background: #ffa114;
}
.left-column {
background: #4fff4f;
height: 180px;
}
.right-column {
background: #52a8ff;
}
.footer {
height: 100px;
background: #ffa114;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="container">
<div class="header">
Here is the title
</div>
<div class="container">
<div class="row">
<div class="left-column col-9">
Left Column
</div>
<div class="right-column col-3">
Right Column
</div>
</div>
</div>
<div class="footer">
Bottom Content
</div>
</div>
I'll restate the obvious, and repeated suggestion, to learn and leverage Bootstrap. I'm still learning myself, so maybe the details I've included here will assist you understanding how to leverage the templates that already exist. In this answer I've modified the Jumbotron template, which is included with the Bootstrap download.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Jumbotron Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<main role="main">
<div class="jumbotron"><!-- start jumbotron -->
<div class="container"><!-- start title container -->
<h1>First Drive: 2017 Porsche Panamera</h1>
<h2>Awesome!!!</h2>
</div><!-- end title container -->
</div><!-- end jumbotron -->
<div class="container"><!-- start article container -->
<div class="row"><!-- start container row -->
<div class="col-md-9"><!-- start article column -->
<h2>Intro</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p>
<div class="row"><!-- start sub row -->
<div class="col-md-9">
<h3>Article</h3>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
</div>
<div class="col-md-3">
<h3>Mini Side</h3>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
</div>
</div><!-- end sub row -->
</div><!-- end article column -->
<div class="col-md-3"><!-- start side column -->
<h3>Side</h3>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus
commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet
risus. Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
</div><!-- end side column -->
</div><!-- end container row -->
<hr>
</div><!-- end article container -->
</main>
<footer class="container">
<p>© Company 2017-2018</p>
</footer>
</body>
</html>
One of the beautiful aspects of using Bootstrap is responsive design. You'll need a whole lot more details to replicate the full look of the site example you provided, but I think, other than some of the ad spaces, this should get you started, with the columns necessary to isolate your titles, the article, add images, etc.
You'll also notice that I didn't need to change any of the CSS that's also included with Bootstrap, i just referenced the CDN.
I hope this helps.
I'm using the new CSS3 layout technique defined by gridbyexample.com.
It's works very well except when I try to print the layout. Chrome and Firefox seem to be ignoring any page breaks and the landscape view mode I have defined in the CSS. I have a code pen for my project but it seems to change how it looks in print preview mode so it's only good for looking at HTML and CSS but not how the print will look.
https://codepen.io/JeffreySpring/pen/rzjeKm
I have created a .zip file with all the files and images that can be downloaded from https://drive.google.com/open?id=0B0LdH-fKpAKeY0NRa290M25uTGc
Here is the HTML
<!DOCTYPE html>
<html>
<head>
<title>Steam Controller Bindings Template</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body cz-shortcut-listen="true" style="">
<ul class="wrapper">
<li class="device">
<div id="steamDeviceContainer">
<div><h1>Couch Gamer's Witcher 3 Bindings</h1></div>
<img src="img/steam_controller.png" alt="Steam Controller">
</div>
<div class="mappingGyroShift1">
<h3 class="mappingHeader gyroShift1">Gyro<span class="boundTo gyroShift1">(Mouse Joystick)</span></h3>
<div class="actionBind gyroShift1">Precision Crossbow/Bomb Aim</div>
</div>
</li>
<li>
<div class="mapping">
<h3 class="mappingHeader">Left Trigger</h3>
<div class="actionBind">Use Witcher Senses</div>
<div class="actionBind">Block or Counterattack</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Left Bumper</h3>
<div class="actionBind">Quick choice menu</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Select Button</h3>
<div class="actionBind">Pause Game/Game Options</div>
<div class="actionBind">HOLD: Inventory Screen</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Left Grip</h3>
<div class="actionBind">Use Item</div>
<div class="actionBind gyroShift1">HOLD: (GYRO ON) Aim Crossbow/Bomb</div>
</div>
</li>
<li>
<div class="mapping">
<h3 class="mappingHeader">Right Trigger</h3>
<div class="actionBind">Use Sign</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Right Bumper</h3>
<div class="actionBind">Quick Save</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Start Button</h3>
<div class="actionBind">In Game Menu</div>
<div class="actionBind">HOLD: Map</div>
</div>
<div class="mapping">
<h3 class="mappingHeader">Right Grip</h3>
<div class="actionBind modeShift1">Mode Shift Left TouchPad</div>
<div class="actionBind modeShift1">Mode Shift A Button</div>
</div>
</li>
<li class="wide">
<div class="mapping pageBreakAfter">
<h3 class="mappingHeader">Left Joystick<span class="boundTo">(Joystick Move)</span></h3>
<div class="actionBind">ROTATE: Move Character</div>
<div class="actionBind">DOUBLE PRESS: Call your mount</div>
</div>
</li>
<li class="wide">
<div class="mapping pageBreakAfter">
<h3 class="mappingHeader">Face Buttons<span class="boundTo">(Button Pad)</span></h3>
<div class="actionBind aBtn">A BUTTON: Interact/Roll</div>
<div class="actionBind aBtn">A BUTTON HOLD: Run/Quick Swim/Gallop/Accelerate Boat</div>
<div class="actionBind aBtn">A BUTTON QUICK DOUBLE PRESS THEN HOLD: Full Gallop</div>
<div class="actionBind bBtn">B BUTTON: Jump/Dodge/Let helm go</div>
<div class="actionBind bBtn">B BUTTON HOLD: Resurfacing</div>
<div class="actionBind yBtn">Y BUTTON: Strong attack</div>
<div class="actionBind xBtn">X BUTTON: Fast Attack</div>
<div class="actionBind xBtn">X BUTTON HOLD: Submerging/Stop the Boat</div>
<div class="actionBind modeShift1">A BUTTON: Autoloot</div>
</div>
</li>
<li class="wide">
<div class="mapping">
<h3 class="mappingHeader">Left TouchPad<span class="boundTo">(4 way D-Pad)</span></h3>
<div class="actionBind">D-PAD UP: Consumable 1/3</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 1/3</div>
<div class="actionBind">D-PAD DOWN: Consumable 2/4</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 2/4</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding steel sword</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding silver sword</div>
<div class="actionBind modeShift1">MODE SHIFT RIGHT GRIP: Radial Menu 1</div>
</div>
</li>
<li class="wide">
<div class="mapping">
<h3 class="mappingHeader">Right TouchPad<span class="boundTo">(4 way D-Pad)</span></h3>
<div class="actionBind">D-PAD UP: Consumable 1/3</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 1/3</div>
<div class="actionBind">D-PAD DOWN: Consumable 2/4</div>
<div class="actionBind">D-PAD UP HOLD: Switch to Consumable 2/4</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding steel sword</div>
<div class="actionBind">D-PAD LEFT: Drawing or hiding silver sword</div>
</div>
</li>
<li class="full">
<div class="mappingModeShift1">
<h3 class="mappingHeader modeShift1">Radial Menu 1<span
class="boundTo modeShift1">(6 button touch menu)</span></h3>
<div class="actionBind modeShift1">BUTTON 1: Aard</div>
<div class="actionBind modeShift1">BUTTON 2: Yrden</div>
<div class="actionBind modeShift1">BUTTON 3: Igni</div>
<div class="actionBind modeShift1">BUTTON 4: Quen</div>
<div class="actionBind modeShift1">BUTTON 5: Axii</div>
<div class="actionBind modeShift1">BUTTON 6: Swap Crossbow/Bomb</div>
</div>
</li>
<li class="full">
<div class="mapping">
<h3 class="mappingHeader">Details</h3>
<div class="notes">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis efficitur arcu ut sapien ullamcorper,
vel ornare tellus venenatis. Pellentesque non sapien magna. Suspendisse potenti. Duis et turpis
sapien.
Donec turpis odio, posuere dignissim ornare semper, commodo a nunc. Nunc lacinia felis id elementum
vehicula.
Curabitur vel risus luctus, ornare nulla ac, tincidunt tellus. Nam tortor lorem, aliquet ut
efficitur vel,
</p>
<p>
ullamcorper vel metus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
Nam v
itae odio arcu. Phasellus fermentum nisi ipsum, a viverra urna placerat dignissim. Ut tempus finibus
mauris
faucibus consequat. Proin eu risus interdum, malesuada lectus id, egestas tortor. In imperdiet eget
augue et semper.
Sed risus justo, pulvinar id velit et, ullamcorper posuere ex. Nulla vel laoreet purus. Vivamus sed
venenatis erat,
in aliquam lectus. Mauris et lectus id eros feugiat viverra eu eu massa.
</p>
<p>
Nam egestas malesuada ligula quis cursus. Duis quis lorem in nunc maximus malesuada. Cras ante enim,
tincidunt ac
risus vel, elementum tincidunt erat. Ut auctor dolor a metus ornare auctor. Pellentesque at tellus
mi. Morbi e
fficitur metus vel enim ullamcorper, quis sagittis eros condimentum. Phasellus laoreet consectetur
lectus et dapibus.
Morbi tincidunt id mi nec ullamcorper. Integer dictum, justo vitae ullamcorper tristique, lorem nunc
rutrum augue, ut
pellentesque diam purus at ex. Proin sollicitudin iaculis eros.
</p>
</div>
</div>
</li>
<li class="full noPrint">
<div class="mapping">
<h3 class="mappingHeader">Screenshots</h3>
<div class="notes">
<div>
<img src="img/customRadialMenu.png" alt="Custom Menu Screenshot">
</div>
</div>
</div>
</li>
<li class="full noPrint">
<div id="videoWrapper">
<div class="video-container">
<iframe width="560" height="315" src="https://www.youtube.com/embed/4lcm4bdtkZs" frameborder="0"
allowfullscreen></iframe>
</div>
</div>
</li>
</ul>
</body>
</html>
Here is the CSS
/*noinspection CssUnknownTarget*/
#import url('https://fonts.googleapis.com/css?family=Oswald');
html {
box-sizing: border-box;
font-family: 'Oswald', sans-serif;
}
*, *:before, *:after {
box-sizing: inherit;
background-color: #00335B;
color: #F9F3F4;
}
img {
max-width: 100%;
}
.wrapper {
list-style: none;
margin: 0 auto 0 auto;
padding: 0;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-auto-flow: dense;
}
#media print {
.noPrint {
display: none !important;
}
#page {
size: landscape; /* auto is the initial value */
/* this affects the margin in the printer settings */
margin: 25px 25px 25px 25px;
}
div.pageBreakAfter {
page-break-after: always;
page-break-inside: avoid;
}
div.pageBreakBefore {
page-break-before: always;
page-break-inside: avoid;
}
}
#media (min-width: 460px) {
.wrapper {
grid-template-columns: 1fr 1fr;
}
.device {
grid-column: 1 / 3;
}
.full {
grid-column: auto / span 2;
}
}
#media (min-width: 660px) {
.wrapper {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.device {
grid-column: 2 / 4;
grid-row: 1 / 3;
}
.wide {
grid-column: auto / span 2;
}
.full {
grid-column: auto / span 4;
}
}
.wrapper li {
margin: 10px;
padding: 10px;
}
h1 {
font-family: 'Oswald', sans-serif;
color: #F9F3F4;
text-shadow: 0 0 300px #000;
font-size: 150%;
text-align: center;
}
.mapping {
border: solid #F9F3F4 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #F9F3F4;
margin: 20px;
}
.mappingModeShift1 {
border: solid #FF8C00 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #FF8C00;
margin: 20px;
}
.mappingGyroShift1 {
border: solid #00FFFF 3px;
border-radius: 9px;
font-family: 'Oswald', sans-serif;
color: #00FFFF;
margin: 20px;
}
.mappingHeader {
padding-left: 3px;
padding-right: 3px;
font-family: 'Oswald', sans-serif;
font-style: normal;
position: relative;
left: 30px;
top: -10px;
text-transform: uppercase;
display: inline;
}
#steamDeviceContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#videoWrapper {
margin-left: 15px;
margin-right: 15px;
}
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
.video-container iframe, .video-container object, .video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.actionBind {
margin-left: 30px;
margin-right: 10px;
padding-bottom: 10px;
}
.notes {
margin-left: 30px;
margin-right: 30px;
margin-bottom: 30px;
padding-bottom: 10px;
}
.boundTo {
font-size: xx-small;
vertical-align: super;
padding: 2px;
}
.modeShift1 {
color: #FF8C00 !important;
}
.gyroShift1 {
color: #00FFFF !important;
}
.yBtn {
color: #F4D00F;
}
.xBtn {
color: #0084C4;
}
.aBtn {
color: #34A853;
}
.bBtn {
color: #fc0602;
}
As you have found page pages do not work inside of grid layout block. I tried everything I could think of, but just doesn't work.
The solution to my report was to do the page-break-before outside the grid layout block.
It makes it a little trick, but it can be done. You just have to make sure your page-break is outside any display: grid class.