How do I center this element? - html

My HTML:
<div class="container">
<div class="card login">
<p id="Title">Plex</p>
<div class="label">
</div>
Random text
</div>
<div class="card welcome">
<div class="label">
<p id="Title">Hi!</p>
</div>
Lorem ipsum
</div>
<div class="card extra">
<div class="label">
<p id="Title">Extra</p>
</div>
Lorem ipsum
</div>
</div>
MY CSS:
.container{
display: flex;
width: 100%;
/*align-content: center;*/
}
.card {
flex: 1 1 auto;
border: 1px solid #f3f3f3;
background-color: #f3f3f3;
margin-left: 50px;
margin-right: 50px;
margin-top: 25px;
height: 450px;
}
.label{
background-color: #434342;
width:auto;
height: 70px;
}
.card:not(:first-child){
margin-left: 20px;
}
#Title {
float: left;
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
}
A JSFiddle: http://jsfiddle.net/cvYGW/
How do I make the PLEX HI EXTRA all align perfectly in the middle of their cards and how do I move them up or down?

You have to reset margin to 0 for #title and put a line-height that equals to the height of the parent.
#title { /* change this selector to .title */
line-height: 70px;
margin: 0;
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
}
See: http://jsfiddle.net/cvYGW/9/
By the way, remember that your code is not valid HTML, as you use the same ID three times (#title). You should use class in this case. And you don't need any float property.

You shouldn't have multiple instances of an ID, so firstly change #Title to a class
You can't use float:left; & text-align:center;, remove the margin from your title p, match the line height
.title {
margin:0px;
line-height:70px;
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
}
http://jsfiddle.net/cvYGW/6/

#Title {
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
margin:0 auto;
}

I have update the js fiddle
you just have to add
#Title {
line-height:70px;
width:100%;
margin:0;
}
Check on fiddle

Please refer below updated fiddle
http://jsfiddle.net/cvYGW/10/
give some width for parent div and align the child elements in center of parent by using margin css property.
margin: 0 auto;
Thanks,
Siva

Check out http://jsfiddle.net/skyrbe/cvYGW/8/
You were using same id for multiple p tags . Never do that.
.Title {
float: left;
font-family: Thinfont-Thin;
font-size: 42px;
color: #d2731d;
text-align: center;
width:100%;
margin:0px auto;
line-height:42px;
}

update css:
#Title {
float: left;
font-family: Thinfont-Thin;
font-size: 20px;
color: #d2731d;
text-align: center;
width: 100%;
}

jquery animation
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$('#Title').click(function(){
$('#Title').animate({
bottom: '-=20'
}, 1000);
});
});
updated fiddle

Related

How do I get my text to align my picture?

This is the look:
How do I move the text up? So its centered besides the image?
CSS:
header{
padding: 20px;
background-color: #34495e;
color: black;
}
.header-1{
color: white;
padding: 0px 190px;
font-size: 17px;
vertical-align: middle;
line-height: 20px;
}
.logopng{
width: 35px;
height: 35px;
}
HTML:
<header>
<div class="header-1">
<img src="http://i.imgur.com/cGlBmw7.png" class="logopng">
Rocket League Prices
</div>
</header>
EDIT: added vertical-align:middle to the image class
The easiest way is to set display: flex and align-items: center on parent element.
header {
padding: 20px;
background-color: #34495e;
color: black;
}
.header-1 {
color: white;
font-size: 17px;
display: flex;
align-items: center;
}
.logopng {
width: 35px;
height: 35px;
margin-right: 20px;
}
<header>
<div class="header-1">
<img src="http://i.imgur.com/cGlBmw7.png" class="logopng">Rocket League Prices
</div>
</header>
you can use css3 flexbox concept.just add
display:flex;
align-items:center;
justify-content:center;
to your .header-1 it works fine.I'm added the snippet below.
header{
padding: 20px;
background-color: #34495e;
color: black;
}
.header-1{
color: white;
font-size: 17px;
display:flex;
align-items:center;
justify-content:center;
}
.logopng{
width: 35px;
height: 35px;
margin-right:10px;
}
<header>
<div class="header-1">
<img src="http://i.imgur.com/cGlBmw7.png" class="logopng">
Rocket League Prices
</div>
</header>

Display an image with a div which can wrap the link

I am working on a simple html/css web page.
What I am trying to do is having an image and a div. Both will be inline display and in div I want to put a link. But when I put a long link title it is not what I expect it to be.
My code is this-
code
<div class="heading"> featured posts
</div>
<div class="img_src">
<img style="height:120px;" src="/uploads/1.jpg"></img>
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
CSS-
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
line-height: 120px;
width: 61%;
margin-top: 3px;
text-transform: uppercase;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
I searched on google and StackOverflow but I did not get anything useful.
I want it to look like this(DIV wraps full)-
Any suggestion?
You csn use diplay:table-cell instead of inline-block but also I made edit in html by adding div.post that contain the image and title, and remove the inline-style that gave height to the image
<div class="post">
<div class="img_src">
<img src="http://i.dailymail.co.uk/i/pix/2016/03/22/13/32738A6E00000578-3504412-image-a-6_1458654517341.jpg">
</div>
<div class="link_src">
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
</div>
and in the css I give width:20%; to .img_src and width:80%; to .link_src (you can change the widths as you like) and remove height and line height from them and the diplay:table-cell will handle those height
.post{
font-size:0;
display:table;
width:100%;
}
.img_src{
display: table-cell;
vertical-align:top;
width:20%;
}
.img_src img{
width:100%;
}
.link_src{
display: table-cell;
background-color: white;
margin-top: 3px;
text-transform: uppercase;
vertical-align:middle;
width:80%;
}
.inside_link{
margin-left: 2%;
margin-right: 2%;
font-size: 15px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
https://jsfiddle.net/IA7medd/gg7ygdLs/17/
You can achieve that by changing the inline-block display to table-cell and then apply the vertical-align:middle; property on the text container.
That way, the text will be perfectly vertically centered if there are one, two, three lines of content.
.parent{
display: table;
border: 5px solid #ccc;
width: 100%;
}
.img_src{
display: table-cell;
}
.link_src{
display: table-cell;
vertical-align: middle;
background-color: white;
width: 61%;
text-transform: uppercase;
}
See this fiddle
Ok you are using the wrong approach. Line height is causing you the problem. Your html should look like this
<img class="img_src" style="height:120px;" src="/uploads/1.jpg">
<div class="link_src">
<div class="inner_link_src">
<div class="inner_margin">
Link will go here but if there is a long title then it may create some problems..
</div>
</div>
</div>
and your css like this
.img_src{
float:left
}
.link_src{
float:left;
position:relative;
width: 61%;
text-transform: uppercase;
background-color: white;
vertical-align: top;
display:table;
height:120px;
}
.inner_link_src{
display:table-cell;
width:100%;
height:100%;
vertical-align:middle;
margin-left:10px;
}
.inner_margin{
margin-left:10px;
}
see the jsfiddle it is working great
https://jsfiddle.net/gg7ygdLs/27/
You just change your CSS and HTML by following and then you get the desired result.
CSS:
.img_src{
display: inline-block;
margin-top: 3px;
margin-left:-2%;
}
.link_src{
display: inline-block;
background-color: white;
height: 120px;
width: 100%;
margin: 10px 0 10px 3px;
-webkit-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
-moz-box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
box-shadow: 7px 0px 0px 3px rgba(204,204,204,1);
}
.inside_link{
margin: 2%;
display: inline-block;
position:absolute;
padding: 8px;
}
.heading{
display: block;
background-color: #000;
color: #fff;
font-family: "Roboto Condensed","HelveticaNeue-CondensedBold","Helvetica Neue",Helvetica,Arial,Geneva,sans-serif;
font-size: 20px;
margin-top:5px;
font-color:white;
margin-left:-2%;
margin-right:-2%;
text-align: center;
line-height: 40px;
height: 40px;
font-style: oblique;
text-transform: uppercase;
}
HTML:
<div class="heading"> featured posts
</div>
<div class="link_src">
<img style="height:120px;" src="http://smashinghub.com/wp-content/uploads/2011/11/Text-Shadow-Box.jpg" />
<a class="inside_link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</div>
Demo
You can simplify your code a lot by using Flexbox.
You can use it for your header as well, to center the title.
.your-header {
display: flex;
align-items: center;
justify-content: center;
}
Then the image container. Use it's more semantic and it's a block element, perfect to wrap an image with a caption or a link in your case:
<figure class="your-figure">
<img class="your-image" src="http://pipsum.com/200x150.jpg"></img>
<a class="your-link" href="#">Link will go here but if there is a long title then it may create some problems..</a>
</figure>
and the CSS
.your-figure {
display: flex;
align-items: center;
padding: 4px;
border: 1px solid #ccc;
background-color: #fff;
}
.your-image {
margin-right: 10px;
}
Have a look here for the complete code ;)
Follow this if you don't know Flexbox, might seems daunting at first, but when it clicks in your head it will change your life :) Complete guide to Flexbox

How do I put one <div> element below another <div>

I just finished doing HTML/CSS with Codecademy. One of the "projects" there is to make your own resume. I took the HTML/CSS from that project, and I'm tweaking it to make the resume look better. I'm currently trying to put one div - the part of the resume where text about my career objective will go - under another div, the header. It is, however, not working. The div for the "objective" is currently behind the div for the header. How on earth do I get that second div for the objective to go underneath the first div?
I read something about how I should float the header div to the left and then put clear:both; in the div for the objective, but that's not working.
HTML
<div id="header">
<p id="name">My Name</p>
<p id="email">myemail#email.com</p>
</div>
<div id="objective"></div>
<div class="left"></div>
<div class="right"></div>
<div id="footer">
<p>1234 Anywhere Street, Brooklyn NY 11216 | Tel: (123) 456-7890</p>
</div>
CSS
div {
border-radius: 5px;
}
#header {
z-index:1;
position: fixed;
width: 98%;
margin-top: -20px;
height: 60px;
background-color: #668284;
margin-bottom: 10px;
float:left;
}
#name {
float:left;
margin-left: 5px;
padding-top: 5px;
font-size: 16px;
font-family: Verdana, sans-serif;
color: #ffffff;
}
#email{
float:right;
margin-right: 5px;
padding-top: 5px;
font-size: 16px;
font-family: Verdana, sans-serif;
color: #ffffff;
}
.right p {
margin-left: 5px;
margin-right: 5px;
margin-top: -10px;
font-family: Garamond, serif;
color: #000000;
}
a:hover {
font-weight: bold;
}
#objective {
height: 50px;
background-color: #668284;
font-family: Verdana, sans-serif;
font-size: 14px;
text-align: center;
clear:both;
color: #ffffff;
}
.left {
position: relative;
float: left;
margin-top: 50px;
width: 49%;
height: 400px;
background-color: #B9D7D9;
margin-bottom: 10px;
}
.right {
position: relative;
float: right;
margin-top: 50px;
width: 49%;
height: 400px;
background-color: #F4EBC3;
margin-bottom: 10px;
}
#footer {
position: relative;
height: 50px;
background-color: #668284;
clear: both;
font-family: Verdana, sans-serif;
font-size: 14px;
text-align: center;
color: #ffffff;
}
#footer p {
position: relative;
padding-top: 15px;
}
For example:
<div class="div1">KSD;JSFAJ;SSD;</div>
<div class="div2">KSD;JSFAJ;SSdfaD;</div>
Css with float:
.div1 {
float: none;
}
.div2 {
float: none;
}
Css with display:
.div1 {
display: inline;
}
.div2 {
display: inline;
}
Here is the updated HTML :
<div id="header">
<p id="name">My Name</p>
<p id="email">myemail#email.com</p>
</div>
<div style="height:50px;width:98%;">
</div>
<div id="objective">Objective goes here</div>
<div class="left"></div>
<div class="right"></div>
<div id="footer">
<p>1234 Anywhere Street, Brooklyn NY 11216 | Tel: (123) 456-7890</p>
</div>
This will show the objective div underneath header div.
Also this is a link for your reference.
Here is update CSS, This show the responsive your html
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
div {
border-radius: 5px;
}
#header {
width: 98%;
margin: 0 auto;
height: 60px;
background-color: #668284;
margin-bottom: 10px;
}
#name {
float:left;
margin-left: 5px;
padding-top: 5px;
font-size: 16px;
font-family: Verdana, sans-serif;
color: #ffffff;
}
#email{
float:right;
margin-right: 5px;
padding-top: 5px;
font-size: 16px;
font-family: Verdana, sans-serif;
color: #ffffff;
}
.right p {
margin-left: 5px;
margin-right: 5px;
margin-top: -10px;
font-family: Garamond, serif;
color: #000000;
}
a:hover {
font-weight: bold;
}
#objective {
height: 50px;
background-color: #668284;
font-family: Verdana, sans-serif;
font-size: 14px;
text-align: center;
clear:both;
color: #ffffff;
}
.left {
position: relative;
float: left;
margin-top: 50px;
width: 49%;
height: 400px;
background-color: #B9D7D9;
margin-bottom: 10px;
}
.right {
position: relative;
float: right;
margin-top: 50px;
width: 49%;
height: 400px;
background-color: #F4EBC3;
margin-bottom: 10px;
}
#footer {
position: relative;
height: 50px;
background-color: #668284;
clear: both;
font-family: Verdana, sans-serif;
font-size: 14px;
text-align: center;
color: #ffffff;
}
#footer p {
position: relative;
padding-top: 15px;
}
Don't ever forget to add this code
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
So that you won't have empty space on your div
DEMO
I think its easier using bootstrap, here is the link http://getbootstrap.com/css/
What bootstrap does is that it creates containers that wrap the content of your site. It divides the site in rows. To do that you need and . With this bootstrap you can divide your rows in 12 cells.
Here is an example of how I divided my portfolio in 3 columns of 4 spaces
<div class="row">
<div class="col-md-12">
<hr>
</div>
</div>
<div class="row text-center">
<div class="col-md-4">
<h3 class="text-body"><u>Block vs Inline</u>
</h3>
<p class="p-text"><span>Block Elements</span> are those who take the complete line and full width of the page creating a "box".<br>
<span>Inline Elements</span> are those who doesn´t affect the layout, just the element inside the tag.
</p>
</div>
<div class="col-md-4">
<h3 class="text-body"><u>Selectors</u></h3>
<p class="p-text"><span>Class selectors</span> are used to target elements with specific attributes<br>On the other hand, <span>id selectors</span> are just for unique elements.</p>
</div>
<div class="col-md-4">
<h3 class="text-body"><u>Responsive Layout</u></h3>
<p class="p-text"><span>Responsive Layout</span> is the combination of html and css design to make the website look good in terms of enlargement, shrink and width in any screen (<em>computers, laptops, netbooks, tablets, phones</em>). </p>
</div>
</div>

How can I get this image done in HTML and CSS?

I have this image that is to be implemented in HTML and CSS.
This is what I have tried.
<span>$</span><span style="font-size: 50px;">99</span><span style="vertical-align: text-top;">00</span>
But this actually doesn't turn out like I want in the image.
For example:
.price {
font-size: 80px;
color: #f60;
}
.price sup {
font-size: 38px;
}
.price sub {
font-size: 28px;
color: #aaa;
position: absolute;
display: inline-block;
margin: 48px 0 0 -40px;
}
<span class="price"><sup>$</sup>99<sup>00</sup><sub>/month</sub></span>
http://jsfiddle.net/1zjuddj8
It sounds like the <sup> tag is your friend here. Any text in the <sup> tags will become superscript.
Example
<sup>$</sup>99<sup>00</sup>
Additional Documentation/Reference from w3.org: http://www.w3.org/TR/html-markup/sup.html
You have a specific tag for make your text appears on the top use <sup></sup> to treat it like an indice and <sub></sub> as a note. To force the alignement you will have to play with vertical-align value in px or in %.
`
<sup style="vertical-align: 10;">$</sup><sub style="font-size: 50px;vertical-align:-10">99</sub><sup style="vertical-align: 10;">00</sup>
You can use sup to make the text superscript and then set the position of the text using position: relative and top:
HTML:
<h1><sup>$</sup>99<sup>00</sup></h1>
CSS:
h1 { font-size: 50px; }
sup { font-size: 15px;
position: relative;
line-height: 0;
vertical-align: baseline;
top: -23px;
}
JS Fiddle
A solution which requires a bit more fine tuning, but has a lot of control, very useful for front-end layouts:
HTML code
<div class="price_tag">
<div class="price"><sup>$</sup><span class="bignum">99</span><sup>00</sup>
</div>
<div class="month">/month</div>
</div>
CSS code
.price_tag {
position:relative;
width:190px;
height:100px;
color:#f90;
font-size:6em;
font-family:helvetica, arial, sans-serif;
}
.price {
position:relative;
width:200px;
height:100px;
font-weight:bold;
}
sup {
position:relative;
font-size:2.5rem;
top:1rem
}
.month {
width:60px;
height:30px;
color:#ccc;
font-size:1rem;
right:0;
bottom:0;
z-index:3;
position:absolute;
}
fiddle here
To duplicate it with accuracy, your code will have to be more involved than that. I've tried to match it as closely as I could here: http://jsfiddle.net/wvcm92ka/
The code is below:
HTML:
<div class="amount">
<div class="amount-parts">
<div class="amount-currency">$</div>
<div class="amount-whole">99</div>
<div style="clear: left;"></div>
</div>
<div class="amount-parts">
<div class="amount-decimal">00</div>
<div class="amount-period">/month</div>
<div style="clear: left;"></div>
</div>
<div style="clear: left;"></div>
</div>
CSS:
.amount-parts{
font-family: verdana, sans-serif;
float: left;
}
.amount-currency, .amount-whole, .amount-decimal, .amount-period{
font-weight: 600;
}
.amount-currency, .amount-whole, .amount-decimal{
color: #ff0000;
}
.amount-currency{
float: left;
font-size: 32pt;
font-weight: bold;
margin-top: 5px;
}
.amount-whole{
font-size: 60pt;
float: left;
}
.amount-decimal{
color: #ff0000;
font-size: 24pt;
font-weight: bold;
margin-top: 15px;
}
.amount-period{
color: #999;
font-size: 10pt;
font-weight: bold;
}
Another solution:
body {
font-size: 20px;
}
.div-table {
display: table;
border-collapse: collapse;
}
.div-table .div-table-row {
display: table-row;
}
.div-table .div-table-cell {
display: table-cell;
text-align: left;
vertical-align: top;
}
.big-number {
font-size: 50px;
}
.padding-top {
padding-top: 5px;
}
<div class="div-table">
<div class="div-table-row">
<div class="div-table-cell padding-top">
$
</div>
<div class="div-table-cell">
<span class="big-number">99</span>
</div>
<div class="div-table-cell padding-top">
<div>00</div>
<div>/month</div>
</div>
</div>
</div>
http://jsfiddle.net/gbx0ogqm/

How to put an image next to each other

I'm trying to put these two 'hyperlinked' icons next to each other but I can't seem to do that. As you can see, the twitter icon falls to the next line.. (they are both hyperlinked to their respective website)
HTML
<div class="nav3" style="height:705px;">
<div id="icons"><img src="images/facebook.png">
</div>
<div id="icons"><img src="images/twitter.png">
</div>
</div>
CSS
.nav3 {
background-color: #E9E8C7;
height: auto;
width: 150px;
float: left;
padding-left: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
padding-top: 20px;
padding-right: 20px;
}
#icons{position:relative;
width: 64px;
height: 64px;
}
#icons a:hover {
background: #C93;
display: block;
}
How do I make the aligned next to each other?
Thanks in advance
You don't need the div's.
HTML:
<div class="nav3" style="height:705px;">
<img src="images/facebook.png">
<img src="images/twitter.png">
</div>
CSS:
.nav3 {
background-color: #E9E8C7;
height: auto;
width: 150px;
float: left;
padding-left: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
padding-top: 20px;
padding-right: 20px;
}
.icons{
display:inline-block;
width: 64px;
height: 64px;
}
a.icons:hover {
background: #C93;
}
See this fiddle
Change div to span. And space the icons using
HTML
<div class="nav3" style="height:705px;">
<span class="icons"><img src="images/facebook.png">
</span>
<span class="icons"><img src="images/twitter.png">
</span>
</div>
CSS
.nav3 {
background-color: #E9E8C7;
height: auto;
width: 150px;
float: left;
padding-left: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
padding-top: 20px;
padding-right: 20px;
}
.icons{
display:inline-block;
width: 64px;
height: 64px;
}
a.icons:hover {
background: #C93;
}
span does not break line, div does.
Check this out. Just use float and get rid of relative.
http://jsfiddle.net/JhpRk/
#icons{float:left;}
try putting both images next to each other. Like this:
<div id="icons"><img src="images/facebook.png"><img src="images/twitter.png">
</div>
Instead of using position:relative in #icons, you could just take that away and maybe add a z-index or something so the picture won't get covered up. Hope this helps.