CSS alignment issue with image - html

Take a look at this image:
http://i.gyazo.com/a5bf5097e6783d4879f12fdba0b2bbec.png
I want to get the "Test" below Profile, a BR html tag produces the above result and I don't want that.
Heres my code for this:
http://pastebin.com/raw.php?i=hW3jDrLu
<i class="fa fa-user fa-3x" style="vertical-align:middle;"></i>
<span style="font-size: 12pt;">Profile <span style="color: #979797;font-size:8pt;">Test</span></span>
I would like the "Test" to be right below the Profile header

It's tough to say without seeing more of your code, but I imagine your best bet is putting the img in one div and the text in another. Then you can have a line break in the text within its div and still have the div to the right of the img.
Here is a mock up of how it should work.
Apparently I have to add the fiddle code here as well:
HTML:
<div class="imgC"><img src="http://www.w3schools.com/tags/smiley.gif" alt="Smiley face" height="42" width="42"> </img></div>
<div class="textC"><span style="font-size: 12pt;">Profile <br></span><span style="color: #979797;font-size:8pt;">Test</span></div>
CSS:
.imgC{
display:inline-block;
float:left;
}
.textC{
display:inline-block;
float:left;
}

You may also want to preserve their block property by floating them and using the clear attribute (fiddle here):
HTML:
<div id="Container">
<img id="Icon" src="http://goo.gl/OJhO2s"/>
<div id="InfoContainer">
<span class="profile">Profile</span>
<span class="test">Test</span>
</div>
</div>
CSS:
#Icon {
width: 64px;
height: 64px;
float: left;
}
#InfoContainer {
float: left;
}
#InfoContainer span {
display: block;
clear: both;
}
.profile {
font-size: medium;
}
.test {
font-size: small;
color: #444;
}

Related

How to not use absolute positioning CSS

I'm currently working on an old website that was created with some old crappy WYSIWYG editor. I'm new to web-dev and still trying to get my head around positioning elements properly. My current issue is, from what I have read, using absolute positioning is BAD, but how would you change this?
So this is the old code:
<div id="wb_Text1"
style="margin:0;
padding:0;
position:absolute;
left:187px;
top:24px;
width:83px;
height:147px;
text-align:left;
z-index:1;
border:0px #C0C0C0 solid;
overflow-y:hidden;
background-color:transparent;
">
<div style="font-family:'.Helvetica Neue DeskInterface';font-size:15px;color:#000000;">
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>W</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>A</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>C</strong>
</span>
</div>
</div>
And what I have come up with to replace it is:
HTML
<div class="logo-ul">
<ul>
<li>W</li>
<li>A</li>
<li>C</li>
</ul>
</div>
CSS
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index:24;
float: right;
margin-right: 80%;
}
Which looks fine until you collapse the window and it falls apart :( lol.
You can see what I'm doing here http://media.wacmotorcycles.co.uk/
How should I be writing this please?
Thanks.
Try changing #logo to
#logo {
max-width: 165px;
max-height: 171px;
margin: 0.75em 0;
float: left;
}
And, .logo-ul to
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index: 24;
float: left;
}
There is nothing inherently wrong with absolute positioning. If used incorrectly, it can have unexpected results when working with responsive layouts.
In your specific case, the W A C might be better implemented as part of the logo image itself rather than text. It's not offering any semantic or SEO benefit to include the letters in a list. Short of that, this is one way to implement what I think you're after:
.logo {
height: 6rem;
padding-left: 50px;
}
.logo-letter {
display: block;
height: 2rem;
}
<div class="logo">
<span class="logo-letter">W</span>
<span class="logo-letter">A</span>
<span class="logo-letter">C</span>
</div>

Why are the links in my footer including the margin-right?

I am practicing my HTML and CSS skills using Notepad++ and I have ran into a problem when I was adding a couple of links to my footer. The problem I am having is that each link is including the margin-right value of 15px (i.e. the white space between each link can be clicked on). I want to be able to ONLY click on the words to direct me to that particular page.
Here is my HTML code for the footer:
<body>
<div id="footer">
<div id="footerlinks">
<a href="index.html">
<span style="color: #FFFFCC">
<p class="footerlink">
HOME
</p>
</span>
</a>
<a href="about.html">
<p class="footerlink">
ABOUT
</p>
</a>
<a href="rooms.html">
<p class="footerlink">
ROOMS
</p>
</a>
<a href="divesite.html">
<p class="footerlink">
DIVE SITE
</p>
</a>
<a href="food.html">
<p class="footerlink">
FOOD
</p>
</a>
<a href="news.html">
<p class="footerlink">
NEWS
</p>
</a>
<a href="contact.html">
<p class="footerlink">
CONTACT
</p>
</a>
</div>
</div>
</body>
Here is my CSS for the footer:
#footer {
width: 100%;
height: 50px;
background-color: #999999;
border-bottom: 1px solid black;
padding-right: 20px;
padding-left: 20px;
clear: both;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#footerlinks {
height: 100%;
line-height: 45px;
display: inline-block;
float: left;
}
#footerlinks a {
color: #333333;
}
#footerlinks a:link {
text-decoration: none;
}
#footerlinks a:hover {
color: #FFFFCC;
}
.footerlink {
font-size: 14px;
vertical-align: center;
margin-right: 15px;
display: inline;
}
Here is my JSFiddle - https://jsfiddle.net/vu4qg17c/2/
I have only included the necessary parts of the HTML and CSS code in the JSFiddle. Thank you in advance.
Instead of
<a href="about.html">
<p class="footerlink">
ABOUT
</p>
</a>
Reverse the position of <a> and <p>
<p class="footerlink">
<a href="about.html">
ABOUT
</a>
</p>
Do the same in all others.
Writing <a> before <p> makes the whole<p> as a link. And, as the <p> has some default padding, the area without text also becomes clickable.
Simplest solution would be reversing the p and a on your links. Then you can adjust margin and padding on the paragraphs (.footerlink) and the links are just as long as the text is.
e.g.
<p class="footerlink">
<a href="rooms.html">
ROOMS
</a>
</p>
in this class you are giving margin of 15px.
.footerlink {
font-size: 14px;
vertical-align: center;
margin-right: 15px;
display: inline;
}
Your behaviour sounds like the standard behaviour for padding, which is whitespace "inside" of the element (between content and border). margin, as you are using it, is whitespace outside of the border and thus should not be part of the link element.
The problem in your case could be that you added the margin to the span element inside of the a element and thus being seen as "belonging" to the link in some browser. Move the margin attribute to the a element (#footerlinks a) itself instead of its child (.footerlink).
See here

Using svg on webpage results in weird css rendering in webkit browsers

I'm running into a weird glitch which only seems to happen in chrome and safari. It's hard to explain why this happens with sample code, but I'll try to illustrate what I'm doing with code, while providing a link to the actual page below.
First of all, I have an unordered list displayed inline-block, so it can be justified just like text. Each list item contains an svg in an image tag and a paragraph with a short description, both wrapped in a single anchor tag. Nothing special i guess, but here's the catch: in chrome and safari the browser renders a 1px by approximately 15px blue/blackish line between the paragraph and the image, and I have no idea why this is happening. Here's the code:
<div class="wrapper">
<div class="justified-list home-icons">
<ul>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
</ul>
<span class="stretcher"></span>
</div><!-- .justified-list -->
</div><!-- .wrapper -->
and here is the css (I'm using scss):
.wrapper {
width: 100%;
}
.justified-list {
width: 100%;
text-align: justify;
* {
display: inline;
}
li {
display: inline-block;
vertical-align: top;
}
.stretcher {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
}
Also, a codepen is provided here:
http://codepen.io/smelly586/pen/NPVVYd
If anyone has a clue on what's going on, or even better: has a possible fix for this, you have my gratitude.
Set your font-size on the element to 0. What you're seeing is the underline in the anchor element for whitespace in your HTML.
You could turn off the text-decoration: underline; that the browser renders by default for anchors, but let's assume that's not what you want to do.
Instead, the element with text will need to be reset to document root font-size (or whatever you want) using something like p { font-size: 1rem; }.
Example Codepen
So, accordingly, the SCSS/LESS would be:
.justified-list {
width: 100%;
text-align: justify;
* {
display: inline;
}
li {
display: inline-block;
vertical-align: top;
a {
font-size: 0;
p { font-size: 1rem; }
}
}
.stretcher {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
}

Format Math Equation (5,343 + 32) Vertically with CSS

I'm trying to format math equations vertically using CSS. For example 5,343 + 32 should be formatted as so:
Line 1: 5,343 (right aligned)
Line 2: + (left aligned) 32 (right aligned) --- Note that the plus sign and bottom number are on the same line.
Line 3: ------ (horizontal line)
I've been fooling around with this for the last hour and have had very little luck.
I laid by HTML out like this:
<div id="textbox">
<p class="upperNum">5,343</p>
<p class="sign">+</p>
<p class="lowerNum">32</p>
<p class="line"><hr></p>
</div>
A semantic approach
Here's a semantic approach to marking up an equation that, from the same markup, can be rendered horizontally or vertically by adding a single class. These equations are made up of numbers, an operator, and an equals sign. Here's the markup for an equation:
<span class="equation">
<span class="number">5,343</span>
<span class="operator">+</span>
<span class="number">32</span>
<span class="equals">=</span>
<span class="number">5,375</span>
</span>
That alone renders horizontally:
5,343
+
32
=
5,375
With a little CSS, we quickly can transform into a stacked layout. We just add a single stacked class to the equation element:
<span class="equation stacked">
<span class="number">5,343</span>
<span class="operator">+</span>
<span class="number">32</span>
<span class="equals">=</span>
<span class="number">5,375</span>
</span>
The following CSS does the magic:
.equation.stacked {
display: inline-block;
}
.equation.stacked .number {
display: block;
margin-left: 1em; /* space for the operator */
text-align: right;
}
.equation.stacked .operator {
float: left;
}
.equation.stacked .equals {
display: block;
height: 0;
border-bottom: solid 1px black;
overflow: hidden;
}
This renders like this:
Here's a JSBin you can explore: http://jsbin.com/afemaf/1/edit
Do you mean something like this?: http://jsfiddle.net/PkfAU/2/
What you would be doing is using divs, because they are better for creating layouts. Paragraphs are also valid, as the other answer points out, but I find it easier to see with divs. In this case you will need a container div, and three horizontal ones, the second of them being also a container.
.plus and .number are floating inside its container .second, because you need them to use the same horizontal space (all floating elements require a wrapper).
HTML:
<div class="container">
<div class="first">5,343 </div>
<div class="second">
<div class="plus">+</div>
<div class="number">32</div>
</div>
<div class="third">
<div class="result">5,375</div>
</div>
</div>
CSS:
.container {
width:200px;
}
.first,
.second {
width:200px;
text-align:right;
display:table;
}
.plus {
width:auto;
float:left;
}
.number {
width:auto;
float:right;
}
.third {
width:200px;
text-align:right;
border-top:1px solid black;
}​
I think this may be your best bet:
HTML:
<div id="textbox">
<p class="upperNum">5,343</p>
<p class="lowerNum">
<span class="operand">32</span>
<span class="sign">+</span>
</p>
<br class="clear" />
<p class="line"><hr></p>
</div>
CSS:
#textbox { width: 75px; }
.upperNum { text-align: right; }
.operand { float: right; }
.sign { float: left; }
.clear { clear: both; }
Here's a fiddle that shows this effect also:
http://jsfiddle.net/8CPar/
Here, you can contain the bottom line in a paragraph, then give the operator and operand a separate span container that you can float, giving you the desired effect. Then, you add a "clear break" which clears the float, making the horizontal break show correctly.
I hope this helps!
There are some fine examples here, but I went through with the effort of making a fiddle so might aswell post it.
You just need to ensure that widths and alignments are set correctly and it should work out.
My JSFiddle Example.
<div id="list">
<span class="item">5472</span>
<span class="operator">+</span><span class="item operand">32</span>
<hr class="divider"/>
<span class="result">5504</span>
</div>
With css
.list
{
width:50px;
}
span
{
display:block;
margin-left:20px;
font-family:"Lucida Console", Monaco, monospace;
width:50px;
}
.operator
{
float:left;
width:20px;
margin-left:0px;
}
.divider
{
clear:both;
width:40px;
margin-left:20px;
}
.operand
{
float:left;
width:50px;
}
I also created an example using pre, that uses pre formatted text, so it should still be precise.
Classics,
<html>
<head>
<style type="text/css">
.textbox
{
width: 100px;
}
.upperNum
{
text-align: right;
width: 100%;
}
.sign
{
float: left;
text-align: left;
}
.lowerNum
{
text-align: right;
}
.secondline
{
clear: both;
width: 100%;
}
</style>
</head>
<body>
<div class="textbox">
<div class="upperNum">
5,343
</div>
<div class="secondline">
<div class="sign">
+
</div>
<div class="lowerNum">
32
</div>
</div>
<div>
<hr />
</div>
</div>
</body>
</html>

align an image with CSS

I have following HTML output which i can not change. These are just two links, one of them is text link, while other is the image.
The problem is that the image is appearing bit higher position than the text. I am trying to align the text in the middle of the image but not getting any success.
I have tried setting the padding-top, margin-top and vertical-align to the image, but none of them seem to work. I'll appriciate any help.
HTML:
<p>
<a href="#" class="link">
<img width="14" height="14" src="http://i50.tinypic.com/f08ehe.jpg">
</a>
my title
</p>
CSS:
.link img{
margin-top: 5px;
}
JSFiddle:
http://jsfiddle.net/e3vnQ/
Try using display: inline-block and vertical-align: middle: http://jsfiddle.net/e3vnQ/7/
add align="top"
<p>
<a href="#" class="link">
<img width="14" height="14" src="http://i50.tinypic.com/f08ehe.jpg" align="top">
</a>
my title
</p>
CSS:
.link img{
margin-top: 5px;
}
you can write the css like this :-
when anchor tag will come in p tag will stay vertical-align:middle; through mentioned below css
p{
font-size: 12px;
border: 1px solid red;
}
p a {
display:inline-block;
vertical-align:middle;
}
.link img{
margin-top: 5px;
}
or see the demo :- http://jsfiddle.net/e3vnQ/13/