Create a sticky sidebar in html for a handbook - html

I will program a sticky sidebar inside a grid layout. I have made a screenshot
from my fist try to build this html page. I don't want use javascript. In the
css file I have used position: fixed. It should be positoin: sticky. How do I get
the sticky sidebar into the grid? If I klick on the link on the right side the the left side should move to the top.
Here the html page
.section-t {
margin-top: 10rem;
margin-bottom: 6rem;
min-height: calc(100vh - 30rem);
}
.section-t .container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1rem;
}
.sidebar {
position: fixed;
top: 10rem;
right: 3rem;
width: 450px;
}
.item12 {
grid-column: 1 / span 2;
}
.card {
background-color: var(--white-color);
border: solid 1px #757575;
border-radius: 0.4rem;
padding: 1em;
}
<section class="section-t">
<div class="container">
<div class="item12 card">
<h1>Handbook</h1>
<hr />
<h3>Introduction</h3>
<p>
Hello Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
</p>
</div>
<div class="item12 card">
<h1>Help Pages</h1>
<hr />
<h3>General</h3>
<p>
Hello Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
</p>
</div>
<div>
<div class="card sidebar">
<h1>Table of contents</h1>
<hr />
<div>
<fieldset>
<ul>
<li>
Introduction
</li>
<li>
How to create a strong password
</li>
</ul>
</fieldset>
</div>
</div>
</div>
</div>
</section>

Related

Image Div next to Text Div + Responisve

So I'm trying to create a template where one div is a picture and another one is a text with background. Now i want to make this template responsive, so that the text is going beneath the picture at a certain px width. Looking through stackoverflow i have seen countless posts that say you should use a flexbox. I tried, but i cant get it quite right.
So on Desktop it should look like this: https://imgur.com/a/XfJDwKL and on a Smartphone it should jump over here https://imgur.com/a/8KaKJxF
I need to have the margin to the sides, at least on the desktop version. Now my problem is, that my picture is having no limitations on my site and is getting too big, that an automatic switch to rows is happening(as i understand it).
My code is here : https://jsfiddle.net/wqesp83a/
.container {
display: inline-flex;
border: 1px solid black;
margin: 5%;
width: 90%;
}
.flex-direction {
flex-direction: row;
}
.div1 {
display: flex;
border-right: 1px solid black;
}
h {
color: #90bd49;
font-size: 30px;
}
p {
color: #333333;
font-size: 16px;
}
.div2 {
display: flex;
background-color: #fff;
max-width: 50%;
padding: 1%;
background-color: #e3e3e3;
}
span {
font-size: 16px;
text-align: left;
}
#media only screen and (min-width: 0px) and (max-width: 500px) {
.flex-direction {
flex-direction: column;
}
.div1 {
max-width: 100%;
border-right: none;
border-bottom: 1px solid black;
}
.div2 {
max-width: 100%;
}
.container {
margin: 0%;
}
<div class="container flex-direction">
<div class="div1"><span><img alt="Fotoabzüge" src="https://s3.eu-central-1.amazonaws.com//pbx-sw-profotolab/media/79/95/4c/1673964627/bild4_(1).jpg" width="100%" height="100%" /></span></div>
<div class="div2"><span><h>Lorem ipsum</h> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.</p> </span></div>
</div>
I tried to limit the width and height of the divs and the picture but either it doesnt help or im breaking the whole thing even more. If someone could help me see my mistakes here, i would be very thankful.
grid to the rescue:
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr))
will create a grid column for each child of the container, as long as they can stretch to 400px width. When there's not enough space for the grid items to be 400px in width, they will wrap into a single column. Just swap the px value to whatever you want.
grid-auto-rows: 1fr will let the two columns have equal height.
.container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
grid-auto-rows: 1fr;
border: 1px solid black;
margin: 5%;
width: 90%;
}
.flex-direction {
flex-direction: row;
}
.div1 {
display: flex;
border-right: 1px solid black;
}
h {
color: #90bd49;
font-size: 30px;
}
p {
color: #333333;
font-size: 16px;
}
.div2 {
display: flex;
background-color: #fff;
/* max-width: 50%; */
padding: 1%;
background-color: #e3e3e3;
}
span {
font-size: 16px;
text-align: left;
}
#media only screen and (min-width: 0px) and (max-width: 500px) {
.flex-direction {
flex-direction: column;
}
.div1 {
max-width: 100%;
border-right: none;
border-bottom: 1px solid black;
}
.div2 {
max-width: 100%;
}
.container {
margin: 0%;
}
<div class="container flex-direction">
<div class="div1"><span><img alt="Fotoabzüge" src="https://s3.eu-central-1.amazonaws.com//pbx-sw-profotolab/media/79/95/4c/1673964627/bild4_(1).jpg" width="100%" height="100%" /></span></div>
<div class="div2"><span><h>Lorem ipsum</h> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud.</p> </span></div>
</div>

use css to move a div into the row above it

My code has 3 divs in a row (gallery, sidebar, description). The HTML needs to remain unchanged, but I need to use CSS to get the .description up under the .sidebar (beside the .gallery) instead of beneath the .gallery.
I want to move that div like so
Code:
<div class="product">
<div class="gallery">
<img src="https://via.placeholder.com/300" alt="item" />
</div>
<div class="sidebar">
<h3>
Sidebar
</h3>
<p>
Product price, etc.
</p>
</div>
<div class="description">
<h3>
Details
</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed eros sem. Aliquam erat volutpat. Phasellus auctor lorem dolor, vitae egestas neque vestibulum sed. Proin sapien purus, faucibus ut elementum eget, consequat sed arcu. Morbi nisl libero,
molestie eget ligula quis, feugiat iaculis felis. Donec condimentum, felis eu sodales interdum, ex purus convallis augue, quis sollicitudin nibh ex vel lorem. Sed eget semper ipsum, vel dictum lorem. Proin ornare massa elit, non aliquam erat ultricies
at.
</p>
</div>
</div>
.product {
box-sizing: border-box;
position: static;
}
.gallery {
box-sizing: border-box;
float: left;
position: relative;
}
.sidebar {
box-sizing: border-box;
float: right;
position: static;
}
.description {
box-sizing: border-box;
clear: left;
float: left;
position: static;
}
If you're willing to use floats, set the width for your elements. Here's fiddle http://jsfiddle.net/y6g4p7u8/1/
I've set the background color for visual display.
.product {
box-sizing: border-box;
background: green;
}
.product:before,
.product:after {
content: " ";
display: table;
}
.product:after {
clear: both;
}
.gallery {
box-sizing: border-box;
width: 35%;
float: left;
background: red;
}
.sidebar {
box-sizing: border-box;
float: left;
width: 65%;
background: lightblue;
}
.description {
box-sizing: border-box;
float: left;
width: 65%;
background: yellow;
}
I suggest you to use a div to wrap both .sidebar and .description.
Then apply display: flex on parent .product.
HTML
<div class="column-wrap">
<div class="sidebar">..</div>
<div class="description">...</div>
</div>
CSS
.product{
display: flex
}
https://jsfiddle.net/blackcityhenry/n9qgvjh6/
css grid would be the easiest, and browser support is now pretty good.
https://css-tricks.com/snippets/css/complete-guide-grid/
https://caniuse.com/#search=grid
If I understand what you are asking correctly you could define your grid template area and then assign your elements to where they need to sit.
From the top of my head it would be something like this, check out the link to css-tricks.
Here is a pen demonstrating https://codepen.io/TomCheckley/pen/dQJQBv
<div class="product">
<div class="gallery">
<img src="https://lorempixel.com/400/200/cats/1" alt="">
</div>
<aside class="sidebar">
<h2>Sidebar</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</aside>
<div class="description">
<h2>Description</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
</div>
</div>
img {
width: 100%;
height: auto;
}
h2 {
margin-top: 0;
}
p:last-child {
margin-bottom: 0;
}
.product {
max-width: 90%;
margin: auto;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-gap: 1.5rem;
grid-template-areas: 'gallery gallery sidebar' 'gallery gallery description';
}
.product > * {
background-color: #c3cece;
padding: 1.5rem;
}
.gallery {
grid-area: gallery;
}
.sidebar {
grid-area: sidebar;
}
.description {
grid-area: description;
}
Well, actually grid maybe not the easiest if you've not used it! But it will give you the most flexible layout options without changing your markdown. It's definitely worth playing around with as browser support is getting near total (apart from IE). You can always progressively enhance as well - float is then overridden by flex and if you put grid after flex in the cascade the browser will use it if it understands it and use flex if it doesn't.

CSS pseudo element blockquote

I need some help...
I am trying to style a blockquote elemet:
<div class="container-fluid testimonials padding">
<div class="row-fluid">
<div class="col-xs-12 col-sm-12 col-md-5 col-md-offset-2 col-lg-5 col-lg-offset-2">
<blockquote>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vul. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vul.
</blockquote>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
</div>
</div>
</div>
Styling I have so far:
.padding {padding-top:2%;padding-bottom:2%;}
blockquote {padding:60px 30px 40px 95px;border:none;position:relative;font-family: 'Comfortaa', cursive;}
blockquote::before{
content: "\201C";
font-family: 'Comfortaa', cursive;
font-size: 180px;
font-weight: bold;
color: #999;
position: absolute;
left:20px;
top:-40px;
color:#b80072;
z-index: -1;
}
blockquote::after{
content: "\201D";
font-family: 'Comfortaa', cursive;
font-size: 180px;
font-weight: bold;
color: #999;
position: absolute;
right:5%;
bottom:-45%;
color:#b80072;
z-index: -1;
opacity:0.5;
width:90px;
}
#media (max-width: 510px) {
blockquote::after {bottom:-25%;}
}
The result is almost what I want to achieve.
The before pseudo element is styled correctly and the blockquote padding itself is fine.
The problem is styling the after pseudo element as. How do I get it to stick to the bottom right hand corner of the blockquote element?
Any help would be appreciated.
The reason the placement seems difficult is because of the huge default line height on the quote marks. You can get a bit more control of it by setting
blockquote::after {line-height: 0;}
... though it's not an ideal solution.

Margin-top not working on div

I'm so confused by why margin-top will not work. Here is my code:
HTML:
<div class="container-extended-blog">
<div class="offers-for-week">
<h1 class="title offers-for-this-week">offers for this week</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<img src="img/extended_blog_pic.jpg" alt="image of recipe">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</div><!-- /.offers-for-week -->
</div><!-- /.container-extended-blog -->
SCSS:
.container-extended-blog {
margin-top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
p {
font-family: $content-font;
color: $icon-font-color;
}
}
I have tried adding position: relative; which I find usually works whenever something like this happens, however I have no idea why this isn't working, and would really like to understand!
add position:absolute; to .container-extended-blog
.container-extended-blog {
top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
position:absolute;
}
OR
Change top: 200px; to margin-top: 200px;
.container-extended-blog {
margin-top: 200px;
margin-left: 300px;
background-color: $blue-ot;
width: 350px;
height: 450px;
overflow: hidden;
}
see fiddle at : http://jsfiddle.net/Q5xdf/

How do I make this nested div to show up on top right corner and make text wrap around it?

I am trying to set a nested div on the top right of its parent div and text to wrap around the nested div.
I really should understand how position, float and display work together.
Here is my sample:
CSS
.parentDiv {
width:295px;
border:1px solid black;
}
.parentDiv .childDiv1 {
width:36px;
border:1px solid black;
float:left;
}
.parentDiv .childDiv2 {
width:210px;
border:1px solid black;
float:left;
}
.parentDiv .childDiv3 {
width:44px;
right:0px;
top:0px;
border:1px solid gray;
position:relative;
float:right;
}
HTML
<div class="parentDiv">
<div class="childDiv1">
<img alt="adfasf" src="../img/image.gif">
</div>
<div class="childDiv2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
<div class="childDiv3"> <span>search here</span>
</div>
</div>
</div>
Live jsfiddle
Like this: jsFiddle. Make the child div appear first as a child of childDiv2 and keep the CSS as-is.
Move it inside .childDiv2
Demo here
CSS (no change):
.parentDiv { width:295px;border:1px solid black; }
.parentDiv .childDiv1 { width:36px;border:1px solid black;float:left; }
.parentDiv .childDiv2 { width:210px;border:1px solid black;float:left; }
.parentDiv .childDiv3 { width:44px;right:0px;top:0px;border:1px solid gray; position:relative; float:right; }
​
HTML
<div class="parentDiv">
<div class="childDiv2">
<div class="childDiv1">
<img alt="adfasf" src="../img/image.gif">
</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
<div class="childDiv3">
<span>search here</span>
</div>
</div>
</div>
Here is a simplified version:
<div class="childDiv2">
<div class="childDiv3">
<span>search here</span>
</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</div>
CSS:
.childDiv2 { width:210px;border:1px solid black;}
.childDiv3 { width:44px;right:0px;top:0px;border:1px solid gray;float:right }
Here's my jsFiddle solution
In addition to the fix, I removed the unnecessary CSS.
The reason for this issue is parsing order. HTML is parsed left-to-right, top-to-bottom. When you have element-A declared after element-B, element-A will naturally be parsed after element-B.
As others have noted, all that needed to be done was to move the paragraph of text so that it's declared after childDiv3. This will allow childDiv3 to reside on the first line of childDiv2 and float itself normally.
Additionally, I added a margin to childDiv1 and some padding to parentDiv to space things out a bit. Feel free to strip out or modify properties as you wish. I also added a .clear element before the closing tag of parentDiv so that it would properly wrap around its floated child elements, as you may have intended it to.