I'm having a real difficult time trying to style a checkbox in bootstrap, I currently have the default checkbox, and I need to style it to look like this
I'm aware this picture it's round but the designer made a mistake, so instead of being round it still needs to be square
I have looked at the following and also tried what is suggested.
Twitter Bootstrap radio/checkbox
I did on the other hand find a website which has a similar to style to what i'm trying to achieve which is on here located on the left hand side where you do the filtering
Example of the checkbox
I tried using firebug to get/check out the CSS but I was unable to obtain the CSS.
So if you don't need support for IE8 you can easily do this with a background image and the :checked selector in CSS only. I used an svg image, but you could use a font, sprite or just two images.
#import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css";
body {
background-color:#f5e1c6;
}
.image-checkbox {
position: absolute;
left: 100%;
visibility: hidden;
}
.image-checkbox-label {
height: 50px;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 96 84" enable-background="new 0 0 96 84" xml:space="preserve"><path fill="rgb(213,195,170)" d="M74.2,73.5H19.5c-2.8,0-5.1-2.3-5.1-5.1V15.6c0-2.8,2.3-5.1,5.1-5.1h54.7c2.8,0,5.1,2.3,5.1,5.1 v52.7C79.3,71.2,77,73.5,74.2,73.5z"/></svg>') no-repeat;
color: #7b7163;
}
.image-checkbox:checked + .image-checkbox-label {
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 96 84" enable-background="new 0 0 96 84" xml:space="preserve"><path fill="rgb(213,195,170)" d="M74.2,73.5H19.5c-2.8,0-5.1-2.3-5.1-5.1V15.6c0-2.8,2.3-5.1,5.1-5.1h54.7c2.8,0,5.1,2.3,5.1,5.1 v52.7C79.3,71.2,77,73.5,74.2,73.5z"/><polygon id="check" fill="rgb(251,253,223)" points="30.2,31.8 30.2,43 46.1,54 80.1,19.1 80.1,6.1 46.4,44.7 "/></svg>') no-repeat;
color: #c3b39c;
}
.checkbox label {
padding-left: 60px;
line-height: 50px;
font-weight: bold;
font-size: 2em;
}
<div class="container">
<div class="row">
<div class="col-xs-12">
<form>
<div class="form">
<div class="checkbox">
<input id="remember-me" type="checkbox" class="image-checkbox" />
<label for="remember-me" class="image-checkbox-label">
Remember Me
</label>
</div>
</div>
</form>
</div>
</div>
</div>
How it Works
Give the input an id so that you can use the for attribute on the label. Don't forget to make your ids unique. Give the input a class (I used .image-checkbox), and position the input so that it's hidden offscreen but still displayed.
Style your label using the background-image for the unchecked box style. Using the :checked pseudo selector and the sibling selector (+), you can target how the label should be styled when the input is selected. In this case, I changed the background image to the checked image and changed the font color.
To get the actual label text to align nicely, I'm also overriding some of the default Bootstrap styles for .checkbox label. You can adjust them to suit your needs.
Related
I have a problem.
Please can anyone help me out? I am creating a clone of flipkart.com ( an Ecom website).
I need some icons of the same color as which are on their website. I found some on google fonts, but only have two color variations ( Black & white).
I need same icon in yellow color can anyone help me out through this.
Google fonts link--- https://fonts.google.com/icons?icon.query=suitcase
<span class="material-icons-outlined">
work_outline
work_outline br
codepoint
e943
download it as a .svg file and put it in your code. Use fill: red; to make it the color you want it to be.
<img src="image.svg" alt="image" fill="red">
This should work :)
Apply styles with css. Does this work?
html, body {height: 100%}
body {
background: #000;
display: flex;
justify-content: center;
align-items: center;
}
svg {
fill: yellow;
width: 100px;
height: auto;
}
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M14 6V4h-4v2h4zM4 8v11h16V8H4zm16-2c1.11 0 2 .89 2 2v11c0 1.11-.89 2-2 2H4c-1.11 0-2-.89-2-2l.01-11c0-1.11.88-2 1.99-2h4V4c0-1.11.89-2 2-2h4c1.11 0 2 .89 2 2v2h4z"/></svg>
I want to create a menu like this Home > where the right arrow is an icon in an svg sprite. I would like to place the > as a psuedo element in the css selector so that i can make any menu have the right arrow just by adding the css selector .menu-arrow. I am trying to do this in ruby on rails 6 with no success.
I have tried adding the svg icon sprite as a background content but it doesn't seem to work correctly.
My svg sprite
path to svg sprite: app/assets/images/sprites.svg
<svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-check-solid" viewBox="0 0 32 32">
<path d="M10.869 27.463l-10.4-10.4c-0.625-0.625-0.625-1.638 0-2.263l2.263-2.263c0.625-0.625 1.638-0.625 2.263 0l7.006 7.006 15.006-15.006c0.625-0.625 1.638-0.625 2.263 0l2.263 2.263c0.625 0.625 0.625 1.638 0 2.263l-18.4 18.4c-0.625 0.625-1.638 0.625-2.263-0z"></path>
</symbol>
<symbol id="icon-chevron-down-solid" viewBox="0 0 28 32">
<path d="M12.939 23.842l-12.146-12.146c-0.586-0.586-0.586-1.536 0-2.121l1.417-1.417c0.585-0.585 1.533-0.586 2.119-0.002l9.672 9.626 9.672-9.626c0.586-0.583 1.534-0.582 2.119 0.002l1.417 1.417c0.586 0.586 0.586 1.536 0 2.121l-12.146 12.146c-0.586 0.586-1.536 0.586-2.121 0z"></path>
</symbol>
</defs>
</svg>`
My css class
.menu-arrow {
&::after {
content: '';
display: inline-block;
height: 2rem;
width: 2rem;
background-image: asset-url("images/sprites.svg#icon-chevron-down-solid");
transform: rotate(90deg) scale(1.5);
fill: var(--color-white);
color: var(--color-white);
font-weight: 700;
border: 1px solid red;
}
}
}
How do i make this work?
This article suggests the #id in the CSS url is referencing a view rather than a symbol
You can certainly use your sprite as an inline SVG (shadow) DOM element via use, and make a helper to streamline the process (see this)
For your chevron specifically, you can achieve an almost identical graphic element using your pseudo element without a background (borders on two sides with rounded corners and rotated 45deg). I made a pen here that demonstrates this approach
[EDIT] I've reviewed my entire post to add precisions about the problem and for additional ressources.
...
I'm new to SVG usage for webdesign, but I intend to implement a cool CSS feature for a theme. For information, I work with SASS to compile my styles.
What I want to achieve is to obtain a configurable theme that can change of color simply by changing some vars in my SASS files.
To do so :
I use "uncolored" SVGs as background for some elements of my website.
Then I apply a SVG filter for those elements to "colorize" them.
At this point, I'm pretty happy, because it is working... on almost all browsers : Brave, Chrome, Firefox, Opera, Edge
But it doesn't work on Safari and I'm not sure Why :
it seems that I cannot use the CSS filter with value url('data:image/svg+xml, <svg>...</svg>')
However it seems that I can use the filter property with url value if I'm targeting an element already in the DOM.
I've found an interesting article that talk about the same problem :
https://www.stefanjudis.com/today-i-learned/svgs-filters-can-be-inlined-in-css/#til%3A-svg-filters-can-be-inlined-in-css
I tested the included examples in Firefox 84 and and Chrome 87. It worked in Safari 14 but stopped for unknown reason.
The "included example" being inline SVG in the CSS
Do someone know if using inline CSS SVG is possible with Safari ?
Here is an example to illustrate the problem:
/* Basic style for parent */
.parent {
border: 3px dotted violet;
background: pink;
width: 400px;
height: 50px;
margin-bottom: 30px;
position: relative;
}
/* Basic style for children */
.children {
text-align: center;
color: #ffffff;
line-height: 40px;
}
.children::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Using a pseudo element inside childrens that carry the background image */
.v0 .children::after, .v1 .children::after{
background-image: url('https://public.xspawn.fr/svg-bg-btn.svg');
background-repeat: no-repeat;
background-size: 100% 100%;
}
/*Creating a new stack context to be able to display text*/
.parent{position: relative; z-index:0;}
.children::after{ z-index:-1;}
/* Applying a filter to each children 'after' pseudo element to colorize its content (the SVG background or the background color) */
.children.recolor::after{
filter : url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg"><filter id="recolor" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="0 0 0 0 .13725 0 0 0 0 .23137 0 0 0 0 .32157 0 0 0 1 0"/></filter></svg>#recolor');
);
}
.children.recolor2::after{
filter : url('#dom-filter');
}
[v0] Element without Without SVG filter
<div class="parent v0">
<div class="children">No filter</div>
</div>
<strong style='color:orangered;'>[v1] KO : Filtered with "filter: url(data:image... )"</strong>
<div class="parent v1">
<div class="children recolor">filter: url(data:image..., < svg > .. .< svg \> )</div>
</div>
<strong style='color:green;'>[v2] OK : Filtered with filter DOM SVG and "filter: url('#elementid')"</strong>
<div class="parent v1">
<div class="children recolor2">filter: url('#dom-filter')</div>
</div>
<svg xmlns="http://www.w3.org/2000/svg"><filter id="dom-filter" color-interpolation-filters="sRGB"><feColorMatrix type="matrix" values="0 0 0 0 .13725 0 0 0 0 .23137 0 0 0 0 .32157 0 0 0 1 0"/></filter></svg>
Question: "Do someone know if using inline CSS SVG is possible with Safari ?"
Answer: "Yes it is possible".
If you use filters on svg elements in css/scss file like this
filter: url(#filter_id);
Transfer the styles from the css/scss file into the svg file separately into styles, and everything will work, like this:
<svg>
...
<g filter="url(#filter)">
..
</g>
<filter id="filter" x="5.54736" y="0" width={width-11.3} height="80.0002" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood floodOpacity="0" result="BackgroundImageFix"/>
<feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
<feGaussianBlur stdDeviation="10" result="effect1_foregroundBlur_326_868"/>
</filter>
</svg>
I'm implementing a layout for a web-app running on Rails 5.2.
The layout has a header with a Css class (named section-divider) whose background is a SVG and it should occupy all the page width.
The SVG works fine in the HTML file I received from the designer: if I open the html file, it works correctly (check the first image).
The SVG doesn’t behave properly when I run the same code from the rails app (check the second image).
The only difference between the HTML version and the Rails one, is the reference to the SVG in the SCSS file.
I’ve tried multiple options and ways to reference the file without luck.
The SVG is being always displayed but it doesn’t stretch as it should.
It’s driving me crazy because the output HTML and Css are the same (from Rails and from the HTML provided by the designer)
SVG file
<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="638" viewBox="0 0 1920 638">
<path id="Rectangle_69" data-name="Rectangle 69" d="M0,0H1920a0,0,0,0,1,0,0V392a246,246,0,0,1-246,246H246A246,246,0,0,1,0,392V0A0,0,0,0,1,0,0Z" fill="#aaa"/>
</svg>
HTML CODE: the section-divider class is the one whose background is the SVG (just at the beginning, in the header)
<header class='search-bar text-center section-divider'>
<div class='container pt-4'>
<div class='mx-auto input-group col col-md-6 col-xxxl-4 ' >
<input type='text' class='form-control shadow-sm search-input' placeholder='' aria-label='Qué buscas' aria-describedby='button-addon2'>
<div class='input-group-append'>
<button class='btn btn-outline-primary' type='button' id='button-addon2'>Buscar</button>
</div>
</div>
</div>
</header>
CSS in Rails
.section-divider (landing_page.scss){
background: image-url("front/divider/header.svg");
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
padding-bottom: 2rem;
}
CSS in designer files (landing_page.scss)
.section-divider{
background: url('../front/divider/header.svg');
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
padding-bottom: 2rem;
}
In this image, the grey area is the SVG and in this image and it is displayed correctly
In this other image, the grey area is the SVG and it is NOT displayed correctly (because it doesn't stretch)
I suppose this is what you want to achieve.
.section-divider{
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' preserveAspectRatio ='none' viewBox='0 0 1920 638'%3E%3Cpath d='M0,0H1920V392a246,246,0,0,1-246,246H246A246,246,0,0,1,0,392V0Z' fill='%23aaa'/%3E%3C/svg%3E");
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
padding-bottom: 2rem;
border:1px solid;
}
<header class='search-bar text-center section-divider'>
<div class='container pt-4'>
<div class='mx-auto input-group col col-md-6 col-xxxl-4 ' >
<input type='text' class='form-control shadow-sm search-input' placeholder='' aria-label='Qué buscas' aria-describedby='button-addon2'>
<div class='input-group-append'>
<button class='btn btn-outline-primary' type='button' id='button-addon2'>Buscar</button>
</div>
</div>
</div>
</header>
In this case you need to use the following svg instead:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1920 638" preserveAspectRatio ="none">
<path id="Rectangle_69" data-name="Rectangle 69" d="M0,0H1920V392a246,246,0,0,1-246,246H246A246,246,0,0,1,0,392V0Z" fill="#aaa"/>
</svg>
Please observe that the svg has no width and height. Also I've added preserveAspectRatio ="none".
Please read about the preserveAspectRatio
attribute. If preserveAspectRatio="none" the image will be scaled non-uniformly.
Also your path has 2 arcs with radius 0. I've removed those arcs.
I'm trying to design an informational and instructional welcome modal box with 3 "pages" using custombox.js
The modal appears in the middle of the screen, I then need to display content in the middle of the modal, with a previous button to the left, next to the right and a footer showing progress.
I did this successfully using CSS grid layout, but many of the users do not have browsers that support this. I can't figure out how to make this using plain CSS...
Here's my html
<div id="modal">
<div id="leftNnav">
<i id="leftNnavImage" class="fa fa-chevron-left" aria-hidden="true"></i>
</div>
<div id="modalContent1" class="modalContent activeModalContent">
<img id="modalContentMedia" src="https://cdn.pixabay.com/photo/2013/04/06/11/50/image-editing-101040_960_720.jpg"/>
content text goes here, lots and lots and lots and lots and lots and lots more
</div>
<div id="modalContent2" class="modalContent">
Content2 = YT Video
</div>
<div id="modalContent3" class="modalContent">
Content3 = text
</div>
<div id="rightNnav">
<i id="rightNnavImage" class="fa fa-chevron-right" aria-hidden="true"></i>
</div>
<div id="modalFooter">
<svg height="40" width="40">
<circle id="circle1" class="circle activeCircle" cx="20" cy="20" r="10"></circle>
</svg>
<svg height="40" width="40">
<circle id="circle2" class="circle" cx="20" cy="20" r="10"></circle>
</svg>
<svg height="40" width="40">
<circle id="circle3" class="circle" cx="20" cy="20" r="10"></circle>
</svg>
</div>
</div>
https://jsfiddle.net/oppt6v9j/15/
But this way just ends up really messy, the text overflows and it just doesn't feel like the correct way to do things, I feel like I'm missing something really obvious. I know I can resize the image using media queries, so that's fine, but I'm not sure how to manage the text.
Any help with how I can design this modal in CSS is very much appreciated!
If your problem with aligning the components, I would suggest the following
.right { float: right; }
.left { float: left; }
.modal { display: flex; }
.modalContent { margin: auto; }
I believe using ID's as CSS selectors is bad practice.
Hope it helps.
Right, this is a tough one since I don't know the exact dimensions of the box (and you use alot of position: absolutes).
I'd imagine it varies with screen size but your image has a height/width set (300px by 150px) so I focused on that size instead.
Note This is not an "end all be all" answer, it won't solve every usecase under the sun, rather it answers the original question:
But this way just ends up really messy, the text overflows and it just
doesn't feel like the correct way to do things, I feel like I'm
missing something really obvious.
It does this by providing a way of thought rather than a clear answer.
The solution
You're using a lot of absolute positions, this means you have to work with alot of magic numbers. Try converting them to relative positions instead.
The text is really easy, you should wrap it in a <p> tag like so:
<p>
Content text goes here, lots and lots and lots and lots and lots and lots more
</p>
And style it appropriately (box padding / corners etc):
p {
color: #001818;
padding-right: 40px;
}
The same holds true for the image:
#modalContentMedia{
width: 300px;
height: 150px;
margin-left: 15px;
}
And I'm not sure where you'd want the arrows positioned (they are in the center of the box right now) but I can imagine you'd want them in the center of the image. To do so use:
#leftNnav{
position: absolute;
cursor: pointer;
z-index: 20;
padding-left: 10px;
left: 5px;
top: calc(50% - 40px);
}
#rightNnav{
position: absolute;
cursor: pointer;
z-index: 20;
padding-right: 10px;
right: 5px;
top: calc(50% - 40px);
}
This makes the entire thing look much neater:
By illustrating how I would start solving this issue I've demonstrated fixing the 3 major things (text, image position not centered, arrows) and trust you'll be able to learn and fix the rest of the issues yourself.