Is there any way to change theme with the help of scss - html

I want to change theme when uses click on change theme button dynamically.
When users click on a checkbox (checkbox is checked)
these commented theme has to be applied
/**
$theme1-background:white;
$theme1-font-color:black;
$theme1-btn-primary:rgba(243,241,0,0.1);
$theme1-btn-secondary:#2ab1e4;
**/
otherwise the default one has to be applied
I don't know any way to do it, but have seen this feature quite often
Here is complete codepen: https://codepen.io/eabangalore/pen/XPqoBK
$theme1-background:rgba(0,0,0,0.8);
$theme1-font-color:white;
$theme1-btn-primary:green;
$theme1-btn-secondary:orange;
//below setting has to be applied based on theme 2
/**
$theme1-background:white;
$theme1-font-color:black;
$theme1-btn-primary:rgba(243,241,0,0.1);
$theme1-btn-secondary:#2ab1e4;
**/
.main{
margin-top:34px;
background:$theme1-background;
border:1px solid orangered;
width:90%;
color:$theme1-font-color;
.btn-primary{
background:$theme1-btn-primary;
color:$theme1-font-color;
}
.btn-secondary{
background:$theme1-btn-secondary;
color:$theme1-font-color;
}
}
<label>change theme:<input type="checkbox"></label>
<div class="main">
<button class="btn-primary">button primary</button>
<button class="btn-secondary">button secondary</button>
<p>text color ------>>> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iure delectus officiis ea in deserunt blanditiis at, ratione recusandae asperiores pariatur perspiciatis voluptate accusantium aperiam, harum accusamus quis veritatis quisquam aliquid.</p>
</div>

You can easily restyle an entire page dynamically by doing two things:
First, create a duplicate stylesheet and add a body class selector such as body.other-theme to the beginning of every selector you want to change. So your two stylesheets might look like this:
/* main-theme.css */
#content {
background: white;
}
/* other-theme.css */
body.other-theme #content {
background: black;
}
Then when the user checks the checkbox, simply add the other-theme class to the body of the document. This will trigger all other-theme styles to display.
In each stylesheet, you can set the theme colors and other variables that will be specific to that theme.

Related

Align two elements on top of each other without a container with a width

I have two elements that I would like to be aligned in a column-like way. These elements also need to be floated to the right of the page. If I float the container containing these two elements to the right, they automatically align in a row-like way. My immediate thought is to specify a width of the container so that they will be forced to move downward. The issue with this is that the two elements are different widths.
<div style="float: right; width: 100px;">
<div style="width: 110px; height:50px; background-color: blue;">
Element 1
</div>
<div style="width: 60px; height:50px; background-color: red;
float:right;">
Element 2
</div>
</div>
paragraph text that will not flow into the bottom element because the container's width prevents it. Filler text.....
If the bottom element is not as wide as the top element, the width of the container makes it wider. This is an issue because I have other text / elements that I would like flow around these side elements, and it looks weird because of the whitespace created by the different in widths.
If I try something like making the parent absolute, as not to effect the other elements on the page, the children don't either.
How can I create elements that are floated in a container without the width of the container affecting the other elements on the page as well? Thanks, Levi
One approach is as below, taking advantage of display: contents comments in the code itself:
/* basic CSS reset to reduce all elements to the same
box-sizing, font, margin and padding: */
*,
::before,
::after {
box-sizing: border-box;
font: normal 1rem / 1.5 sans-serif;
margin: 0;
padding: 0;
}
/* a wrapping element to allow for some dynamic sizing of the
contents: */
main {
/* the width of the <main> element is 80vw (viewport-width units)
unless that is less than 30em (the minimum size it will be) or
unless that size exceeds 1000px (at which point it will take
a width of 1000px maximum): */
width: clamp(30em, 80vw, 1000px);
/* a margin of 1em on the top and bottom top-to-bottom languages: */
margin-block: 1em;
/* a margin of auto on the inline axis, left (start) and right (end)
in left-to-right languages, such as English: */
margin-inline: auto;
}
div.wrapper {
/* for those browsers that are yet to implement
logical properties: */
float: right;
/* equivalent to "float: right" in left-to-right
languages, such as English: */
float: inset-inline-end;
width: 100px;
/* effectively removes this element from the
layout, exposing its contents to the layout
engine: */
display: contents;
}
div.wrapper > div {
/* ensuring that the "display: contents" is
unset, which takes it back to the default
display model: */
display: unset;
/* for those browsers that are yet to implement
logical properties: */
float: right;
/* as above, equivalent to "float: right" in
left-to-right languages, such as English: */
float: inset-inline-end;
height: 50px;
/* forces each element to clear the float of its
siblings: */
clear: both;
/* to hide the overflowing text: */
overflow: hidden;
text-overflow: ellipsis;
}
.wrapper > div:first-child {
background-color: blue;
width: 110px;
}
.wrapper > div:last-child {
background-color: red;
width: 60px;
}
<main>
<div class="wrapper">
<div>
Element 1
</div>
<div>
Element 2
</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur perferendis corporis itaque, sequi quod commodi explicabo dolore, totam, libero architecto doloremque nisi illo iste quae ea, laboriosam reprehenderit nemo animi! Lorem ipsum dolor
sit amet, consectetur adipisicing elit. Quia reiciendis sapiente blanditiis provident ad ullam consequatur, temporibus ex accusamus est nihil voluptatum totam cupiditate. Ducimus sit deserunt nostrum, dolorem doloremque. Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Consectetur perferendis corporis itaque, sequi quod commodi explicabo dolore, totam, libero architecto doloremque nisi illo iste quae ea, laboriosam reprehenderit nemo animi! Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Quia reiciendis sapiente blanditiis provident ad ullam consequatur, temporibus ex accusamus est nihil voluptatum totam cupiditate. Ducimus sit deserunt nostrum, dolorem doloremque.</p>
</main>
JS Fiddle demo.
References:
CSS logical properties.
display.
float.
Bibliography:
Compatibility of CSS logical properties, from "Can I Use."

How do I change the color of the text-cursor in html/css?

I am currently new to HTML and CSS and do not have much knowledge about them. Recently, I came across a problem where my text-cursor is not visible when the background-color of a <div> element is darkish.
Here is an example:
<style>
.PreCode {
font-family: Georgia, 'Times New Roman', Times, serif;
font-size: initial;
color: rgb(28,26,26);
background-color: grey;
border: 1px solid black;
text-transform: capitalize;
font-weight: 100;
margin-top: 20px;
text-align: center;
padding: 10px;
}
</style>
Now when ever I try to focus the text written inside of a <div> element with this as the class my text cursor becomes transparent.
Is there any way to prevent this from happening? Is there a way to change the color of the text-cursor to the color of the cursor i.e red?
Here is the <div> code:
<div class="PreCode">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla necessitatibus dolorem suscipit. Quibusdam dolorem eos sunt voluptate neque, unde expedita, error modi, assumenda quisquam repudiandae iste provident rerum vel blanditiis.
</div>
The caret-color property is only supposed to apply to input elements and similar - elements that are intended to be user editable. So, if you apply is to a div (as here), you'll get unexpected results. (And, I suspect that you mean "invisible" rather than "transparent" - unless you actually see transparency being applied, but I suspect it's just that you can't see it against the dark background.)
Do you mean that you want the background colour of the highlighted text to be different from the default? In which case you need to set the background-color property for .PreCode::selection in your CSS.
Also, bear in mind that the way the cursor is rendered on screen depends on your browser and also your operating system. There are ways to set a custom cursor, but I don't think that's your problem here. The default cursor shapes and colours depend ultimately on the reader (i.e. your user's browser and OS). On my system, for example, the pointer is a black arrow with a white outline, and the text marker similarly has an outline. So, whatever background it's on, it remains visible.
It also depends what you mean by "cursor": the mouse pointer? The text-position marker? The actual cursor (the often-flashing vertical line that marks the text-input position)? Because the actual cursor will only be displayed in an editable element (as above), because it marks a text-input position and there isn't one of those at all if the text element doesn't accept user input.
you face that issue because you don't make changes on that line the caret-cursor property is used when you wanna make changes on any text, para, input, and etc.
Caret-Cursor : Set the color of the cursor in input elements.
if you wanna make your cursor color change in the div or see work or not you can add the contenteditable before the class then your code work properly and you also edit your text.
follow the code for the desired output.
<div contenteditable class="PreCode">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla necessitatibus dolorem suscipit. Quibusdam dolorem eos sunt voluptate neque, unde expedita, error modi, assumenda quisquam repudiandae iste provident rerum vel blanditiis.
now your code work properly if you want any help then ping me.
Thanks

Non-JS, CSS-only technique for show more/less text, for page with 'n' text elements

I'm creating a simply show more solution for a page where there are n text elements that need toggling between show and hide. n is dynamic and not fixed.
For the purposes of this question, I'm exploring non-JS, CSS-only solutions.
It's possible to achieve a show and hide toggle functionality for a single element via CSS (solution below). But how does one extend it to n elements? Would be great to get an illustrative, working answer.
How I would do it in a single text element case:
#textarea {
/* hide by default: */
display: none;
}
/* when the checkbox is checked, show the neighbouring #textarea element: */
#textAreaToggle:checked + #textarea {
display: block;
}
/* position the checkbox off-screen: */
input[type="checkbox"] {
position: absolute;
left: -1000px;
}
/* Aesthetics only, adjust to taste: */
label {
display: block;
}
/* when the checkbox is unchecked (its default state) show the text
'Show ' in the label element: */
#textAreaToggle + #textarea + label::before {
content: 'Show ';
}
/* when the checkbox is checked 'Hide ' in the label element; the
general-sibling combinator '~' is required for a bug in Chrome: */
#textAreaToggle:checked ~ #textarea + label::before {
content: 'Hide ';
}
<input id="textAreaToggle" type="checkbox" /><p id="textarea">This is hidden textarea, that needs to be shown</p><label for="textAreaToggle">textarea</label>
This single-case solution is based on this answer, and it's tried and tested. You can run the code snippet to see for yourself.
But I'm struggling to generalize it for n text elements on a single page (in a CSS-only setting), thus this question.
Why not simply use the details element?
[open] summary {
position: absolute;
bottom: -1.5em;
left: 0;
}
summary::before {
content: "...More";
}
[open] summary::before {
content: "Less";
}
details {
display: inline;
}
.more-text {
position: relative;
margin-bottom: 2em;
}
<div class="more-text">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit laborum nesciunt dolorem deleniti non magnam natus iure nobis quaerat amet commodi aspernatur,
<details>
<summary></summary>
ad, maiores possimus fugiat ipsum assumenda cum? Voluptas.
</details>
</div>
<div class="more-text">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit laborum nesciunt dolorem deleniti non magnam natus iure nobis quaerat amet commodi aspernatur,
<details>
<summary></summary>
ad, maiores possimus fugiat ipsum assumenda cum? Voluptas.
</details>
</div>
<div class="more-text">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit laborum nesciunt dolorem deleniti non magnam natus iure nobis quaerat amet commodi aspernatur,
<details>
<summary></summary>
ad, maiores possimus fugiat ipsum assumenda cum? Voluptas.
</details>
</div>
<div class="more-text">
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit laborum nesciunt dolorem deleniti non magnam natus iure nobis quaerat amet commodi aspernatur,
<details>
<summary></summary>
ad, maiores possimus fugiat ipsum assumenda cum? Voluptas.
</details>
</div>
If you need legacy browser support, here's a very small polyfill that comes without any dependencies:
https://github.com/rstacruz/details-polyfill
You want different toggles for different text. You can give them unique id's to work with and then aggregate all of them in the ~ selector. So
For #fortext(1) checked, we display #textarea(1)
For #fortext(2) checked, we display #textarea(2)
For #fortext(n) checked, we display #textarea(n)
p {
/* hide by default: */
display: none;
}
#fortext1:checked~#textarea1,
#fortext2:checked~#textarea2,
#fortext3:checked~#textarea3 {
display: block;
}
<input id="fortext1" type="checkbox" /><br>
<p id="textarea1">textarea1</p>
<input id="fortext2" type="checkbox" /><br>
<p id="textarea2">textarea2</p>
<input id="fortext3" type="checkbox" /><br>
<p id="textarea3">textarea3</p>
The general sibling selector selects the next sibling of the selector. Like this
selector ~ siblings to affect {
code goes here
}
You can understand this by the snippet below
.selector~p { /* this means that after the class selector, every p sibling will be colored red */
color: red
}
<p class="selector">Main Selector</p>
<p>P tag</p>
<span>span</span>
<span>span</span>
<span>span</span>
<p>P tag</p>
<p>P tag</p>
<span>span</span>
<p>P tag</p>
Here is a generic idea where the only requirement is to have a different wrapper per text.
I considered CSS grid to be able to put the label before in the DOM then change its position visually. I also made the label and the input on the same row/column having the input on the top to trigger the click. Then I simply create an overflow for the input so we don't see it.
.box {
display:grid;
overflow:hidden;
margin:10px;
}
.box span,input[type="checkbox"] {
grid-row:1;
grid-column:1;
width:100%;
height:100%;
}
input[type="checkbox"] {
z-index:2;
width:300%; /*big value to create the overflow*/
}
/* show/hide the text*/
p {
display: none;
}
input:checked ~ p {
display: block;
}
/**/
span {
color:red;
}
/* Change label text*/
input + span::before {
content: 'Show ';
}
input:checked + span::before {
content: 'Hide ';
}
/**/
<div class="box">
<input type="checkbox" />
<span>textarea</span>
<p >This is hidden textarea, that needs to be shown</p>
</div>
<div class="box">
<input type="checkbox" />
<span>textarea</span>
<p >This is hidden textarea, that needs to be shown</p>
</div>
<div class="box">
<input type="checkbox" />
<span>textarea</span>
<p >This is hidden textarea, that needs to be shown</p>
</div>
In order to get the collapse effect you can consider using the html elements: details and summary.
You can add your own CSS as you wish, but you don't have to write the toggle part since it is built in.
Generic example:
<details>
<summary>Read More</summary>
More of your content....
</details>
Read more on MDN

How to have different color for underline and overline in css?

I have this currently
p {
text-decoration: underline overline red;
}
<p>
This is some text
</p>
Here, I want to have different colors for the overline and underline.
Is this possible at all?
Put one span inside p and then you can set different color on span's overline.
p {
text-decoration: blue underline ;
}
span {
text-decoration: red overline;
}
<p><span>This is some text Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis ut iusto optio, similique iure. Autem facilis, eveniet vel ea mollitia ad obcaecati dignissimos nisi, reiciendis odio voluptas, aliquid iure voluptatibus.</span></p>
As far as I know you are only able to set text-decoration-color once and all decorations will have the same color. The syntax you are using as well will only work in Firefox currently. Other browsers will require prefixes like -webkit and may require experimental features be enabled in the browser.
A far more universally compatible solution would be to apply a border to your text. You will be able to achieve the effect you want and it will be compatible everywhere.
p {
border-top: 1px solid blue;
border-bottom: 1px solid red;
display: inline-block;
}
<p>Testing</p>

Force a line break in a URL

I've got a Twitter feed on my blog. It's working great, but there's an issue with long URLs in tweets. Long URLs break the layout by extending past the width of the container.
My code looks like this:
<ul id="twitter_update_list">
<!-- twitter feed -->
</ul>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&count=3"></script>
The blogger.js script contains the callback function which takes the data from the Twitter request and populates <li> elements to a predefined <ul>.
I'm using the following CSS to automatically break the line (for browsers that support it):
#twitter_update_list li span a {
word-wrap: break-word;
}
I know about the <wbr> tag and was trying to use it with a jquery function that looked like this:
$(document).ready(function(){
$("#twitter_update_list li span a").each(function(){
// a replaceAll string prototype was used here to replace "/" with "<wbr>/"
});
});
However when I tried using that snippet, it would cause IE to stop responding and that's no good.
I'm looking for a block of code I can just drop in that will fix the line break issue (by adding a line break to long URLs). Firefox and Chrome are working properly, but IE7 and IE8 need something more. (I don't care about IE6.)
You can try using: word-break: break-all;
div {
background: lightblue;
border: 1px solid #000;
width: 200px;
margin: 1em;
padding: 1em;
}
.break {
word-break: break-all;
}
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate vitae fugiat fuga fugit cum http://www.ThisLongTextBreaksBecauseItHasWordBreak-BreakAll.com facere mollitia repellat hic, officiis, consequatur quam ad cumque dolorem doloribus ex magni necessitatibus, nisi accusantium.</p>
<p>Voluptatibus atque inventore http://www.looooooooooooooooooooooooooooongURL.com veritatis exercitationem nihil minus omnis, quisquam earum ipsum magnam. Animi ad autem quos rem provident minus officia vel beatae fugiat quasi, dignissimos
sapiente sint quam voluptas repellat!</p>
</div>
Just be sure of applying this only to the link. Otherwise, all other words will break too. :)
Try playing with the white-space CSS property.
Check this link for more info: http://perishablepress.com/press/2010/06/01/wrapping-content/
I believe what you're looking for are soft hyphens. This was covered by ALA a while back.
http://www.alistapart.com/articles/the-look-that-says-book/
I know this is old post but since I ended up here with a related google search - someone else might also.
I needed to make a long url breakable, and since wasn't usable for my site (i.e not in html5 standards, and ie8 seems to ignore it)
<style>.wbr { display: inline-block; width: 0px;}</style>
Since i generated the url I was able to insert <span class="wbr"> </span> before the slashes.
So I ended up with :
www.example.com<span class="wbr"> </span>/somepath<span class="wbr"> </span>/blah.php
which looks normal in the browser but allows from word wraping at the / marks
www.example.com/somepath/blah.php
Hope that helps the next person who visits