Zoom in and out changing the position of the radio button - css

How can I fix the problem when zooming in and out(e.g. 80%) the checked radio button is slightly changing the position of the dot in the radio button?
Tried position fixed but it didn't help.Something to do with width and height probably but I can't figure out.
This is how it looks after zooming out
input[type="radio"] {
-webkit-appearance : none;
width : 20px;
height : 20px;
border-radius : 50%;
/* outline : none; */
border : 3px solid gray;
}
input[type="radio"]:before {
content : "";
display : block;
width : 60%;
height : 60%;
margin : 20% auto;
border-radius : 50%;
}
input[type="radio"]:checked:before {
background : green;
}
input[type="radio"]:checked {
border-color : green;
}
.role {
margin-right : 80px;
margin-left : 20px;
font-weight : normal;
}
.checkbox label {
margin-bottom : 20px !important;
}
.roles {
margin-bottom : 40px;
}
<div class="roles">
<input type="radio" name="role" value="ONE" id="one" />
<label class="role" for="one">ONE</label>
<input type="radio" name="role" value="TWO" id="two" />
<label class="role" for="two">TWO</label>
</div>

To achieve expected result, using display:flex for class roles and align-items:center for aligning vertically
Sample working code below and codepen- https://codepen.io/nagasai/pen/rNrgeOx for reference -
input[type="radio"] {
-webkit-appearance : none;
width : 20px;
height : 20px;
border-radius : 50%;
/* outline : none; */
border : 3px solid gray;
}
input[type="radio"]:before {
content : "";
display : block;
width : 60%;
height : 60%;
margin : 20% auto;
border-radius : 50%;
}
input[type="radio"]:checked:before {
background : green;
}
input[type="radio"]:checked {
border-color : green;
}
.role {
margin-right : 80px;
margin-left : 20px;
font-weight : normal;
}
.checkbox label {
margin-bottom : 20px !important;
}
.roles {
margin-bottom : 40px;
display: flex;
align-items: center;
}
<div class="roles">
<input type="radio" name="role" value="ONE" id="one" />
<label class="role" for="one">ONE</label>
<input type="radio" name="role" value="TWO" id="two" />
<label class="role" for="two">TWO</label>
</div>

Related

width of paragraph not the width of the text

I'm doing a message app with html js and php, but the css of the messages does something I don't uderstand : basically the width of the p isn't the with of the text but the max-width of the parent element here's the image of what happens : messages
i've tried multiple things, like assigning a static width but the width should change with the text, the php output is put in the chat-box with jquery
.chat-area header {
display : flex;
align-items : center;
padding : 18px 30px;
}
.chat-box {
height : 500px;
background : #f7f7f7;
padding : 10px 30px 20px 30px;
box-shadow : inset 0 32px 32px -32px rgb(0 0 0 / 5%),
inset 0 -32px 32px -32px rgb(0 0 0 / 5%);
overflow-y : auto;
}
.chatbox .chat {
margin : 15px 0;
}
.chatbox .chat p {
word-wrap : break-word;
padding : 8px 16px;
}
.chatbox .outgoing {
display : flex;
}
.chatbox .incoming {
display : flex;
}
.outgoing .details {
margin-left : auto;
max-width : calc(100% - 130px);
margin-right : 10px;
}
.outgoing .details p {
margin-left : auto;
position : relative;
background : #333;
color : #fff;
padding : 10px;
border-radius : 18px 18px 0px 18px;
margin-bottom : 10px;
}
.incoming .details {
margin-left : 10px;
margin-right : auto;
max-width : calc(100% - 130px);
}
.incoming .details p {
color : #333;
background : #fff;
border-radius : 18px 18px 18px 0px;
padding : 10px;
margin-bottom : 10px;
}
<section class="chat-area" style="width : 100%">
<header>
<i class="fas fa-arrow-left" id="goBackToSearch"></i>
<div class="content">
<div class="details">
<span id="CalledName">Admin</span>
<p>Active Now</p>
</div>
</header>
<div class="chat-box">
</div>
<form action="#" class="typing-area" autocomplete="off">
<input type="text" class= "input-field" placeholder="Scrivi un messaggio...">
<button><i class='bx bxs-caret-right-circle' ></i>
</form>
</section>
$query = "
SELECT *
FROM messages
WHERE outgoing_msg_id = :outgoing_id AND incoming_msg_id = :incoming_id
OR outgoing_msg_id = :incoming_id2 AND incoming_msg_id = :outgoing_id2
";
$output = "";
$check = $pdo->prepare($query);
$check->bindParam(':outgoing_id', $outgoing_id, PDO::PARAM_STR);
$check->bindParam(':outgoing_id2', $outgoing_id, PDO::PARAM_STR);
$check->bindParam(':incoming_id', $id, PDO::PARAM_STR);
$check->bindParam(':incoming_id2', $id, PDO::PARAM_STR);
$check->execute();
$messages = $check->fetchAll(PDO::FETCH_ASSOC);
for($i=0;$i<$check->rowCount();$i++){
if ($messages[$i]["outgoing_msg_id"] == $outgoing_id){ //he is a message sender
$output .= '<div class="chat outgoing">
<div class="details">
<p>'.$messages[$i]["msg"].'</p>
</div>
</div>';
} else if ($messages[$i]["outgoing_msg_id"] == $id) { //he is a message receiver
'<div class="chat incoming">
<div class="details">
<p>'.$messages[$i].'</p>
</div>
</div>';
}
}
echo $output;

How to change css rules of a sibling element when one is on focus?

How to change css rules of a sibling element when one is on focus?
So the idea is to make the opacity of img 0.5 when the input[type="text"] is on focus.
How can I do that?
#search img {
width: 1rem;
margin: 0 0.64rem;
opacity: 0.9;
}
#search input[type="text"] {
background-color: transparent;
outline: none;
border: none;
padding: 0.64rem 0;
}
#search input[type="text"]:focus+img {
opacity: 0.5;
}
<div id="search">
<img src="assets/search-ico.svg" alt="search" />
<input type="text" placeholder="Search Products" />
</div>

Spacing inline-block elements (with variable widths) on multiple rows within a fixed width padded container

I have some <input type="radio"/ > radio buttons that are used as toggle buttons according to this example: http://jsfiddle.net/davidelrizzo/DYJkG/
The buttons themselves have variable widths and are grouped inside a <div class="toggle-btn-grp">.
The buttons-group is itself is located in a parent <div> with fixed width (blue lines in the picture) and padding (pink lines).
Currently, the buttons are spaced with margin-right:1em.
The rightmost element on each row should however not have any right-margin (or this one should overflow the padding of the grand-parent container).
As we see, there is enough space for button #6 to stay on the same row as button #5, if it did not have a margin on its right.
How can I achieve this?
Here's the XHTML:
<div class="toggle-btn-grp" style="padding-top:0.3em;padding-bottom:0.3em;word-spacing:-.3em;" >
<label onclick="" class="toggle-btn"><input type="radio" name="brand" value="1" />1</label>
<label onclick="" class="toggle-btn"><input type="radio" name="brand" value="2 "/>2</label>
<label onclick="" class="toggle-btn"><input type="radio" name="brand" value="3" />3</label>
(...)
</div>
and the CSS of the toggle buttons:
/* Toggle buttons */
label {
padding:0.3em 1em 0.3em 0;
}
.toggle-btn-grp {
}
.toggle-btn {
display:inline-block;
text-align:center;
min-width:3em;
margin-bottom:1em;
margin-right:1em;
padding:0.2em 1em;
/*background-color:#f8f8f8;*/
border-radius:0.2em;
border:solid 2px #ccc;
cursor:pointer;
}
.toggle-btn-grp.joint-toggle .toggle-btn {
margin:5px 0;
padding:0.2em 0.1em;
border-radius:0px;
border-right-color:#fff;
}
.toggle-btn-grp.joint-toggle {
display:inline-block;
}
.toggle-btn-grp.joint-toggle .toggle-btn:first-child {
margin-left:2px;
border-radius: 0.2em 0px 0px 0.1em;
}
.toggle-btn-grp.joint-toggle .toggle-btn:last-child {
margin-right:2px;
border-radius: 0px 0.2em 0.1em 0px;
border-right:solid 1px #ccc;
}
.toggle-btn:hover {
border:solid 2px #888 !important;
color:#000;
background:#def;
}
.toggle-btn.active {
color: #fff;
font-weight:bold;
background:#a2dafe;
border:solid 1px #888 !important;
}
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.visuallyhidden.focusable:active, .visuallyhidden.focusable:focus {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}
Note 1. So far, the best solution I found is adding the right margin only to odd elements.
This works for me only because there is place to display two buttons per row, but would not work if the buttons had more variations in their width:
.toggle-btn:nth-child(odd) {
margin-right:1em;
}
Note 2. I tried using a flex layout, but it didn't work for me:
.toggle-btn-grp {
display: flex;
flex-direction: row;
}
.toggle-btn {
flex: 1 1 auto;
}
I would recommend looking into the gap property on CSS grid.
MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
CSS Tricks: https://css-tricks.com/snippets/css/complete-guide-grid/
The gap is only applied between items. Something like this could get it started.
.toggle-btn-grp {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto;
column-gap: 1rem;
}
Don't use margins, make use of the white space you already have in your matkup between the labels and stretch it using letter-spacing or word-spacing to get whatever gap you want. Because space characters are automatically dropped at the ends of line boxes, the labels will fit nicely.
/* Toggle buttons */
.toggle-btn-grp {
padding-top:0.3em;
padding-bottom:0.3em;
letter-spacing:0.65em; /* this controls the gap between the labels */
}
.toggle-btn {
font-size:1rem;
background-color:lightblue;
display:inline-block;
text-align:center;
margin-bottom:1em;
padding:0.2em 1em;
border-radius:0.2em;
border:solid 2px #ccc;
cursor:pointer;
letter-spacing:0em; /* resets the spacing inside the labels */
}
/* Just for demo purposes */
body {
width:155px;
border-color: blue;
border-style: solid;
border-width: 0 1px;
padding:10px;
position:relative;
}
body::before, body::after {
content:'';
position:absolute;
top:0;
bottom:0;
border-right:1px solid pink;
}
body::before {
left:10px;
}
body::after {
right:10px;
}
<div class="toggle-btn-grp">
<label class="toggle-btn"><input type="radio" name="brand" value="1" />1</label>
<label class="toggle-btn"><input type="radio" name="brand" value="2 "/>2</label>
<label class="toggle-btn"><input type="radio" name="brand" value="3" />3</label>
<label class="toggle-btn"><input type="radio" name="brand" value="10" />10</label>
<label class="toggle-btn"><input type="radio" name="brand" value="20 "/>20</label>
<label class="toggle-btn"><input type="radio" name="brand" value="100" />100</label>
</div>

JSFiddle : Shading radio button a different color

I am trying to change the background color of my radio button so that my whole button itself looks blue.
This is the html code :
<div class="col-sm-6" id="bcolor">
<center><label class="blue"><input type="radio" id="b1" name="toggle" ><span
</span></label> </center>
</div>
and these are the css styles I've tried and none of them seem to work :
input[type="radio"]
{
background-color : #5499C7;
}
input[type="radio"] + label
{
background-color : #5499C7;
}
input[type="radio"] +label.blue
{
background-color : #5499C7;
}
input#b1
{
background-color : #5499C7;
}
It would be great if someone could tell me what I'm missing.
input[type="radio"] + label
{
background-color : #5499C7;
height:15px;
width:15px;
display:inline-block;
vertical-align:text-top;
border-radius:50%;
}
input[type="radio"]:checked +label{
background-color: red;
}
<div class="col-sm-6" id="bcolor">
<center>
<input type="radio" id="b1" name="toggle" >
<label class="blue"></label>
</center>
</div>
You Can Try Something Like this.
The Problem in your code is that, you wrapped the input[radio] in the label tag and you are using the sibling selector + in CSS, which doesn't work.
Styling radio-buttons is not difficult, but you will need to use other element, most likely label, obvious choice so that you don't need javascript to handle click. It will look like radio-button, and radio-button itself will be hidden. The principle I shoed in snippet. Hope you will be able to reproduce it with your code. Need explanation of CSS or is it self-explanatory enough?
input {
position: absolute;
left: -10000px;
top: 0;
height: 0;
width: 0;
visibility: hidden;
}
label {
height: 34px;
width: 34px;
border-radius: 17px;
background-color: whitesmoke;
border: 1px solid silver;
position: relative;
display: block;
}
input:checked + label {
background-color: #5499C7;
}
input:checked + label:before {
display: inline-block;
position: absolute;
content: '';
left: 50%;
top: 50%;
margin-left: -10px;
margin-top: -10px;
background: silver;
width: 20px;
height: 20px;
border-radius: 10px;
}
<input type="checkbox" id="id1"/>
<label for="id1"></label>

adjust label position in image type radio button

I am creating radio buttons but i am facing to adjust the label position. Please helo me to solve this.
my code is:
<style>
input[type=radio]:not(old){
width : 50px;
margin : 0;
padding : 0;
opacity : 0;
}
input[type=radio]:not(old) + label{
display : inline-block;
padding-left : 63px;
background : url('radio.png') no-repeat 0 0;
line-height : 25px;
}
input[type=radio]:not(old):checked + label{
background-position : 0 -24px;
}
html:
<input id="radio1" type="radio" name="radio" value="1" onclick="javascript:yesnoCheck();" checked="checked"><label for="radio1">Now </label>
<input id="radio2" type="radio" name="radio" onclick="javascript:yesnoCheck();" value="2"><label for="radio2">Later</label>
Please have a look at image, i need to move labels to the left side
HTML:
<input id="radio1" type="radio" name="radio" value="1" onclick="javascript:yesnoCheck();" checked="checked"><label for="radio1">Now </label>
<input id="radio2" type="radio" name="radio" onclick="javascript:yesnoCheck();" value="2"><label for="radio2">Later</label>
CSS:
input[type=radio]:not(old){
width : 50px;
margin : 0;
padding : 0;
opacity : 0;
}
input[type=radio]:not(old) + label{
display : inline-block;
padding-left : 63px;
line-height : 25px;
position: relative;
}
input[type=radio]:not(old) + label:after{
content: '';
position: absolute;
top: 0;
left: 23px;
width: 100%;
height: 100%;
z-index: -1;
background : url('radio.png') no-repeat 0 0;
}
input[type=radio]:not(old):checked + label{
background-position : 0 -24px;
}
Is this helping?

Resources