How to place background with text over another background image without HTML - css

I made a form with checkbox as a forest image. I need to place another transparent background with text from html parameter (data-forest) over the forest checbox image but I have to do this only by CSS. I've tried so many solutions but no one work properly. Anyone have some idea?
Final effect on hover:
JsFiddle: https://jsfiddle.net/ac9z8sgd/
HTML
<form action="action" method="get">
<input type="hidden" name="test" value="test" />
<ul>
<li><input id="checkbox" type="checkbox" name="forest_type" value="forest_1"><label for="checkbox_forest" data-forest="Estern forest">Forest 1</label></li>
</ul>
<button type="submit">Submit</button>
</form>
CSS
/* Default check button */
#checkbox + label {
background: url('http://i.imgur.com/Ds7gh7b.jpg?1');
background-repeat: no-repeat;
height: 250px;
width: 250px;
padding: 15px 15px;
display: inline-block;
position: relative;
}
/* Hover action */
#checkbox + label[data-forest]:hover {
background: rgba(0,0,0,0.8);
content: attr(data-forest);
display: inline-block;
font-size: 20px;
color: white;
position: relative;
}

Use a pseudo-element.
/* Default check button */
#checkbox + label {
background: url('http://i.imgur.com/Ds7gh7b.jpg?1');
background-repeat: no-repeat;
height: 275px;
width: 184px;
display: inline-block;
position: relative;
}
/* Hover action */
#checkbox + label[data-forest]:hover::after {
background: rgba(0, 0, 0, 0.8);
content: attr(data-forest);
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 50%;
font-size: 20px;
color: white;
display: flex;
}
<form action="action" method="get">
<input type="hidden" name="test" value="test" />
<ul>
<li>
<input id="checkbox" type="checkbox" name="forest_type" value="forest_1">
<label for="checkbox_forest" data-forest="Estern forest">Forest 1</label>
</li>
</ul>
<button type="submit">Submit</button>
</form>
JSfiddle with Transitions

My suggestion:
label[data-forest]:hover:before {
background: rgba(0,0,0,0.8);
content: attr(data-forest);
font-size: 20px;
color: white;
margin-top: 240px;
margin-left: -15px;
position: absolute;
width: 100%;
text-align: center;
}
BTW: Maybe 0.8 is too much a high value for a perceptible transparency. I'd make it 0.4.

Related

CSS Invisible radio button but highlight wrapping div

The following HTML is being generates radio_buttons as selectors from an image label
<div class='small-2 columns buttonselector'>
<label for="content_ki_id_1">
<input class="invisi-selector" type="radio" value="1" name="content[ki_id]" id="content_ki_id_1" />
<img src="/assets/circle.svg" />
<div></div>
</label>
</div>
The CSS properly makes the radio button invisible, but there is a gap in handling the wrapper and its visibility on radio_button selected
.buttonselector > div {
width: 100%;
height: 100%;
background: #fff;
}
.invisi-selector {
opacity: 0;
}
.invisi-selector:checked + div {
border-color: #ba53ad;
border-width: 4px;
}
the wrapper cannot logically take the selector's class for it would be invisible. How can the checked action be binded to the wrapping div?
It can't, but you can use absolute positioning to make it look like it is.
.buttonselector>label {
width: 100%;
height: 100%;
background: #fff;
display: block;
position: relative;
}
.invisi-selector {
opacity: 0;
position: absolute;
}
.invisi-selector~div {
z-index: -1;
position: absolute;
left: -4px;
top: -4px;
width: 100%;
height: 100%;
}
.invisi-selector:checked~div {
border: 4px solid #ba53ad;
}
<div class='small-2 columns buttonselector'>
<label for="content_ki_id_1">
<input class="invisi-selector" type="radio" value="1" name="content[ki_id]" id="content_ki_id_1" />
<img src="/assets/circle.svg" />
<div></div>
</label>
</div>

Custom checkbox and radio button not support in all browser

I used custom checkbox and radio button for my project using :before and :after, but this work only in "Google Chrome" and not supported in other browsers, Is any trick that's why it should look same in all browser, I don't want to use label after checkbox or radio button.
CSS is here:
FIDDLE ( For example )
My actual radio button looks like this :
Google Chrome:
Firefox:
IE:
Pseudo Elements like :before and :after add content before and after the content of an element. Checkbox and Radio buttons do not have content, so they don't support before and after pseudo elements. Chrome is ' special ' , but the normal behavior is the one from FF and IE.
Furthermore checkbox and radio are browser default elements. They are very hard to change and not supposed to be changed.
Although you said you don't want to add a label, that's the way to go. Add it with position absolute to put it on top of the radiobutton/checkbox like in the example below
body {
padding: 50px;
}
input[type='radio'] {
margin: 0;
height: 13px;
width: 13px;
margin-top: 2px;
position: relative;
}
div.wrapper {
position: relative;
}
input[type='radio'] + label {
content: '';
display: inline-block;
width: 13px;
height: 13px;
border: none;
position: absolute;
left: 0;
top: 1px;
background: gray url("../images/i-radio-empty.png") no-repeat 0 0;
}
input[type='radio']:checked + label {
width: 13px;
height: 13px;
background: red url("../images/i-radio-checked.png") no-repeat 0 0;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male"> Male
<label for="male"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female"> Female
<label for="female"></label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="other" id="other"> Other
<label for="other"></label>
</div>
Mihai T's solution isn't bad, but not checking checkbox when cliking on text can be really anoying. I personally hate it :)
Though it is true that radio and chekbox does not support pseudo elemens :before and :after but label does. So you can have normal label with text and pseudo element :before with position: absolute.
div.wrapper {
position: relative;
display: inline-block;
margin-right: 10px;
}
input[type='radio'] {
display: none;
}
input[type='radio'] + label {
padding-left: 20px;
}
input[type='radio'] + label:before {
content: '';
width: 13px;
height: 13px;
position: absolute;
left: 0;
top: 1px;
background: #FFF;
border: 1px solid #999;
border-radius: 50%;
cursor: pointer;
box-sizing: border-box;
}
input[type='radio']:checked + label:before {
background: #000;
border: 4px solid #F9CC55;
}
<div class="wrapper">
<input type="radio" name="gender" value="male" id="male">
<label for="male">Create Tabs Group</label>
</div>
<div class="wrapper">
<input type="radio" name="gender" value="female" id="female">
<label for="female">Update Existing Tabs Group</label>
</div>

CSS- Coloured cox inside form field

I am a newbie but pretty good at CSS, But i can not seem to get my head around doing the following:
It is the box and background, that is confusing me. The rest i am perfecting fine with. Any pointers would be very helpful. I know bootstrap have a similar plugin, but i find bootstrap a nightmare to use.
I have tired countless of ridiculous things, i am to embarrassed to show, thought is is about time i ask the pro's.
input[type=text]{
background-color: linear-gradient(90deg, #FFC0CB 50%, #00FFFF 50%);
color: black;
}
input[type=text]{
background-color: red;
color: aqua;
background-size: 20%;
}
HTML
<div id="section_left">
<form id="franchiseDets" action ="Franchise-Details.php" method="POST">
<!-- franchise details form-->
<div class="field">
<input type="text" name="fran_name" id="fran_name" value="<?php echo $_SESSION['fran_name']; ?>" placeholder="e.g One Delivery Leeds" pattern="[a-zA-Z]"
autofocus required tabindex="1">
<br>
<input type="email" name="fran_email" id="fran_email" value="<?php echo $_SESSION['fran_email'] ?> ' <?php echo $disabled ?>" placeholder="leeds#one-delivery.co.uk" required tabindex="2">
<br>
<input type="text" name="mang_name" id="mang_name" value="<?php echo $_SESSION['mang_name']; ?>" placeholder="Joe Blogs" required tabindex="3">
<br>
These are last two ridiculous things i have tired
Here is a method I would usually use.
Pure CSS and semantics :)
HTML
<fieldset class="example">
<input type="text" placeholder="Phone" />
</fieldset>
CSS
fieldset.example {
position: relative;
}
fieldset.example,
fieldset.example:before,
fieldset.example input {
height: 33px;
padding: 0;
border-width: 0;
/* remove default border */
}
fieldset.example input {
border: 1px solid red;
border-left: 0px;
padding-left: 5px;
border-radius: 0 5px 5px 0;
}
fieldset.example:before {
content: "\0260E";
width: 30px;
border: 1px solid red;
display: inline-block;
float: left;
position: relative;
background: red;
color: white;
text-align: center;
line-height: 33px;
border-radius: 5px 0 0 5px;
}
LIVE EXAMPLE
http://codepen.io/KarlDoyle/pen/grRrwG
This is how I would have solved it with less code as comment suggested:
(Do not evauluate the design)
.input-field {
/* And border and so on... */
background-color: #f00;
box-sizing: border-box;
padding-left: 2em;
position: relative;
}
.input-field:before {
content: "X"; /* Use this if the icon comes from a font,
or relpace it with a space and then use the background-image property */
position: absolute;
left: 0;
width: 2em; /* Just to center the padding */
text-align: center;
font-size: 1em; /* For the scalability */
}
.input-field > input {
width: 100%;
font-size: 1em;
}
/* This is just for play, to test the scaleability */
.fill-row {
width: 100%;
}
.big {
font-size: 2em;
}
.short {
max-width: 160px;
}
<div class="input-field fill-row">
<input />
</div>
<div class="input-field big short">
<input />
</div>
<div class="input-field short">
<input />
</div>

changing the Style of Radio buttons in jQuery mobile 1.4.0

I have the Following Radio buttons in my jQuery mobile app , I need to style them as the Radio button in the image bellow . I have tried the following css but it didn't give me the same result , Please Help me ..
Html
<div data-role="page">
<div data-role="header" data-theme="b" style="height:63px;">
</div>
<div data-role="content">
<form>
<fieldset>
<input type="radio" id="Male" value=" Male" name="radio-group-1" />
<label for="Male" data-inline="true" style="background:transparent !important;">Male </label>
<input type="radio" id="Female" value=" Female" name="radio-group-1" />
<label for="Female" data-inline="true" style="background:transparent !important;" >Female </label>
</fieldset>
</form>
</div>
</div>
CSS
input[type="radio"] {
display: none;
}
.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
width: 25px;
height: 25px;
}
.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
margin-top: -18px;
margin-left: -38px;
}
.ui-btn.ui-radio-on:after{
width: 55px;
height: 55px;
background: green !important;
background-size:100px 24px;
}
This is what i get
To get a green inner circle with transparent around it and a border after that, you really need 2 circles. This could be achieved by adding a :before element as well as the :after element in CSS.
Here is a DEMO
The CSS makes the whole button 56px tall and vertically centers the text by making the line-height the same. When off, the radio image is 26x26 with a gray border. When on, the :before css adds a new 26x26 empty circle with a border while the :after css creates a smaller green circle in the center. NOTE: you may need to tweak sizes and margins to get your desired results.
input[type="radio"] {
display: none;
}
.ui-radio label {
height:56px;
line-height: 56px;
padding-left: 50px;
}
.ui-radio .ui-btn.ui-radio-off:after {
background-image: none;
width: 26px;
height: 26px;
border: 2px solid #6E7983;
margin-top: -13px;
}
.ui-radio .ui-btn.ui-radio-on:after {
background-color: #86D51C;
width: 14px;
height: 14px;
margin-top: -6px;
margin-left: 10px;
border: 0;
}
.ui-radio .ui-btn.ui-radio-on:before {
content:"";
position: absolute;
display: block;
border: 2px solid #6E7983;
border-radius: 50%;
background-color: transparent;
width: 26px;
height: 26px;
margin-top: 14px;
margin-left: -39px;
}

Two inputs next to each other with box-shadow

I'm trying to add a box shadow on two inputs next to each other, but the shadows are overlapping the inputs.
I've tried to add a position: relative and z-index to the inputs, but then the shadow overlap the input with the lowest z-index.
Is there a way to prevent the shadow from overlapping the other input next to it?
HTML:
<form method="post">
<input name="email" type="text" >
<input name="send" type="submit">
</form>
CSS:
.email {
height:45px;
width: 395px;
float: left;
box-shadow: 0 0 40px 6px rgba(0,0,0,0.65);
-webkit-appearance: none;
}
.search {
height: 45px;
width: 60px;
float: right;
box-shadow: 0 0 40px 6px rgba(0,0,0,0.65);
cursor: pointer;
-webkit-appearance: none;
}
Here is an example of what i mean:
Thanks :)
- Jesper
You have to wrap the two inputs into divs :
<form method="post">
<div class="input--email">
<input name="email" type="text" class="email">
</div>
<div class="input--search">
<input name="send" type="submit" class="search">
</div>
</form>
And give them the same shadows :
.input--email, .input--search {
float: left;
box-shadow: 0 0 40px 6px rgba(0,0,0,0.65);
height: 45px;
}
.input--email{
width: 395px;
}
.input--search{
margin-left: 15px;
width: 60px;
}
.email, .search {
width: 100%;
height: 100%;
position: relative;
-webkit-appearance: none;
}
.search {
cursor: pointer;
}
Here is a fiddle : http://jsfiddle.net/VLy6Q/

Resources