How to align divs to the right - html

I have a cityHeader(in this pic it is Los Angeles).
Underneath cityHeader there is div called weatherMain which contains three smaller divs(id=temperature,id=weatherDescriptionHeader and id=documentIconImg
#cityHeader {
float: right;
display: block;
margin: 5px;
font-size: 42px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
#weatherMain {
display: block;
margin-bottom: 20px;
text-align: right;
}
#weatherMain div {
display: inline-block;
}
#weatherDescriptionHeader {
font-size: 28px;
vertical-align: 50%;
}
#temperature {
font-size: 38px;
vertical-align: 25%;
}
<h1 id="cityHeader"></h1>
<div id="weatherMain">
<div id="temperature"></div>
<div id="weatherDescriptionHeader"></div>
<div><img id="documentIconImg" /></div>
</div>
enter image description heredocumentIconImg).
Three smaller divs should be under cityHeader, positioned next to each other and all aligned to the right.
I tried floating them to the right,adding text-align:right to their parent element(weatherMain), nothing works.
In the pic temperature div is 9 degrees,weatherDescriptionHeader is Clear sky and documentIconImg is icon.

Is this what you're looking for: https://codepen.io/dillonbrannick/pen/XOoNjp
I added in the background colours just so it's easy to identify the elements. Just put your background image into the #weatherMain and remove the other background colours and it should work fine. I added in a margin to #weathermain just to display it within the middle of the page.
Also I added a margin:0 to the h1 tag as h1 automatically adds some css style to it that was interfering.
HTML:
<div id="weatherMain">
<h1 id="cityHeader">Hello World</h1>
<div id="temperature">Howya</div>
<div id="weatherDescriptionHeader">Hola</div>
</div>
CSS:
#weatherMain {
background-color:red;
text-align: right;
margin: 10% 20% 10% 20%
}
#cityHeader {
background-color:yellow;
}
h1{
margin:0;
font-size:45px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; }
#temperature {
background-color:green;
font-size: 38px;
}
#weatherDescriptionHeader {
background-color:lightblue;
font-size: 28px;
}

Try this:
#weatherMain {
display: block;
margin-bottom: 20px;
text-align: right;
float: right
}

Related

Align Select box and images

I have a div with a select box and 3 images.
I want to make this:
I have this:
So basically I am having trouble aligning the 3 images at the same height as the select box. I have tried several things and have no clue why it does not work.
Here is my HTML and CSS:
#lang_social {
width: 100%;
height: 60px;
background-color: #3CC;
display: table;
}
#language select {
height: 40px;
width: 200px;
background-color: #3FF;
border-color: #3FF;
display: inline-block;
vertical-align: middle;
color: #FFF;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
font-size: 16px;
margin-left: 10%;
margin-top: 10px;
;
}
#twitter_conn img {
float: right;
display: inline-block;
vertical-align: middle;
position: absolute;
float: right;
}
#fb_conn {
float: right;
margin-top: 10px;
margin-right: 20%;
display: inline-block;
vertical-align: middle;
}
#linkedin_conn {
float: right;
margin-top: 10px;
margin-right: 10%;
display: inline-block;
vertical-align: middle;
}
<div id="lang_social">
<div id="language">
<select>
<option value="swe">SWEDISH</option>
<option value="eng">ENGLISH</option>
</select>
</div>
<div id="twitter_conn">
<img src="http://www.placehold.it/32" onmouseover="this.src='http://www.placehold.it/32'" onmouseout="this.src='http://www.placehold.it/32'">
</div>
<div id="fb_conn">
<img src="http://www.placehold.it/32" onmouseover="this.src='http://www.placehold.it/32'" onmouseout="this.src='http://www.placehold.it/32'">
</div>
<div id="linked_conn">
<img src="http://www.placehold.it/32" onmouseover="this.src='http://www.placehold.it/32'" onmouseout="this.src='http://www.placehold.it/32'">
</div>
</div>
The general layout
To simplify things, let's create two separate divs that are each given 50% width on one line.
They can be marked up like this:
<div id="lang_social">
<div id="language"><!-- Select goes here --></div>
<div id="social"><!-- Icons go here --></div>
</div>
and positioned like this, each child div is given 50% width and will line up next to the other:
#lang_social > div {
display: inline-block;
width: 50%;
}
We now have two divs on one line:
Right align the icons
We want the social icons to be aligned from the right, that's easy now:
#social {
text-align: right;
}
Apply the colours and we get the finished result:
If you want, we can end the answer here, have a snippet:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#lang_social {
width: 100%;
background-color: #3CC;
line-height: 60px;
/*This Line height is the same as the height and will vertically center a single line*/
min-width: 340px;
}
#lang_social > div {
display: inline-block;
width: 50%;
padding: 0 10px;
}
img {
vertical-align: middle;/*Important to align in the middle*/
}
#social {
text-align: right;
}
#language select {
height: 40px;
width: 200px;
background-color: #3FF;
border-color: #3FF;
color: #FFF;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
font-size: 16px;
}
<div id="lang_social">
<div id="language">
<select>
<option value="swe">SWEDISH</option>
<option value="eng">ENGLISH</option>
</select>
</div><div id="social">
<img src="http://www.placehold.it/32/FF0000" />
<img src="http://www.placehold.it/32/FF9900" />
<img src="http://www.placehold.it/32/FF99CC" />
</div>
</div>
or we can go a little further below.
Note:
Each inline elements closing tag has no whitespace between it and the next inline elements opening tag, this prevents the gaps between inline elements. Example:
<div id="language">
Contents
</div><div id="social">
Contents
</div>
box-sizing: border-box incorporates padding and borders into the width and height.
Hover states for the social icons using CSS Sprites
If you want to, we can create a simple image hover state for each social image without javascript.
Instead of using <img>, we can use <a>, like so:
<div id="social">
<a class="icon facebook"></a>
<a class="icon twitter"></a>
<a class="icon linked"></a>
</div>
This allows us to create the normal and hover state with a CSS sprite. We can apply the background to the icon class:
.icon {
display: inline-block;
vertical-align: middle;
background: url(http://i.stack.imgur.com/1eIYU.png);
height: 32px;
width: 32px;
}
The background image looks like this:
Each coloured section should be changed with the social logo on a transparent background.
the top row of colours is used for the unhovered icon state. The bottom row is used for the hovered state.
Red = Facebook icon
Orange = Twitter icon
Pink = LinkedIn icon
Each icon section is 32px x 32px and each icon is positioned with background-position:
.facebook {
background-position: 0 0; /*x-axis | y-axis*/
}
.twitter {
background-position: -32px 0;
}
.linked {
background-position: -64px 0;
}
On hover, the background-position is changed to show a hover state:
.facebook:hover {
background-position: 0 -32px;
}
.twitter:hover {
background-position: -32px -32px;
}
.linked:hover {
background-position: -64px -32px;
}
Completed example
Note:
Each inline elements closing tag has no whitespace between it and the next inline elements opening tag, this prevents the gaps between inline elements.
box-sizing: border-box incorporates padding and borders into the width and height.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#lang_social {
width: 100%;
background-color: #3CC;
line-height: 60px;
/*This Line height is the same as the height and will vertically center a single line*/
min-width: 340px;
}
#lang_social > div {
display: inline-block;
width: 50%;
padding: 0 10px;
}
#social {
text-align: right;
}
#language select {
height: 40px;
width: 200px;
background-color: #3FF;
border-color: #3FF;
color: #FFF;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
font-size: 16px;
}
.icon {
display: inline-block;
vertical-align: middle;
margin: 0 0 0 10px;
background: url(http://i.stack.imgur.com/1eIYU.png);
height: 32px;
width: 32px;
transition: background-position .3s
}
.facebook {
background-position: 0 0;
}
.twitter {
background-position: -32px 0;
}
.linked {
background-position: -64px 0;
}
.facebook:hover {
background-position: 0 -32px;
}
.twitter:hover {
background-position: -32px -32px;
}
.linked:hover {
background-position: -64px -32px;
}
<div id="lang_social">
<div id="language">
<select>
<option value="swe">SWEDISH</option>
<option value="eng">ENGLISH</option>
</select>
</div><div id="social">
<a class="icon facebook"></a><a class="icon twitter"></a><a class="icon linked"></a>
</div>
</div>
I couldn't see your icons so i have used my own. you can substitute. I made your ids into classes and gave the lang_social an overall attr of vertical-align:middle to affect everything. I also floated the language left. Here is a fiddle
#lang_social {
width: 100%;
height: 60px;
background-color: #3CC;
display: table;
vertical-align:middle;
}
.language select {
height: 40px;
width: 200px;
background-color: #3FF;
border-color: #3FF;
display: inline-block;
vertical-align: middle;
color: #FFF;
font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
font-size: 16px;
margin-left: 10%;
margin-top: 10px;
float:left;
}
.twitter_conn {
display:inline-block;
margin-top: 10px;
margin-right: 20px;
width:30px;
float:right;
}
.fb_conn {
margin-top: 10px;
margin-right: 20px;
display:inline-block;
width:30px;
float:right;
}
.linkedin_conn {
width:30px;
float:right;
margin-top: 10px;
margin-right: 20px;
display:inline-block;
}
img {
width:32px;
height:32px;
padding:4px;
}
<div id="lang_social">
<div class="language">
<select>
<option value="swe">SWEDISH</option>
<option value="eng">ENGLISH</option>
</select>
</div>
<div class="linkedin_conn">
<img src="http://www.teratology.org/images/linkedin.png" onmouseover="this.src='http://www.teratology.org/images/linkedin.png'" onmouseout="this.src='http://www.teratology.org/images/linkedin.png">
</div>
<div class="fb_conn">
<img src="http://www.musicmatters.ie/images/fb3.png" onmouseover="this.src='http://www.musicmatters.ie/images/fb3.png'" onmouseout="this.src='http://www.musicmatters.ie/images/fb3.png'">
</div>
<div class="twitter_conn">
<img src="http://www.musicmatters.ie/images/twitter3.png" onmouseover="this.src='http://www.musicmatters.ie/images/twitter3.png" onmouseout="this.src='http://www.musicmatters.ie/images/twitter3.png'">
</div>
</div>

Center text horisontaly and verticaly in an image

I want to change the text on the photos to be in the center, both horisontal and vertical. It's currently centered horisontally, but not vertically. Remember it's a "hover-effect background image"-thing.
HTML
<a href="portrait">
<div id="imagebox1" class="imagebox columns">
<div id="image1">
<span id="plus">Portrett</span>
</div>
</div>
</a>
<a href="nature">
<div id="imagebox3" class="imagebox columns">
<div id="image3">
<span id="plus">Natur</span>
</div>
</div>
</a>
<a href="various">
<div id="imagebox2" class="imagebox columns">
<div id="image2">
<span id="plus">Annet</span>
</div>
</div>
</a>
CSS
#imagebox1, #imagebox2, #imagebox3 {
float: left;
background-repeat: no-repeat;
margin-right: 0px;
}
#imagebox1 {
background:url(../images/sample_image400.jpg);
background-size: cover;
margin-left: 0px;
}
#imagebox2 {
background:url(../images/sample_image.jpg);
background-size: cover;
}
#imagebox3 {
background:url(../images/sample_image.jpg);
background-size: cover;
}
#image1, #image2, #image3 {
background:rgba(255,255,255,.75);
text-align:center;
padding-top: 100%;
opacity:0;
-webkit-transition: all 0.3s ease-in-out;
}
#imagebox1:hover #image1 {
opacity:1;
}
#imagebox2:hover #image2 {
opacity:1;
}
#imagebox3:hover #image3 {
opacity:1;
}
.images img {
margin-left: 0px;
padding-bottom:30px;
padding-top:35px;
}
#imagebox1, #imagebox2, #imagebox3 {
margin-bottom: 30px;
}
#plus {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200;
color: #282828;
font-size: 20px;
text-transform: uppercase;
}
JSFIDDLE
http://jsfiddle.net/8abCY/
Ok...I think your HTML structure is too complex for what you are trying to do.
So I've simplified it.
JSfiddle DEmo
The image is content and so it should be in the HTML not a background-image in the CSS which gives us, simply
HTML
<a href="portrait" class="imagebox">
<img src="http://www.ginakorslund.no/images/sample_image400.jpg" alt=""/>
<span class="plus">Portrett</span>
</a>
Note I'be changed a lot of the ID out for a more generic class. you can still give each anchor link an individual ID if you want but the classes mean that the CSS is re-usable.
CSS
.imagebox {
position: relative; /* required */
text-align: center;
display: block;
}
.plus {
position: absolute;
top:50%; /* top and left values put the span's top left corner exactly */
left:50%; /* halfway down and across the screen but do **not** center it */
-webkit-transform:translate(-50%, -50%);
transform:translate(-50%, -50%);
/* move the span back exactly half it's own width and height */
/* and now it's centered regardless of width & height */
display: none; /* hide it until hovered */
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200;
color: #282828;
font-size: 20px;
text-transform: uppercase;
color:white;
}
.imagebox:hover .plus {
display: block; /* show it when the link is hovered */
}
try...
#plus {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200;
color: #282828;
font-size: 20px;
text-transform: uppercase;
position: relative;
margin-top: auto;
margin-bottom: auto;
}

Why can I get no satisfaction trying to add margin or padding between an image and some text?

I want an image on the left and three pieces of text on the right. I've got that, but trying to add some space between them is proving to be an exercise in futility. I've tried adding both padding-left and margin to the css, but they ignore them like a cheerleader does a nerd.
The jsfiddle is here: http://jsfiddle.net/GwYJH/
Here's my HTML:
<a id="mainImage" class="floatLeft" href="https://rads.stackoverflow.com/amzn/click/com/1456334050" rel="nofollow noreferrer"><img height="200" width="160" src="http://ecx.images-amazon.com/images/I/51ETjedyMAL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg"></img></a>
<div class="category">Picaresque Satire</div>
</br>
<div class="title">the Zany Time Travels of Warble McGorkle</div>
</br>
<div class="author">Blackbird Crow Raven</div>
</br>
...and the CSS:
body {
background-color: black;
}
.floatLeft {
float: left;
}
.category {
display: inline-block;
font-family: Consolas, sans-serif;
font-size: 2em;
color: Orange;
padding-left: 25;
margin: 25;
}
.title {
display: inline-block;
font-family: Calibri, Candara, serif;
color: Yellow;
}
.author {
display: inline-block;
font-family: Courier, sans-serif;
font-size: 0.8em;
color: White;
}
I also want each piece of text to wrap if the viewbox narrows. IOW, "Picaresque Satire" should become:
Picaresque
Satire
...if there's not enough space to fit on one line; what it's doing now is moving below the image if it runs out of space (then it will break as I want it to if it gets squished even more).
#mainImage {
margin-right:15px;
}
.category p {
word-wrap:break-word;
}
Demo here:http://jsfiddle.net/GwYJH/8/
How the word wraps (i.e. if it wraps to the right hand side of the image or below it) is wholly dependent on the width of the containing element.
I have some suggestions for you. Fist of all, use this code to get the spaces.
.floatLeft {
float: left;
padding-left: 25px;
margin: 25px;
}
The, set the width to the .category, so you wrap the text
.category {
display: inline-block;
font-family: Consolas, sans-serif;
font-size: 2em;
color: Orange;
padding-left: 25;
width:30px;
}
jsfiddle
Non-zero padding and margin values require a unit to be specified. I assume you wanted pixels:
padding-left: 25px;
margin: 25px;
http://jsfiddle.net/GwYJH/6/
Old versions of IE would allow you to omit the unit, but modern standards compliant browsers do not.
You dont have (px) defined on the padding-left and margin. Remove margin and only use padding-left on all of the divs.
Use this code instead:
.category {
display: inline-block;
font-family: Consolas, sans-serif;
font-size: 2em;
color: Orange;
padding-left: 25px;
}
.title {
display: inline-block;
font-family: Calibri, Candara, serif;
color: Yellow;
padding-left: 25px;
}
.author {
display: inline-block;
font-family: Courier, sans-serif;
font-size: 0.8em;
color: White;
padding-left: 25px;
}

Why won't my text center here?

I have the following CSS:
.me-header {
display: inline-block;
position: relative;
top: 50px;
left: 10px;
}
.me-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-decoration: none
}
.resume-header {
display: inline-block;
position: relative;
top: 50px;
left: 100px;
}
.resume-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-align: center;
text-decoration: none
}
.center-text {
text-align: center;
}
And the following HTML:
<div class="me-header">
<img src="media/me-icon.png" alt="Picture of Christian Selig"><br> <span class="center-text">Contact Me</span>
</div>
<div class="resume-header">
<img src="media/resume-icon.png" alt="Resume icon" title="Click to download resume (PDF)"><br> <span class="center-text">Resume (PDF)</span>
</div>
But my text still comes out left-aligned. Why?
Both a and span are inline elements - so they are only as wide as their contents. So when you center the text, it is centred within the inline element, but the inline element appears on the left.
If you set text-align: center; on the parent block element it will work.
If you want to center the whole block, use an automatic margin.
You could do
.center-text
{
display: table;
margin: 0 auto;
}

How to center a menu using <div>

I've tried this:
Code:
<div class="center">
<div class="mainmenuoption">Home</div>
<div class="mainmenuoption">About Us</div>
<div class="mainmenuoption">Experiences</div>
<div class="mainmenuoption">Get Involved</div>
<div class="mainmenuoption">Support Us</div>
<div class="mainmenuoption">Contact Us</div>
</div>
CSS:
div.center
{
display: block;
margin-left: auto;
margin-right: auto;
}
div.mainmenuoption
{
float: left;
font: normal normal bold 100% "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
width: 100px;
color: #FFFF00;
text-align: center;
vertical-align: middle;
}
Setting the inner divs to display: inline-block and the outer div to text-align: center, It should solve your problem.
Unless you set an explicit width on your div it will expand to take up the available width. Since you seem to know how wide you want it this will work:
div.center {
width: 600px;
margin: 0 auto;
}
If the div might be of variable width use display: inline-block as Madara Uchiha suggested.
Add a width to your div.center declaration or add text-align: center to your div.center declaration.
Give display: inline-block; to the inner divs and a text-align: center; to the parent div.
<div class="center">
<div class="mainmenuoption">Home</div>
<div class="mainmenuoption">About Us</div>
<div class="mainmenuoption">Experiences</div>
<div class="mainmenuoption">Get Involved</div>
<div class="mainmenuoption">Support Us</div>
<div class="mainmenuoption">Contact Us</div>
</div>
CSS:
div.center
{
text-align: center;
}
div.mainmenuoption
{
font: normal normal bold 100% "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
width: 100px;
color: #FFFF00;
text-align: center;
vertical-align: middle;
display: inline-block;
}
Demo: http://jsfiddle.net/8Y8YW/
if you want to center the menu (class .center) then you can use
.center
{
width:600px; // what ever width you want
margin: auto 0;
}
or you want to center the menu item use text-align: center
If you set the width in your div.center, it should work!
I posted a sample at: http://jsfiddle.net/EFXXs/2/