How can you fix sidebar issue here:
http://codepen.io/chriscoyier/pen/ClGcF
body {
padding: 30px;
}
header {
background: lightblue;
}
section {
background: lightgreen;
width: 75%;
float: left;
}
article {
background: white;
margin: 0 0 1rem 0;
}
aside {
background: pink;
width: 25%;
float: right;
}
header,
article,
section,
.module {
padding: 1rem;
}
<main>
<header>
<h1>Site</h1>
</header>
<section>
<article>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab doloremque accusamus iusto aliquam facilis sapiente!</p>
</article>
<article>
<h2>Title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab doloremque accusamus iusto aliquam facilis sapiente!</p>
</article>
</section>
<aside>
<div class="module">
<h3>Module</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio rem ab delectus fugit repellendus perspiciatis dolor consequuntur tenetur voluptatem a vitae odit aspernatur? Voluptas quisquam corporis nostrum aspernatur aliquid harum saepe ab pariatur
veniam iste ipsam alias nemo voluptatibus doloribus.</p>
</div>
</aside>
</main>
The goal is to have the sidebar move back to the top.
My confusion:
Where is the sidebar there inside the pen?
<aside> is the sidebar part.
In your css:
*,*:after,*:before { box-sizing: border-box; }
You can read about box-sizing following this link: http://www.paulirish.com/2012/box-sizing-border-box-ftw/
The problem is that you are telling the program to take up 100% of the pagewidth. If you reduce the two widths to 70% and 20-25%, the sidebar will float right, adjacent to the main content body.
Related
I want to align divs side by side but the padding doesn't let the divs to align side by side and I'm not allowed to remove padding or change anything. just need to add a property and i don't know what property I should add.
Here's the code:
body {
padding: 30px;
}
section {
background: lightgreen;
width: 75%;
float: left;
}
article {
background: white;
margin: 0 0 1rem 0;
}
aside {
background: pink;
width: 25%;
float: right;
}
header,
article,
section,
.module {
padding: 1rem;
}
<section>
<article>
<h2>Title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo
molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab
doloremque accusamus iusto aliquam facilis sapiente!
</p>
</article>
<article>
<h2>Title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo
molestias ex officia eligendi reiciendis fuga magnam? Ullam ut ab
doloremque accusamus iusto aliquam facilis sapiente!
</p>
</article>
</section>
<aside>
<div className="module">
<h3>Module</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio rem
ab delectus fugit repellendus perspiciatis dolor consequuntur
tenetur voluptatem a vitae odit aspernatur? Voluptas quisquam
corporis nostrum aspernatur aliquid harum saepe ab pariatur veniam
iste ipsam alias nemo voluptatibus doloribus.
</p>
</div>
</aside>
box-sizing CSS will fix this issue.
Add default box-sizing property to border-box
* {
box-sizing: border-box;
}
I have this green line down the middle of the page, how can I make it so that each section appears on the left then the right, for example section 1 at the top and to the left, section2 on the right hand side and a little lower than the next one.
So on so forth
#line {
height: 500px;
width: 5px;
border: 1px solid green;
background: green;
position: relative;
left: 50%;
}
<div class='about'>
<h2>About</h2>
<p>A little journey throguh my life/career</p>
<div class='timeline'>
<div id='line'></div>
<div id='section1'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section2'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section3'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section4'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section5'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
</div>
</div>
Generating the line as a separate element is just going to cause you problems giving it the right height.
Make the line a border, and use the odd or even position of the div to design which side to push it to and which side to draw the line on.
.timeline > div {
overflow: hidden;
margin: 0;
padding: 0;
}
.timeline > div:nth-child(odd) {
margin-right: calc(50% - 3px);
border-right: 5px solid green;
}
.timeline > div:nth-child(even) {
margin-left: calc(50% - 3px);
border-left: 5px solid green;
}
<div class='about'>
<h2>About</h2>
<p>A little journey throguh my life/career</p>
<div class='timeline'>
<div id='section1'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section2'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section3'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section4'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
<div id='section5'>
<h3>xx.xx.xxxx</h3>
<h3>Timeline Section Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque voluptatum quis perferendis consectetur distinctio sequi et laborum modi mollitia iste eum doloribus vel, ea eos, molestias explicabo cumque ut, assumenda.</p>
</div>
</div>
</div>
Try:
#section1,
#section3,
#section5{
float: left;
clear: both;
}
#section2,
#section4{
float: right;
clear: both;
}
Without changing the HTML structure, you can do it like this:
1) Add a class to the sections, something like .section.
<div class="section" id='section1'>
...
</div>
<div class="section" id='section2'>
...
</div>
<div class="section" id='section3'>
...
</div>
...
2) Then, change the relative position to absolute position for the line element, so it will be absolutely positioned in the middle.
#line {
height: 500px;
width: 5px;
border: 1px solid green;
background: green;
position: absolute;
left: 50%;
}
3) Finally, make each section 50% of the total width and use nth-of-type() selector to make it alternating from left to right using a margin-left for the sections that will be on the right side.
.timeline .section:nth-of-type(2n) {
margin-left: 50%;
}
.section {
width: 50%;
}
If you want to make each section a little lower than the previous one, you can add some negative margin, which is a little bit hacky, but can work well in this case.
The first section doesn't need it. The selector is number 2 because it is the second child, not the first. The first is the about div element.
.section {
margin-top: -50px;
}
.timeline .section:nth-of-type(2) {
margin-top: 0;
}
Footer is on right place but the columns in section are overlapping the footer
.columns {
float:left;
width: 22%;
height: 30%;
margin-left:8%;
}
Instead of float:left; I have used display:inline-block; but issue
not resolved this problem is occurring when website displayed on
mobile. When viewed on desktop it's working fine.
Try adding this to your CSS
box-sizing: border-box;
.container {
background: #f4f4f4;
padding: 5%;
margin: 5%;
}
.column1 {
background: #b40404;
padding: 5%;
color: #fff;
}
.column2 {
background: #000;
padding: 5%;
color: #fff;
}
.column3 {
background: #b40404;
padding: 5%;
color: #fff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="column1">
This is column 1<br><br> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloribus vero labore obcaecati illum reprehenderit incidunt consequatur quidem, id repellendus impedit, quaerat, mollitia ea culpa sint? Totam sunt omnis quis
eaque.
</div>
</div>
<div class="col-md-4">
<div class="column2">
This is column 2<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium mollitia, incidunt accusantium iure eius suscipit fugit tempore veniam deleniti, nulla dolore repudiandae voluptas, eaque architecto ratione recusandae
consectetur officia. Saepe.
</div>
</div>
<div class="col-md-4">
<div class="column3">
This is column 3<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis vitae nulla, beatae tenetur ea eaque obcaecati perspiciatis, architecto nemo culpa id non facilis distinctio aliquam. Accusamus voluptatum mollitia perferendis
libero.
</div>
</div>
</div>
</div>
you can use Bootstrap. Use the class container then row and define columns inside it. Like this:
let mymap = L.map('map').setView([54.5, -2], 6);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoidHRtdCIsImEiOiJjajhqeWhjOW8wN2JvMndwbTlqaTV0YjhhIn0.rlysm052tK3vDdZSSg-wQg'
}).addTo(mymap);
*{
padding: 0;
margin: 0;
}
html, body{
height: 100%;
}
.map-container{
display: flex;
}
/*#map {*/
/* //height: 100%;*/
/* //width: 100%;*/
/* position: absolute;*/
/* top: 0;*/
/* bottom: 0;*/
/* left: 0;*/
/* right: 0;*/
/*}*/
.map{
border: 1px solid green;
}
.info-block{
background: white;
width: 400px;
}
.info-block__inner{
overflow: scroll;
height: 100%;
}
.content_container{
padding: 0 20px 20px 20px;
}
.content{
margin-top: 30px;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.2.0/dist/leaflet.css" integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin="" />
<div class='map-container'>
<div id="map" class="map flex-element"></div>
<div class="info-block flex-element">
<div class="info-block__inner">
<div class="content_container">
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
</div>
</div>
</div>
</div>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet#1.2.0/dist/leaflet.js" integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" crossorigin=""></script>
I have a plunker here - https://plnkr.co/edit/RnJBeUaXcQtOneIn4jwM?p=preview
I'm trying to create a layout like this - https://plnkr.co/edit/PvszkAJCwFK9FhftEwTA?p=preview
I need the full page split into two columns one fixed with and the other the rest of the with of the page and containing the map.
Is it possbile to do this with flex box.
.map-container{
display: flex;
}
You can accomplish that with these steps:
Give map-container a height, height: 100%;
Add flex-grow: 1 to map, and it will take the avail space left (and order: 1 to move it to the right side)
Move overflow: scroll to info-block (I changed it to auto and also removed the info-block__inner as it appeared it was only there for the scroll)
Instead of adding order: 1 to map, you can of course move its markup after the info-block.
Updated plnkr
Stack snippet
let mymap = L.map('map').setView([54.5, -2], 6);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoidHRtdCIsImEiOiJjajhqeWhjOW8wN2JvMndwbTlqaTV0YjhhIn0.rlysm052tK3vDdZSSg-wQg'
}).addTo(mymap);
*{
padding: 0;
margin: 0;
}
html, body{
height: 100%;
}
.map-container{
display: flex;
height: 100%;
}
.map{
border: 1px solid green;
flex-grow: 1;
order: 1;
}
.info-block{
background: white;
width: 400px;
overflow: auto;
}
.content_container{
padding: 0 20px 20px 20px;
}
.content{
margin-top: 30px;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet#1.2.0/dist/leaflet.css" integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin="" />
<div class='map-container'>
<div id="map" class="map flex-element"></div>
<div class="info-block flex-element">
<div class="content_container">
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam explicabo incidunt minus necessitatibus nisi quo totam. Assumenda, consequatur cupiditate dolorem esse eum fugiat, fugit minus nam natus nesciunt optio vel.</p>
</div>
</div>
</div>
</div>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet#1.2.0/dist/leaflet.js" integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" crossorigin=""></script>
You could do something like this:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}
.parent {
display: flex; /* displays children inline */
}
.parent > .fixed {
width: 400px; /* adjust to your needs */
height: 200px; /* for presentation */
background: Teal;
}
.parent > .map {
flex: 1; /* takes all the remaining space */
height: 200px; /* for presentation */
background: Aqua;
}
#media screen and (max-width: 568px) { /* adjust to your needs */
.parent {
flex-direction: column; /* stacks children vertically */
}
.parent > .fixed {
width: 100%; /* makes it responsive */
}
}
<div class="parent">
<div class="fixed">CONTENT</div>
<div class="map">MAP</div>
</div>
CODEPEN
How can I align my paragraphs between columns when my h1s vary in size? caveat I have no control over the size of headers and therefore cannot add a static height.
Align to the crosshairs.
HTML:
<div class="paddingBlock">
<h1>Align the paragraphs to dynamic height h1s</h1>
<p>How do I make sure the paragraphs align w/o a fixed height on headers ?</p>
<div class="eqWrap">
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium numquam quibusdam quis, deleniti placeat quas vitae ex </h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem nesciunt aliquam magni corporis dolor, assumenda similique nisi doloremque repudiandae, consequatur, reprehenderit. Explicabo dolorum consequatur quasi consequuntur, qui adipisci saepe ipsam!</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
</div>
</div>
CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
font-family: sans-serif;
line-height: 1.4;
}
h1 {
font-size: 150%;
}
p {
margin-bottom: 10px;
}
.eqWrap {
display: flex;
}
.eq {
width: 50%;
padding: 10px;
}
.eq:nth-child(1) {
background: papayawhip;
}
.eq:nth-child(2) {
background: maroon;
}
One thing you can try is to make your content boxes (.eq) flex containers, then use auto margins to pin the paragraphs to the bottom:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
height: 100%;
width: 100%;
}
body {
font-family: sans-serif;
line-height: 1.4;
}
h1 {
font-size: 150%;
}
.eqWrap {
display: flex;
}
.eq {
width: 50%;
padding: 10px;
display: flex; /* NEW */
flex-direction: column; /* NEW */
}
p {
margin-top: auto; /* NEW */
margin-bottom: 10px;
}
<div class="paddingBlock">
<h1>Align the paragraphs to dynamic height h1s</h1>
<p>How do I make sure the paragraphs align w/o a fixed height on headers ?</p>
<div class="eqWrap">
<div class="eq">
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium numquam quibusdam quis, deleniti placeat quas vitae ex </h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam harum commodi impedit.</p>
</div>
<div class="eq">
<h1>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem nesciunt aliquam magni corporis dolor, assumenda similique nisi doloremque repudiandae, consequatur, reprehenderit. Explicabo dolorum consequatur quasi consequuntur, qui adipisci saepe ipsam!</h1>
<p>Align these paragraphs. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime aliquam inventore doloribus debitis id facere exercitationem, voluptate necessitatibus consequuntur, delectus et nisi eaque reprehenderit natus assumenda, ipsam
harum commodi impedit.</p>
</div>`
</div>
Revised Codepen
Depending on the size of each paragraph, and where you want your h1 aligned, you may need to adjust the auto margins. Here are some examples: Methods for Aligning Flex Items