Read More in PURE CSS - html

Trying to implement a CSS read more code using ONLY CSS with NO JavaScript involved. Here is the html:
.has-read-more {
position: relative;
width: 300px;
}
.has-read-more div {
height: 160px;
overflow: hidden;
}
.show-more {
position: absolute;
bottom: 10px;
width: 140%;
text-align: center;
cursor: pointer;
margin: 0;
margin-left: -20%;
}
.show-more:after {
content: "read more";
background-image: linear-gradient(to bottom, transparent, white);
padding-bottom: 10px;
display: block;
font-weight: bold;
color: black;
}
.show-more span {
background: white
}
input[type=checkbox]:checked {
display: none;
}
input[type=checkbox]:checked+div {
height: auto;
}
<div class="has-read-more">
<input type="checkbox" class="show-more">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet ornare odio, at cursus nisi. Suspendisse sodales ante mollis posuere finibus. Sed erat nibh, efficitur vitae venenatis sit amet, ornare et ligula. Suspendisse hendrerit nulla
quam, at hendrerit justo lacinia quis. Nunc nec dui in enim suscipit egestas et ut augue.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet ornare odio, at cursus nisi. Suspendisse sodales ante mollis posuere finibus. Sed erat nibh, efficitur vitae venenatis sit amet, ornare et ligula. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet ornare odio, at cursus nisi. Suspendisse sodales ante mollis posuere finibus. Sed erat nibh, efficitur vitae venenatis sit amet, ornare et ligula. Suspendisse hendrerit nulla
quam, at hendrerit justo lacinia quis. Nunc nec dui in enim suscipit egestas et ut augue.</p>
<p>Sed erat nibh, efficitur vitae venenatis sit amet, ornare et ligula. Suspendisse hendrerit nulla quam, at hendrerit justo lacinia quis. Nunc nec dui in enim suscipit egestas et ut augue.</p>
</div>
</div>
It all works apart from the checkbox appearing and not being replaced by read more text (which has its own background).
I have read other similar stack threads including this one: How to implement Read more / Read less in pure CSS but not looking to implement one that has read more/read less as that has.
The one I am working with works apart from that last bit. I must be a bit stupid as I just cannot seem to figure out why the checkbox is not replaced with the text.
It needs to be a purse CSS solution and not one based on JS. I have tried using a label but it gets appended to the beginning of the text box and not inline with the checkbox.
What do I seem to be doing wrong?

Related

Sticky navbar disappears on scroll

How can I make the sticky navbar stick to top of the page even after I provide a static height on sections below? Now when I scroll to the point of test-section then the nav disappears. How can I avoid this?
.header {
position: sticky;
top: 0;
z-index: 100;
height: 50px;
background: blue;
}
.test-section {
height: 300px;
background: red;
}
<div>
<div class="header">
hi navbar
</div>
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor tellus. Fusce laoreet nibh at nisl iaculis sollicitudin. Nullam dapibus, est vitae aliquet consectetur, velit ipsum vestibulum ante, et hendrerit enim erat non odio. Nullam sit amet nisi dictum, suscipit diam nec, pellentesque urna. Quisque semper turpis vitae suscipit eleifend. Mauris sed nisl at eros tristique accumsan vitae nec libero. Cras et laoreet mauris, eget posuere ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor tellus. Fusce laoreet nibh at nisl iaculis sollicitudin. Nullam dapibus, est vitae aliquet consectetur, velit ipsum vestibulum ante, et hendrerit enim erat non odio. Nullam sit amet nisi dictum, suscipit diam nec, pellentesque utur, ve
</p>
</div>
<div class="test-section">
<img src="https://commonslibrary.parliament.uk/content/uploads/2018/02/The_City_London-scaled.jpg">
</div>
Use "position: fixed" instead on the class header
Changing from position: sticky; to position: fixed; and also adding width: 100%; to your .header class seems to get the result your looking for
.header {
position: fixed;
top: 0;
z-index: 100;
height: 50px;
width:100%;
background: blue;
}
.test-section {
height: 300px;
background: red;
}
<div>
<div class="header">
hi navbar
</div>
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor tellus. Fusce laoreet nibh at nisl iaculis sollicitudin. Nullam dapibus, est vitae aliquet consectetur, velit ipsum vestibulum ante, et hendrerit enim erat non odio. Nullam sit amet nisi dictum, suscipit diam nec, pellentesque urna. Quisque semper turpis vitae suscipit eleifend. Mauris sed nisl at eros tristique accumsan vitae nec libero. Cras et laoreet mauris, eget posuere ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et dolor tellus. Fusce laoreet nibh at nisl iaculis sollicitudin. Nullam dapibus, est vitae aliquet consectetur, velit ipsum vestibulum ante, et hendrerit enim erat non odio. Nullam sit amet nisi dictum, suscipit diam nec, pellentesque utur, ve
</p>
</div>
<div class="test-section">
<img src="https://commonslibrary.parliament.uk/content/uploads/2018/02/The_City_London-scaled.jpg">
</div>
.header {
position: fixed;
top: 0;
z-index: 100;
height: 50px;
background: blue;
}

How do I make my side column extend all the way to the end?

For my website, I can't get my side column to extend all the way to the end of the body column without giving it a fixed max height (it's supposed to adjust according to the length of the body, which is altered either by the amount of words/content the body has and/or the wrapping of the body in a smaller screen). Please keep in mind that I have a footer at the bottom that is supposed to take up the entire width of the screen so I can't do something that makes the side column longer than anything and keep everything else on the body column.
Here is my example: https://jsfiddle.net/r7g20fvk/
Here is the code:
<style>
.sidebar_container {
float: right;
width: 70%;
max-width: 230px;
margin: 0px 20px 20px 0;
min-width: 300px;
/*I can add a min-height until the side column is long enough to reach the entire bottom rather than end after the content runs out, but it doesn't adjust accordingly (to the length of the body column, whether the screen makes the body longer or the amount of text makes the body longer)*/
}
.left {
overflow: hidden width: 70%;
line-height: 2;
font-size: 18px;
}
</style>
<div class="left">
<h2>Home</h2>
</div>
<div>
<div class="sidebar_container" style="float: right;">
<div class="sidebar">
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</div>
<div class="sidebar">
<h2>Post 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus.. Read More</p>
</div>
<div class="sidebar">
<h2>Post 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem
neque, vel mattis arcu semper in...Read More</p>
</div>
<!--close sidebar-->
</div>
<div class="left">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem
neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu enim a mauris ullamcorper
tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris. Nunc molestie libero
quis odio tristique euismod.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat
id. Donec vehicula lorem neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu
enim a mauris ullamcorper tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris.
Nunc molestie libero quis odio tristique euismod.</p>
</div>
</div>
Is there a way to make it adjust accordingly? Perhaps make the side column's width be a percentage of the entire width of the screen so it isn't a fixed width when viewing at a smaller screen size, or make it completely disappear or something when in super-small mobile screens. I'm trying to make it mobile friendly and adjust its height based off of the bottom.
Do you think making a table (with two columns, one as body and one on the side) would be a better way of making the webpage mobile friendly and automatically adjust to the wrapping of content? Or is there a better way using div grouping?
Something like this?: https://jsfiddle.net/xcy9s64g/
The trick is to position the right child div absolutely:
position: absolute;
right: 0;
top: 0;
And, of course, positioning the parent container as relative, to provide a reference point for the absolute positioning. Then, you can use percentages for the children.
#container {
position: relative;
width: 100%;
}
Do you think making a table (with two columns, one as body and one on
the side) would be a better way of making the webpage mobile friendly
and automatically adjust to the wrapping of content? Or is there a
better way using div grouping?
Using a table for layout is a bad idea. Use flexbox instead if you want to try something different.
I think you should use flexbox, hope it solves your problem.
Please check this codepen solution
body {
background: #eee;
}
section {
padding: 10px;
}
h2 {
margin: 0;
padding: 0;
display: inline-block;
}
.wrapper {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.main-container {
background: #fff;
margin: 10px;
display: flex;
/*flex-wrap: wrap;*/
/*justify-content: space-between;*/
}
.left-container {
flex: 3 3 70%;
background-color: #fff;
}
.right-container {
flex: 1 1 30%;
flex-direction: column;
background-color: #ccc;
}
#media screen and (max-width:768px) {
.main-container {
display: flex;
flex-wrap: wrap;
}
.left-container {
flex: 0 1 100%;
order: 1;
/*change the order of the blocks for smaller screens as you like */
background-color: #fff;
}
.right-container {
flex: 0 1 100%;
order: 2;
/*change the order of the blocks for smaller screens as you like */
background-color: #ccc;
}
}
<body>
<div class="wrapper">
<div class="main-container">
<section class="left-container">
<h2>Home</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat id. Donec vehicula lorem neque,
vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eu enim a mauris ullamcorper tincidunt
ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus in mauris. Nunc molestie libero quis odio
tristique euismod.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus, in iaculis neque aliquam vitae. Ut mattis aliquet mi, eu cursus est placerat
id. Donec vehicula lorem neque, vel mattis arcu semper in. Aenean venenatis pulvinar sagittis. In eget congue sapien, in semper ligula. Curabitur sagittis mi a lacinia fermentum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
eu enim a mauris ullamcorper tincidunt ac vel erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus lacinia, velit eu eleifend interdum, lacus velit maximus nisi, ut feugiat metus metus
in mauris. Nunc molestie libero quis odio tristique euismod.
</p>
</section>
<section class="right-container">
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
<article>
<h2>Post 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla vulputate mauris fermentum laoreet. Suspendisse lacinia tincidunt lectus...
Read More
</p>
</article>
</section>
</div>
</div>
</body>

How can I align the paragraphs in this div with pure CSS?

JSfiddle
I have a situation where I would like to float a small image to the left of text within a div. I don't want the text to wrap under the image, and some research led me to add the overflow:hidden; property on <p>. While this makes the paragraph next to the image behave as I want, the following paragraphs are then not aligned with the first. Is there a nice way to get all paragraphs aligned? I tried display: table-row;, but this affects other elements on the page (and I have read up on why this is the case).
I need to work within the constraints present in the JSFiddle (i.e., can't really modify html), and cross-browser support is a priority.
.header {
color: white;
background-color: red;
padding: 15px;
}
.header p {
overflow: hidden;
}
.img {
background-color: green;
width: 45px;
height: 45px;
float: left;
}
<div class="header">
<div class="img">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut
pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
Use a margin-left on the paragraphs that is the width of the image + the margin/space you want between the image and paragraph. Then you have no need for the overflow.
.header {
color: white;
background-color: red;
padding: 15px;
}
.header p {
margin: 0 0 1em 55px;
}
.img {
background-color: green;
width: 45px;
height: 45px;
float: left;
}
<div class="header">
<div class="img">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut
pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
So, you should set a div for the whole thing, one for the image and one for the text.
I don't know if that's what you're looking for, but here you go.
.container {
width: 400px;
height: auto;
}
.imageDiv {
max-width: 200px;
height: auto;
float: left;
}
.image {
max-width: 100%;
}
.text {
max-width: 200px;
min-width: 200px;
text-align: center;
float: left;
}
<div class="container">
<div class="text">
<p>
Some text.
</p>
</div>
<div class="imageDiv">
<img class="image" src="http://nexceris.com/wp-content/uploads/2014/04/bokeh-cover-bg.jpg">
</div>
</div>
Code the one div for other content and manage that two inside div like you want.
<div class="header">
<div class="img">
</div>
<div class="other">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet turpis vel diam elementum imperdiet eu id ex. Nam dictum blandit ullamcorper. Nam ultrices risus neque, eget finibus dolor suscipit a. Fusce lobortis dictum odio sit amet tempus. Ut pretium augue vitae neque finibus, quis ornare dolor fermentum.
</p>
<p>
Maecenas suscipit risus tellus, posuere commodo diam egestas ut. Suspendisse ex enim, ullamcorper et faucibus nec, viverra vel leo. Aliquam venenatis mi metus, et tincidunt nulla laoreet quis. Donec sodales nunc ut finibus cursus.
</p>
</div>
</div>

Can you vertically align the text of a paragraph that also contains a floated image?

Here is what I am trying to achieve:
Given the following markup:
p > img {
float: left;
margin: 1em;
}
<p>
<img src="https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quam velit, vulputate eu pharetra nec, mattis ac neque. Duis vulputate commodo lectus, ac blandit elit tincidunt id. Sed rhoncus, tortor sed eleifend tristique, tortor mauris molestie elit, et lacinia ipsum quam nec dui. Quisque nec mauris sit amet elit iaculis pretium sit amet quis magna. Aenean velit odio,
</p>
My largest hurdle is that I cannot change this markup. So, my question revolves around this specific scenario: Is it possible to vertically align the text inside of an element which also contains a floated image?
You can do this with Flexbox
p {
display: flex;
align-items: center;
}
img {
flex: 0 0 200px;
margin: 10px;
}
<p>
<img src="http://placehold.it/200x200">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quam velit, vulputate eu pharetra nec, mattis ac neque. Duis vulputate commodo lectus, ac blandit elit tincidunt id. Sed rhoncus, tortor sed eleifend tristique, tortor mauris molestie elit, et lacinia ipsum quam nec dui. Quisque nec mauris sit amet elit iaculis pretium sit amet quis magna. Aenean velit odio,
</p>
As an alternative to the flex method you could change the position property on the img element and use padding and calc() for some good text positioning.
DEMO
Of course, YMMV depending on whether or not img elements will have standard sizing and how long your text will be.
p > img {
position: absolute;
top: 0;
left: 0;
margin: 1em;
}
p {
position: relative;
padding-left: calc(300px + 1.25em);
padding-top: 150px;
}
<p>
<img src="https://placeholdit.imgix.net/~text?txtsize=28&txt=300%C3%97300&w=300&h=300">
A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine.
</p>

double arrow in beginning and end of paragraph

I want to have double arrow on a paragraph. Just like the image below.
How can I make this through CSS?
CSS CODE
.people-wrap p {
position: relative;
display: inline-block;
float: none;
padding-bottom: 15px;
font-family:'Droid Serif', serif;
font-size:17px !important;
font-style:italic;
}
You could use two pseudo elements for this:
.people-wrap p:before {
content: "«";
padding-right: .5em;
}
.people-wrap p:after {
content: "»";
padding-left: .5em;
}
<div class="people-wrap">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula sapien eu ullamcorper vulputate. Nunc quis viverra nisi. Integer quis neque sit amet dolor lobortis gravida. Duis eget lacinia ipsum, quis malesuada est. Mauris vitae ultricies leo. Donec ac orci non justo consectetur aliquet. Aenean semper mi ut dui posuere iaculis non at magna. Maecenas sit amet lacus ut nunc commodo consequat sed sit amet purus. In cursus ac leo sed convallis. Curabitur efficitur eget mi sit amet maximus. Proin tincidunt nulla vitae metus viverra dignissim. Curabitur gravida, turpis id auctor facilisis, nulla dolor lacinia risus, sed vulputate enim lectus et diam.</p>
</div>