I'm trying to build a HTML/CSS periodic table. I have this as my HTML code:
<div id="Hydrogen">
<p>1</p>
H
Hydrogen
1.00794
</div>
and this is my CSS code:
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
padding: 100px;
font-size: 13px;
}
#hydrogen {
background: #fff;
margin: 0 auto;
width: 50px;
padding: 30px;
text-align: center;
/* border-radius */
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
/* box-shadow */
-webkit-box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
-moz-box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
box-shadow: rgba(0,0,0,0.2) 0px 1px 3px;
position: absolute;
}
How do I target the <p>1</p> tag in my #hydrogen ID? Basically, I want to display a 1 on the top-left corner of the div cell. Also, is this the best method of doing this, or is there a easier way?
If it’s the only p element within that div, then sinply
#Hydrogen p { … }
Otherwise, if it’s the first one,
#Hydrogen p:first-child { … }
This are absolute CSS selector basics – so you should perhaps read some tutorials on that matter.
Something along the lines of
#hydrogen p { position:absolute; left:0; top:0;}
should get you started.
You can also use the command "span".
Example:
<p><span>1</span></p>
CSS:
span { font-size:14; }
You can expend this code with "id" or "class".
ID-Example:
<p><span id="name">1</span></p>
CSS:
#name { font-size:14; }
Class-Example:
<p><span class="large">1</span></p>
CSS:
.large { font-size:14; }
There is nothing wrong with:
#hydrogen p{..}
but as you said you want to do periodic table so you will have 103 elements so than for every p-element you will have to write:
#hydrogen p{..}
#helium p{...}
#lithium p{...}
... and so 103 times, same thing with divs with Id's
Better solution would be to give p and div class name
.atomic-number{...}
.grid-cell{...}
<div class="grid-cell">
<p class="atomic-number">1</p>
H
Hydrogen
1.00794
</div>
You can style all elements with just two lines of CSS
EDIT
Create rows, and position elements inside them.
For example float all grid cells left, if you need something to stick on the right side add class="right" (1st row) you probably will have to change colours same way, also you can create invisible cells and fill space with them (2nd row)
http://fiddle.jshell.net/tH7Pq/1/
If you want you can read more about classes, id's and selectors here:
Id's and classes
multiple classes
child-and-sibling
Related
I have two elements (<a> and <button>), both of which are sharing the same classes from Tachyons:
<a class="f4 br2 fw9 pa3 bg-dark-blue white link db tc lh-solid fixed left-1 bottom-1 right-1 mla mra z-1 " href="/edit-profile/photos"
>Confirm account</a>
<button class="f4 br2 fw9 pa3 bg-dark-blue white link db tc lh-solid fixed left-1 bottom-1 right-1 mla mra z-1 " type="submit">Next</button>
The expected behaviour is that they will both be the same width, and yet they're different (despite the same styles).
Any idea what's going on here?
Here's a Codepen demonstrating the issue.
In your particular case the button has a border and a different font, which is a default style for your browser. Each browser have it's own defaults for every type of elements, that's why a button and a link would look the way they do without any styling. In a matter of fact it isn't right to say "without any styling", it is rather "without any additional styling":
<button>I'm a button</button>
I'm a link
I didn't go through all the css you have, because you have 17 classes for a single element and I'm too lazy for it, but it actually possible to have different styles for different elements with a common class:
.awesome {
display: inline-block;
border: 5px solid;
width: 200px;
box-sizing: border-box;
padding: 20px;
text-align: center;
margin: 10px 0 10px 10px;
font-family: Arial, serif;
}
div.awesome {
background-color: deepskyblue;
border-color: royalblue;
font-style: italic;
color: darkslateblue;
}
span.awesome {
background-color: orangered;
border-color: firebrick;
font-weight: bold;
color: gold;
}
<div class="awesome">I'm a div</div>
<span class="awesome">I'm a span</span>
I add some content to a span-element with ::after as a sort of tooltip.
As that after-content is bigger then the span-element itself and it's not within the span-elements boundary, it is not clickable.
I'd need to make the after-elements (or its boundaries) clickable too. How could I do that?
I guess it's not so important but here is the ::after-"code":
span.link_wer::after{
content:'What is it actually?';
vertical-align:1.8em;
font-size:0.2em;
margin-left:-80px;
border-bottom: 1px solid $color_3;
padding:5px 10px;
background:red;
transition:0.3s;
opacity:0.2;
}
And here is the markup
<h3>We can move <span class="link_wer">it<span> easily.</h3>
So I get sort of tooltip over the word "it" and while "it" triggers a link, the after-content "What is it actually?" doesn't as it is intentionally lying off its parent elements boundary. What can I do to solve that?
Pseudo-elements belong to their parents, so if their parent is clickable (button, a) then you can make them clickable. So, what you could do is make that pseudo-element of a than span.
span.link_wer a {
position: relative;
text-decoration: none;
color: red;
}
span.link_wer a::after{
content:'What is it actually?';
vertical-align:1.8em;
font-size:0.2em;
margin-left:-80px;
border-bottom: 1px solid red;
padding:5px 10px;
background: rgba(255, 0, 0, 0.5);
transition:0.3s;
color: white;
font-size: 10px;
}
As always, things are pretty simple once you're trying. Of course the organisation of my markup was wrong. So if you actually do
<h3>We can move <span class="link_wer">it<span> easily.</h3>
instead of
<h3>We can move <span class="link_wer">it<span> easily.</h3>
by swapping href and span (or which ever element you're using as the container for the :after or :before-content) you're good to go. Which makes sense.
Try like this. I have just changed your markup and CSS property a bit. I hope this will help you.
span.link_wer::before{
content:'What is it actually?';
vertical-align:1.8em;
font-size:0.5em;
border-bottom: 1px solid $color_3;
padding:5px 10px;
background:red;
transition:0.3s;
opacity:0.2;
position: absolute;
top: 3px;
color: aqua;
}
#target_options {
position:relative;
}
<h3>We can move <span class="link_wer">it<span> easily.</h3>
I have the following badge that I can add to any element:
.notification-badge {
position: relative;
}
.notification-badge:after {
content:attr(data-badge);
position:absolute;
top:-10px;
right:-10px;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: 700;
line-height: 1;
background-color: $brand-danger;
color: #fff;
text-align: center;
white-space: nowrap;
vertical-align: middle;
border-radius: 10px;
border: 2px solid #fff;
}
It's fairly straightforward, the element that I attach the badge class onto provides a data-badge attribute with some number, which gets shoved into the :after element's content.
I would like the badge to not appear at all if content is empty. I've tried using the :empty selector, but it doesn't work because the actual tag may still contain other elements, for instance:
<a href="/cart" class="notification-badge" data-badge="">
<i class="fa fa-shopping-cart"></i>
</a>
In this case, I'd want the shopping cart icon and link to still exist, but have the notification-badge class not render the badge.
So, I suppose I could give up on the idea of it being a pure pseudo element and just make it a span with the number inside of it instead of a data- attribute, but it seems like there is probably an easy way to do this that I'm just not aware of.
This works for me:
.notification-badge:after {
visibility: hidden;
}
.notification-badge[data-badge]:after {
visibility: visible;
}
The :empty selector selector matches every element that has no children (including text nodes) W3Schools
So what you could do is here do something like this:
.notification-bade .fa-shopping-cart {visibility:visible}
.notification-badge:after {
content:attr(data-badge); visibility: hidden
}
I am basically trying to do THIS with a paragraph that contains text-indent, but can't get it because the display:inline won't allow text-indent. Any ideas?
Using pseudo elements
I've created a JSFiddle example that uses span elements which are inline and then adds before and after pseudo elements to add additional spacing in front and at the end of each highlighted block of text.
In case you need to manipulate amount of that space adjust font-size within those pseudo elements and you should be good to go.
The trick is just:
.highlight {
font-family: Helvetica, Sans-serif;
font-size: 48pt;
font-weight: bold;
text-transform: uppercase;
}
.highlight:before,
.highlight:after {
/* no-breaking-space (nbsp) entity */
content: "\00a0";
}
Controlling space amount
Using appropriate character(s) in :before and :after pseudo elements one can actually control amount of added spacing down to individual pixels.
The best way is to use thin space which is in typographical terms 1/5 or sometimes 1/6 of an em. If we set font-size of these two pseudo elements to 6 pixels thin space should always approximate to 1 pixel width regardless of dimension discrepancies.
.highlight:before,
.highlight:after {
content: "\2009";
font-size: 6px;
}
Upper style definition will add 1 pixel of space on each side. If we put 5 thin spaces in content, we'd get 5 pixel space...
Or use one thin space and add padding to it and control its width this way. Or even abolish any content and just use padding:
.highlight:before,
.highlight:after {
content: "";
padding: 0 5px; /* will give 10px space */
}
However one does it it's possible to control amount of space down to pixel granularity.
Without br tag : demo here : http://jsfiddle.net/korigan/jzm3qu1q/1/
HTML
<div class="wrap">
<p class="highlight">
<span class="text">Amet assumenda atque eos excepturi harum ipsa</span>
</p>
</div>
CSS
.wrap {
width: 150px;
}
.highlight {
color: #fff;
display: inline;
background: blue;
font-size: 25px;
font-weight: normal;
line-height: 1.2;
}
.highlight .text {
padding: 4px;
box-shadow: 4px 0 0 blue, -4px 0 0 blue;
background-color: blue;
box-decoration-break: clone; /* For Firefox */
}
Kindly see this page:
http://www.technodoze.com
See the Button in the Categories on the right side of the page.
See the word Tips and Tricks.
Problem 1:
It is expanded in whole the column .
The problem is: I want my cell to be expanded just according to the text string but it is looking awkward.
Problem 2:
See the link Web Designing half of which is lying on one line half on other, i want it to be on same line. (One <a> link, one line.)
My Code:
<style type="text/css">
.cat_link a, .cat_link a:hover, .cat_link a:focus{
padding: 0.25em;
color:#3B5998;
font-family: Verdana;
text-decoration: none;
border:1px solid #DADADA;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
background: #EDEFF4;
margin-left: 0;
margin-right: 0;
line-height:2;
margin-top: 1em;
margin-bottom: 1em;
}
.cat_link {
line-height:2;
}
</style>
HTML CODE:
<p class="cat_link">
Cell Phones
Android
Tips and Tricks
Amazing
Web Designing
Windows Tips
Physics
CSS
CSS 3
Communication
Facebook Tips
Dajjal
Bermuda Triangle
</p>
Please give me solution if you can.
add this to css classes
.cat_link{
text-align: left ; /* gets rid of wierd white space */
}
.cat_link a{
white-space: nowrap; /*stops buttons from taking up two lines */
}
You have text-align: justify set on the page body; reset it with text-align: left for those category tags and it will fix that strange spacing.
To ensure that the text doesn't wrap as you describe in Problem #2, set white-space: nowrap on each of the category tags (selector .cat_link a).
Problem 1: with a text-align:left is solved-
Problem 2: you can put a display:block; in the a element to force the new line, but if the text is larger than the container with it will break into a new line.