Image border hover won't work - html

I have an image centered on the screen that I would like a border around, which when hovered over changes color. I am trying to do this as you can see in the code below, but the problem is that the image just keeps being a link but no border, what is wrong?
html code:
<div id="container">
<div id="content">
<div class="10Img">
<img src="10Pimg.png" alt="10img" style="width:900px; height:200px">
</div>
</div>
</div>
css code:
#content{
padding-bottom: 200px;
position: absolute;
float: left;
left: 50%;
margin-left: -450px;
top: 200px;
}
#container{
height:100%;
}
.10Img{
border: 2px solid grey;
}
.10Img a:hover{
outline: 2px solid black;
}

The main issue is you are starting your class name with a numerical character change 10Img and start it with an alphabetic character.
Ex. i change it from 10Img to aImg
Then you can use
.aImg img {
border: 2px solid grey;
}
or only
.aImg {
border: 2px solid grey;
}

Try this: Demo
a img {
border: 2px solid grey;
}
a img:hover {
border: 2px solid black;
}

See This Demo
.Img{border: 2px solid grey;}
.Img a:hover{
outline: 2px solid black;}
Note: Class Name can not start with integer.
Refer This for Rules regarding naming.

Your css class 10Img doesn't work, because css class names must not begin with a number, see:
Which characters are valid in CSS class names/selectors?
So if you call your class Img10 instead of 10Img it should work.
<div id="container">
<div id="content">
<div class="Img10">
<img src="http://dummyimage.com/900x200/000/fff" alt="10img" style="width:900px; height:200px" />
</div>
</div>
</div>
Also you may want to have the :hover border on the div instead on the a:
#content{
padding-bottom: 200px;
position: absolute;
float: left;
left: 50%;
margin-left: -450px;
top: 200px;
}
#container{
height:100%;
}
.Img10{
border: 2px solid grey;
}
.Img10:hover{
outline: 2px solid black;
}
Here is a working fiddle:
http://jsfiddle.net/k2Ld7yfe/

Related

How to enable a double dashed border?

When I type this:
<style>
.tavit{
width:400px;
height:300px;
background-color:yellow;
border:dashed; /*First I applied - border:dashed double (In order to get a double dashed border - but it didn't work for some reason*/
border-style:double;
margin:auto;
font-size:medium;
text-align:right;
}
.adom {
color: red;
font-size: xx-large;
text-align: center;
}
</style>
nothing works. Like it's even one or the other. What am I missing?
Thanks
You can simply fix this with one div, you can use outline and border, then use outline-offset property
.test {
background:white;
padding:15px;
border:1px dashed #000;
outline:1px dashed #000;
outline-offset:-5px;
}
<div class="test">see this</div>
There is no border-style as dashed double,
But border-style:double property give two border but as solid lines, so you can use pseudo selector and declare border-style:dashed on both as below,
.tavit {
width: 400px;
height: 300px;
background-color: yellow;
border: dashed;
border-style: dashed;
margin: auto;
font-size: medium;
text-align: right;
position: relative;
}
.tavit:before {
content: "";
width: 94%;
height: 280px;
border-style: dashed;
position: absolute;
left: 2%;
top: 8px;
}
<div class="tavit">
</div>
You can create an outer and inner div and can give border to both of them.
div {
border: 1px dashed black;
}
.outer {
padding: 5px;
}
<div class="outer">
<div class="inner">Long long long text</div>
</div>

How can I position two div elements side by side inside another one?

I would like div#alpha1 and div#alpha2 inside the div#alpha placed side by side.
CODE
#alpha {
position: relative;
padding-top: 4px;
margin-top: 8px;
margin-left: 2%;
margin-right: 2%;
width: 96%;
height: 100px;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
}
#alpha1 {
position: relative;
width: 94px;
height: 94px;
border: 1px solid black;
margin-left: 2%;
}
#alpha2 {
position: relative;
margin-top: 0px;
height: 40px;
border-top: 1px;
border-bottom: 1px solid black;
margin-left: 94px;
}
<DIV id="alpha">
<DIV id="alpha1">
<IMG src="img/jenny.jpg" width="94px" height="94px">
</DIV>
<DIV id="alpha2">
<H1 id="patientname">Jenny Thomas</H1>
</DIV>
</DIV>
you can use flexbox for that by using display:flex in parent and then flex:1 in #alpha2 to make it grow according to screen size
Don't use HTML width/height tags, instead use CSS for styling it.
Note I did a few tweaks to your code.
#alpha {
padding-top: 4px;
margin: 8px 2% 0;
width: 96%;
height: 100px;
border: solid black;
border-width: 1px 0;
display: flex
}
#alpha1 {
width: 94px;
height: 94px;
border: 1px solid black;
margin: 0 2%;
}
#alpha2 {
flex: 1
}
#alpha2 h1 {
border-bottom: 1px solid black;
height: 40px
}
<div id="alpha">
<div id="alpha1">
<img src="//lorempixel.com/94/94" />
</div>
<div id="alpha2">
<h1 id="patientname">Jenny Thomas</h1>
</div>
</div>
The easiest/fastest solution is to assign display: flex to the container #alpha
http://codepen.io/anon/pen/mPgaJP
(I also erased some unneccesary settings in there)
You just needed to set the float property of your div. Here you are :-
#alpha{
position:relative;
padding-top:4px;
margin-top:8px;
margin-left:2%;
margin-right:2%;
width:96%;
height:100px;
border-top:1px solid black;
border-bottom:1px solid black;
float: none;
}
#alpha1{
position:relative;
width:94px;
height:94px;
border:1px solid black;
margin-left:2%;
margin-right: 0px;
float: left;
}
#alpha2{
position:relative;
margin-top:0px;
height:40px;
border-top:1px;
border-bottom:1px solid black;
margin-left:9%;
float: next;
}
<DIV id="alpha">
<DIV id="alpha1">
<IMG src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTvU-f_zys67Kv6hdqJcmSN5n_dfe2igiq9lLZYpcXAyVXEBNQ6" width="94" height="94" alt="IMAGE">
</DIV>
<DIV id="alpha2">
<H1 id="patientname">Jenny Thomas</H1>
</DIV>
</DIV>
I edited your margin in alpha2 for correct display of bottom line. It is displayed correct in browser. Here it is not. You can check it here. Mark the problem solved if it helps.

CSS Help Floating a div to center when enough space

I'm trying to center a div in the web browser when there is enough space. If not it should be collapsed between 2 divs.
This is the collapsed view
And this would be the expanded view
I've tried so many different things but nothing seems to work right. When I get something that looks right, the filterDiv ends up going over the top of titleDiv or buttonDiv or both.
Here's some code that I started with and should represent the collapsed view when the browser isn't very wide.
<style type="text/css">
.controlsDiv{
background-color:yellow;
border: 1px solid black;
}
.titleDiv{
background-color:Red;
width:25em;
height: 5em;
border: 1px solid black;
}
.filterDiv {
background-color: gainsboro;
width: 600px;
height: 10em;
border: 1px solid black;
}
.buttonDiv{
width:25em;
height:5em;
background-color:green;
border: 1px solid black;
}
</style>
<div class="controlsDiv" >
<div class="titleDiv">
<h2>titleDiv</h2>
</div>
<div class="filterDiv">
<h2>filterDiv</h2>
<h2>Centered in Browser Window</h2>
<h2>titleDiv and ButtonDiv Collapsed</h2>
</div>
<div style:clear:both></div>
<div class="buttonDiv">
<h2>buttonDiv</h2>
</div>
</div>
Thank you in advance!
You can always position absolute required div:
<style type="text/css">
.controlsDiv{
background-color:yellow;
border: 1px solid black;
}
.titleDiv{
background-color:Red;
width:25em;
height: 5em;
border: 1px solid black;
}
.filterDiv {
background-color: gainsboro;
width: 600px;
height: 10em;
border: 1px solid black;
}
#media(min-width: 900px) {
.filterDiv {
position: absolute;
left: calc(50% - 300px);
top: 0;
}
}
.buttonDiv{
width:25em;
height:5em;
background-color:green;
border: 1px solid black;
}
</style>

2 separate css classes applied to 1 element

I have a wordpress page, and I would like to add a bottom border to the post, according to the post category.
If post has only 1 category, then I use:
.category-daily {
border-bottom: red solid 3px;
}
But there are posts who have 2 categories, and therefore 2 classes, for example: category-weekly and category-daily
What can I do to add a red bottom border for daily category and after that add a yellow bottom border for weekly category
Elements cannot have two borders..but you can fake it with a pseudo-element.
body {
text-align: center;
}
div {
height: 100px;
width: 150px;
display: inline-block;
box-shadow: inset 0 0 1px 0 black;
/* for demo purposes only */
padding-bottom: 6px;
position: relative;
}
.category-daily:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-bottom: red solid 3px;
}
.category-weekly:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-bottom: yellow solid 3px;
}
.category-daily.category-weekly:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-top: red solid 3px;
border-bottom: yellow solid 3px;
}
<div class="category-daily"></div>
<div class="category-weekly"></div>
<div class="category-daily category-weekly"></div>
There is no possibility to define more than one border bottom.
If you wish to achive such visual result you have to add an extra element for each category you're applying.
For example with div element for each category:
html
<div class="post">
<div class="daily"></div>
<div class="weekly"></div>
</div>
css
.post .daily{
background:red;
height:1px;
width:100%;
}
.post .weekly{
background:yellow;
height:1px;
width:100%;
}
Or even better: a hr for each category
html
<div class="post">
<hr class="daily"/>
<hr class="weekly" />
</div>
css
.post .daily{
background-color:red;
color:red;
border:0;
height:1px;
}
.post .weekly{
background-color:yellow;
color:yellow;
border:0;
height:1px;
}
One option is to use box-shadow for the other border, like this:
.daily {
border-bottom: 3px solid red;
}
.weekly {
box-shadow: 0 3px 0 yellow;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="daily">This is daily</div>
<div class="daily">This is daily</div>
<div class="weekly">This is weekly</div>
<div class="daily">This is daily</div>
<div class="daily weekly">This is daily and weekly</div>
<div class="weekly">This is weekly</div>
<div class="daily">This is daily</div>
</body>
</html>
You can't have two border-bottoms, but if you're comfortable with jquery, this may work for you:
$('.category-daily.category-weekly').wrap('<div class="bbottom"></div>');
div{
width: 60px;
height: 60px;
}
.category-daily.category-weekly {
border: 1px solid black;
border-bottom: 9px solid red;
}
.category-daily{
border: 1px solid black;
border-bottom: 9px solid red;
}
.category-weekly {
border: 1px solid black;
border-bottom: 9px solid yellow;
}
.bbottom{
padding-bottom: 9px;
border-bottom: 9px solid yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div class='category-daily category-weekly'>
</div>
<br>
<div class='category-daily'>
</div>
<br>
<div class='category-weekly'>
</div>
This wraps a div with both classes with another div which contains the secondary border-bottom.

How can I centre each text element within each <div> both vertically and horizontally, so that the text is exactly in the middle

I am trying to create nine circles, with a picture of a person in each, with the name of the indidvidual directly in the middle of each picture. Below is my HTML and CSS file. I have tried using text-align: centre however it does not look accurate? Also, it only move the text horizontally and not vertically, i.e not to the center of the image, only to the center of the TOP of the image. Thank you.
<div class="friend">Stacey</div>
<div class="Sexy">Caroline</div>
<div class="friend"; id="best_friend">Adam</div></br>
<div class="boss">Paul</div>
<div class="friend">Phil</div>
<div class"colleague"; id="archnemesis">Luca</div>
<div class="friend">Ruth</div>
<div class="family">Mum</div>
<div class="enemy">Satan</div>
</body>
**My CSS file below:**
div {
display: inline-block;
margin-left: 5px;
border: 2px solid black;
border-radius: 100%;
height: 100px;
width: 100px;
text-align: center;
}
.friend {
border: 2px dashed #008000;
}
.family {
border: 2px dashed #0000FF;
}
.enemy {
border: 2px dashed #FF0000;
}
.colleague {
border: 2px solid brown;
}
.boss {
border: 5px solid pink;
}
.sexy {
border-color: purple;
}
#best_friend {
border: 4px solid #00C957;
}
#archnemesis {
border: 4px solid #CC0000;
}
<html>
<head>
<style>
div {
display: inline-block;
margin-left: 5px;
border: 2px solid black;
border-radius: 100%;
height: 100px;
width: 100px;
text-align: center;
}
span.center-content {
display: inline-block;
vertical-align: middle;
line-height:100px;
}
.friend {
border: 2px dashed #008000;
}
.family {
border: 2px dashed #0000FF;
}
.enemy {
border: 2px dashed #FF0000;
}
.colleague {
border: 2px solid brown;
}
.boss {
border: 5px solid pink;
}
.sexy {
border-color: purple;
}
#best_friend {
border: 4px solid #00C957;
}
#archnemesis {
border: 4px solid #CC0000;
}
</style>
</head>
<body>
<div class="friend"><span class="center-content ">Stacey</span></div>
<div class="Sexy"><span class="center-content ">Caroline</span></div>
<div class="friend"; id="best_friend"><span class="center-content ">Adam</span></div></br>
<div class="boss"><span class="center-content ">Paul</span></div>
<div class="friend"><span class="center-content ">Phil</span></div>
<div class="colleague"; id="archnemesis"><span class="center-content ">Luca</span></div>
<div class="friend"><span class="center-content ">Ruth</span></div>
<div class="family"><span class="center-content ">Mum</span></div>
<div class="enemy"><span class="center-content ">Satan</span></div>
</body>
</html>
Changes
Added a new span and common class to all spans - center-content
added new class in style - span.center-content
You will need to keep same height for div and span to get it in the middle of each div.
Either you can test the code above on your browser or else visit this demo url - https://jsfiddle.net/BRxKX/4962/
You probably want something along the lines of:
<div style="display:table;">
<div style="display:table-cell;vertical-align:middle;">
<div style="margin-left:auto;margin-right:auto;"></div>
</div>
</div>
This may be of help in the future http://howtocenterincss.com
You could use vertical-align:middlebut that requires to be a table and you can spoof it using display:table-cell.
I suggest to use line-height with the height of the circles, this works with only 1 line of text, if you one multiline you have to use internal divs or spans.
If if doesn't look accurate horizontally may be the padding.
div {
display: inline-block;
margin-left: 5px;
border: 2px solid black;
border-radius: 100%;
height: 100px;
width: 100px;
text-align: center;
padding:0;
line-height:100px;
}