I made a CSS code, which changes style properties two other html elements, with events.
When a check box is checked, I want to change background colour of a label box and a div tag. And when I uncheck the check box, the background colour must be toggled with the previous.
The code is working on changing css properties of label tag. But not working for div tag.
Here is the CSS:
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked + label
{
background: #0080FF;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked ~ #menu_content
{
height:100vh;
width:25vh;
position:fixed;
left:0;
top:11%;
background-color:#41a3d8;
}
input[type=checkbox]:not(:checked) ~ #menu_content
{
height:100vh;
width:25vh;
position:fixed;
left:0;
top:11%;
background-color:#fff;
border-style:solid;
border-width:1px 1px 1px 1px;
}
Here is the html code:
<div id="header">
<span id="nav_button">
<input type='checkbox' name='thing' id="thing"/>
<label for="thing">
</label>
</span>
<span id="title">
<TITLE>
</span>
</div>
<div id="menu_content">
<p id="menu_head">
Nav
</p>
<a href="#" id="menu_links">
Link1
</a>
<a href="#" id="menu_links">
Link2
</a>
<a href="#" id="menu_links">
Link3
</a>
</div>
I'm trying to do this, without using any kind of scripts
The ~ selectors only works with it siblings, so I would recommend making the div a sibling of the checkbox like the example.
input[type=checkbox] {
display:none;
}
input[type=checkbox] + label
{
background: #999;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked + label
{
background: #0080FF;
height: 16px;
width: 16px;
display:inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked ~ #menu_content
{
height:100vh;
width:25vh;
position:fixed;
left:0;
top:11%;
background-color:#41a3d8;
}
input[type=checkbox]:not(:checked) ~ #menu_content
{
height:100vh;
width:25vh;
position:fixed;
left:0;
top:11%;
background-color:#fff;
border-style:solid;
border-width:1px 1px 1px 1px;
}
<div id="header">
<span id="nav_button">
<input type='checkbox' name='thing' id="thing"/>
<label for="thing">
</label>
<div id="menu_content">
<p id="menu_head">
Nav
</p>
<a href="#" id="menu_links">
Link1
</a>
<a href="#" id="menu_links">
Link2
</a>
<a href="#" id="menu_links">
Link3
</a>
</div>
</span>
<span id="title">
<TITLE>
</span>
</div>
Another option would be using Js..
or with pure css will be using css selectors in the url using :target() https://stackoverflow.com/a/9442590/2894798 (haven't tried...)
As you can see, the first two CSS rules work as desired, but the other ones don't. The reason is that label is a sibling to that input and follows directly after that input, which the + in the CSS selector corresponds to.
But #menu_content is not a sibling (as ~ would require) , it's two levels higher.
You won't be able to do this without a script, there are no CSS methods to select ancestors.
input[type=checkbox]+label {
background: #999;
height: 16px;
width: 16px;
display: inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked+label {
background: #0080FF;
height: 16px;
width: 16px;
display: inline-block;
padding: 0 0 0 0px;
}
input[type=checkbox]:checked~#menu_content {
height: 100vh;
width: 25vh;
position: fixed;
left: 0;
top: 11%;
background-color: #41a3d8;
}
input[type=checkbox]:not(:checked)~#menu_content {
height: 100vh;
width: 25vh;
position: fixed;
left: 0;
top: 11%;
background-color: #fff;
border-style: solid;
border-width: 1px 1px 1px 1px;
}
<div id="header">
<span id="nav_button">
<input type='checkbox' name='thing' id="thing"/>
<label for="thing">
</label>
</span>
<span id="title">
<TITLE>
</span>
</div>
<div id="menu_content">
<p id="menu_head">
Nav
</p>
<a href="#" id="menu_links">
Link1
</a>
<a href="#" id="menu_links">
Link2
</a>
<a href="#" id="menu_links">
Link3
</a>
</div>
Related
I am trying to show a tick mark on top of the image when a user clicks on it. I have an input radio button element and label both wrapped in anchor element and inside the label i have and an image element and i use css to apply tick mark. Whenever i click on the image nothing happens. Please i would appreciate if anyone can help. Here is the snippets
.icon {
margin: 5px 0;
}
.icon input {
display: none;
}
.icon img {
vertical-align: middle;
width: 50%;
border: 2px solid greenyellow;
}
.icon input:checked {
background: rgba(0,0,0,0.5);
}
.icon input:checked::after{
content: '✔';
position: absolute;
top: 50%;
left: 50%;
width: 30px;
height: 30px;
transform: translate(-50%, -50%);
color: black;
font-size: 20px;
text-align: center;
border: 1px solid black;
border-radius: 50%;
}
<div class="row">
<a href="#" class="col-sm-4 icon">
<input type="radio" name="selimg" id="selimg1">
<label for="selimg1">
<img src="./images/baby-bottle.png">
</label>
</a>
<a href="#" class="col-sm-4 icon">
<input type="radio" name="selimg" id="selimg2">
<label for="selimg2">
<img src="./images/badge.png">
</label>
</a>
<a href="#" class="col-sm-4 icon">
<img src="./images/cardiologist.png">
</a>
</div>
::before and ::after only work on container elements, so you can not use that on your inputs.
Instead of .icon input:checked::after try using .icon input:checked + label::before.
(The rest of your CSS needs adjustments to make it show how you want, but this will at least make it show up and you can move it where it needs to be)
.icon {
margin: 5px 0;
}
.icon input {
display: none;
}
.icon img {
vertical-align: middle;
width: 50%;
border: 2px solid greenyellow;
}
.icon input:checked {
background: rgba(0, 0, 0, 0.5);
}
.icon input:checked + label::before {
content: '✔';
position: absolute;
top: 50%;
left: 50%;
width: 30px;
height: 30px;
transform: translate(-50%, -50%);
color: black;
font-size: 20px;
text-align: center;
border: 1px solid black;
border-radius: 50%;
}
<div class="row">
<a href="#" class="col-sm-4 icon">
<input type="radio" name="selimg" id="selimg1">
<label for="selimg1">
<img src="./images/baby-bottle.png">
</label>
</a>
<a href="#" class="col-sm-4 icon">
<input type="radio" name="selimg" id="selimg2">
<label for="selimg2">
<img src="./images/badge.png">
</label>
</a>
<a href="#" class="col-sm-4 icon">
<img src="./images/cardiologist.png">
</a>
</div>
I've created a left navigation bar using buttons. I'm trying to reduce the hyperlink area to just the background image. Also, another issue I'm having is the elements overlaying the background image are taking precedence over the hyperlink, so the button is not actually clickable. Page for reference
http://www.auburn.edu/administration/facilities/home-page/index.html
Hyperlink area
Here's the background image area
.img-responsive {
display: block;
padding: 0;
margin: 0;
}
.background:hover .head {
color: #d76e08;
}
.overlay {
position: absolute;
z-index: 1;
top: 0;
left: 0;
color: white;
}
.icon {
padding-top: 15px;
padding-left: 40px;
}
.head {
margin-top: -75px;
padding-left: 120px;
}
.content {
margin-top: -5px;
padding-left: 120px;
padding-right: 35px;
}
<div class="row">
<div class="col-sm-12">
<div class="background">
<a href="../Collin/misc/issues/index.html">
<img alt="background" class="img-responsive" src="buttons/images/button.png" />
</a>
<div class="overlay">
<div class="icon">
<img alt="test" class="img-responsive" src="buttons/images/info-icon.png" />
</div>
<p class="head">Ask Facilities</p>
<p class="content">Here will be text about the button. .</p>
</div>
</div>
</div>
</div>
I'm trying to reduce the hyperlink area to just the background image.
Your markup is incredibly complex for what you are displaying.
You could have something like:
<ul>
<li>
<a>
<h2></h2>
<p></p>
</a>
</li>
<li>
<a>
<h2></h2>
<p></p>
</a>
</li>
</ul>
and add the image and the gradient using CSS.
I would use a single link tag for your button and leverage CSS gradients for the background:
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
}
.button {
background-image: linear-gradient(to bottom, #3D85C6, #07355F 50%, #07355F);
background-size: 100% 200%;
border-radius: 4px;
color: #fff;
display: block;
padding: 10px;
text-decoration: none;
transition: all 150ms ease-in-out;
}
.button:hover,
.button:focus,
.button:active {
background-position: 0 50%;
}
.button-icon {
float: left;
margin-right: 15px;
}
.button-content {
overflow: hidden;
}
.button-title {
font-size: 18px;
font-weight: bold;
}
.button-description {
font-size: 16px;
}
<a class="button" href="../Collin/misc/issues/index.html">
<div class="button-icon">
<img src="http://satyr.io/72/white?brand=github" alt=""/>
</div>
<div class="button-content">
<p class="button-title">Ask Facilities</p>
<p class="button-description">Here will be text about the button…</p>
</div>
</a>
Also here http://jsbin.com/rikisemawe/edit?html,css,output
The elements in OP were stacked in the markup, there were no nested components of the button. That would explain the unusual position coords and large padding.
Instead of <img>, background-image is used. Changed some of the tags to a real <button>, <h4> instead of <p>, etc.
SNIPPET
.button {
position: relative;
min-width: 350px;
max-width: 100%;
min-height: 95px;
height: auto;
padding: 5px 10px;
border: 0 none transparent;
border-radius: 6px;
background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/button.png)no-repeat;
background-size: cover;
}
.background:hover .head {
color: #d76e08;
}
.text {
padding: 0 5px;
position: absolute;
left: 85px;
top: 5px;
text-align: left;
color: #def;
text-decoration: none;
}
.button:hover,
.text:hover {
text-decoration: none;
color: #def;
}
.button:hover .head {
color: gold;
}
.icon {
width: 75px;
height: 75px;
position: absolute;
top: calc(50% - 37.5px);
background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/service-icon.png)no-repeat;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-sm-12">
<button class="button">
<div class="icon"></div>
<a class='text'>
<h4 class="head">Ask Facilities</h4>
<p class="content">Here will be text about the button.</p>
</a>
</button>
</div>
</div>
I want to add a profile icon at the top right corner that should have 'My account' and 'logout' as options like shown in the image.Please let me know how can i add it to the below code.
<style type="text/css">
ul {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
}
#nav {
display: table;
table-layout: fixed;
text-align: center;
}
#nav li {
display: table-cell;
width: 25%;
padding-right: 1px;
height: auto;
vertical-align: bottom;
}
#nav a {
display: block;
min-height: 100%;
padding: 12px 50px;
background-color: #222;
color: white;
border-radius: 6px 6px 0 0;
}
.logoutLblPos{
position:fixed;
right:10px;
top:5px;
}
</style>
<body>
<div class="container">
<div class="row">
<div class="col-sm-5 col-sm-push-3 col-xs-4 col-xs-push-2">
<h1 class="text-center" style="font-family:Colonna MT;font-size:50px;color:ForestGreen ;">Welcome</h1>
<p class="lead text-center" style="font-size:20px;color:DarkSalmon;"><i>"This is caption"</i></p>
<label class="logoutLblPos">
<span class="glyphicon glyphicon-user" style="height:50px;width:20px"></span> User
<input name="submit2" type="submit" id="submit2" value="log out">
</label>
<ul id="nav">
<li>Home</li>
<li> tab2</li>
<li>tab3</li>
<li>tab4</li>
</ul>
</div>
</div>
</div>
</div>
Also, I need to include "Post your Ad' beside profile icon.
Please see example fiddle
HTML
<div style="background:color:#fff; border:solid 1px #333; float:left; text-align:center; padding:5px;">
<i class="fa fa-user"></i><br>
User
</div>
(The title might sound stupid but I don't know how to put it more sophisticated.)
As you can see in the follwing screenshots, I have 3 stacked divs.
<div class="col-xs-3">
<div class="center-horizontal-inline">
<a class="upvote" href="#" data-id="iZheLNnewWtMhPTQd">
</div>
<div class="score">
115
<span class="badge score-diff vertical-align"> +5 </span>
</div>
<div class="center-horizontal-inline">
</div>
The one in the middle contains the number (115). The other two the vote-arrows. For the one containing the number, I want to add a "badge" (in bootstrap context) right next to the number, let's say to the right. You can see my attempt shining through the colored overlay.
The goal is to leave the number centered respectively to the arrow-icons, while placing the badge with an offset (or "right next to") respectively to the number.
My attempt was to set a float: right; for the badge, but as you can see, the number has an offset now. When I try position: absolute; on the badge, there is no offset (as wanted), but I can't get the badge right next to the number, I can only attach it to the right border because I don't have the number as positioning-reference anymore.
Hope my explanation was clear enough. I also didn't know how to search for that problem...
EDIT 1:
As I want it to look like (positioning-wise):
Here we go, using relative and absolute positions together:
DEMO: http://jsfiddle.net/1qbo7uwn/
HTML
<div class="score">
<span class="score-wrap">
<span class="score-main">123</span>
<span class="score-diff">8</span>
</span>
</div>
CSS
.score {
width: 80px;
border: 2px solid blue;
padding: 10px 0;
text-align: center;
}
.score-wrap {
display: inline-block;
position: relative;
}
.score-main {
border: 2px solid green;
}
.score-diff {
position: absolute;
border: 2px solid red;
left: 100%;
top: -2px;
}
Added some span tags in the HTML.
EDIT: vertical align of everything, by setting line height.
http://jsfiddle.net/1qbo7uwn/1/
As you said you are okay with HTML modification. Here's my attempt:
Demo Fiddle
HTML
<div class="wrap">
<div class="vote up">
<i class="fa fa-angle-up"></i>
</div>
<div class="stat">
<span class="score">115
<span class="badge">+5</span>
</span>
</div>
<div class="vote inactive">
<i class="fa fa-angle-down"></i>
</div>
</div>
CSS
.wrap{
margin: 100px;
text-align:center;
}
.vote{
font-size:36px;
}
.up{
color:green;
}
.down{
color:red;
}
.inactive{
color:gray;
}
.score{
position: relative;
display:block;
padding: 5px 0;
}
.badge{
background: #eee;
padding:5px 10px;
border-radius: 30px;
position: absolute;
top:0;
margin-left:10px;
}
Try
Demo: http://jsfiddle.net/tamilcselvan/rjv1xxo2/1/
.center-horizontal-inline {
font-size: 2em;
text-align: center;
}
.score {
text-align: center;
}
.score:after {
content:attr(data-badge);
position: absolute;
margin-left: .4em;
font-size: x-small;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: 700;
line-height: 1;
color: #FFF;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
background-color: #777;
border-radius: 10px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-3">
<div class="center-horizontal-inline vote"> <i class="glyphicon glyphicon-chevron-up"></i>
</div>
<div class="score" data-badge="+5">115</div>
<div class="center-horizontal-inline"> <i class="glyphicon glyphicon-chevron-down"></i>
</div>
</div>
I'll provide CSS and HTML sources first.
jsFiddle
The live example is here
The problem is, h2 texts are not visible unless I do z-index: -1; on images. It makes the text appear, however, then the image is being lost and I look at body background.
There is not something touching z-index values except the fixed navigation bar at top.
What may be causing this, can you have a look?
Ps. Writing z-index: 2; on H2 tags doesn't work either.
If you want z-index:2 on <h2> works, you should add position:relative; or position:absolute; or position:fixed.
You can see z-index
i change your HTML & CSS
change in HTML: Move img into a tag
<div class="spotlight-area">
<div class="spotlight">
<div class="spotlight-item width-2 height-2">
<a href="#" class="spotlight-info">
<h2 class="large">
Random text
</h2>
<img src="http://www.sobafire.com/__v2/themes/default/images/news/spotlight-big.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
</a>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
</div>
</div>
css:
change On CSS: Remove position: absolute; From img and ADD It TO .spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 Remove padding From .spotlight-area .spotlight-info { and Add Margin to .spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 with similar value
.spotlight-area {
width: 790px;
margin: 0px auto;
padding: 0px;
}
.spotlight-area img, .spotlight-area embed {
max-width: 100%;
height: auto;
min-height: 50px;
}
.spotlight-area .spotlight {
display: block;
border-top: 1px solid #3b3b3b;
border-left: 1px solid #3b3b3b;
float: left;
margin-bottom: 4px;
}
.spotlight-area .spotlight .width-1 { width: 262px }
.spotlight-area .spotlight .width-2 { width: 525px }
.spotlight-area .spotlight .height-1 { height: 174px }
.spotlight-area .spotlight .height-2 { height: 349px }
.spotlight-area .spotlight .spotlight-item {
float: left;
position: relative;
border-bottom: 1px solid #3b3b3b;
border-right: 1px solid #3b3b3b;
overflow: hidden;
}
.spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 {
color: #ffc203;
}
.spotlight-area .spotlight .spotlight-item img {
width: 100%;
height: 100%;
top: 0;
left: 0;
margin: 0;
border: 0;
z-index: -1; /* tricky part */
}
.spotlight-area .spotlight-info {
display: block;
height: 100%;
min-height: 50px;
}
.spotlight-area .spotlight-info a {
display: block;
height: 100%;
min-height: 50px;
padding: 20px;
}
.spotlight-area .spotlight .spotlight-item .spotlight-info h2 {
display: inline-block;
max-width: 480px;
font-size: 30px;
line-height: 32px;
color: #f0f0f0;
position: absolute;
margin:20px;
}
in My Test This Change work