Css - Figure placing - css

Hi everyone I'm fairly new to HTML5/CSS, so I'm in need of some help.
The problem is the image won't go inside the box.
It's current placement is at the bottom left of the box.
I'd like to put it in the left side IN the box and the h2 and p on the image's right side
I'm just stuck as to what I'm missing
Also, is it okay if I create an id for each of the html element? it just seems like there are too many elements, and is this frowned upon in web design? If so, what's the proper way of doing it?
Thanks very much in advance
#featPost {
padding:70px 0px 0px 51.2px;
/* background-color: orange;*/
}
#featPost section {
width: 750px;
height: 261px;
border-style: double;
border-width: 4px;
border-color: black;
}
#featPost figure {
position: relative;
padding-right:20px;
float:left;
}
#featPost h1 {
font-family: "Calibri", Helvetica, sans-serif;
}
#featPost h2 {
padding: 50px 0px 10px 41.5px;
font-size: 30px;
text-align: center;
font-family: "Calibri", Helvetica, sans-serif;
}
#featPost section{
border-style: double;
border-width: 4px;
border-color: black;
}
#featPost p {
padding-bottom: 150px;
font-size: 20px;
}
<aside id="featPost"><article>
<h1> Featured Post </h1>
<section>
<h2> Essay as Easy as 1,2,3 </h2>
<figure>
<img src="images/example.png" width="250" height="250" alt="image of an egg">
</figure>
<p> What? There are rules in writing an essay?? Read more</p>
</section>
</article></aside>

I would suggest to float the image to the left. I updated your code a bit:
HTML:
<aside id="featPost">
<article>
<h1> Featured Post </h1>
<section>
<figure>
<img src="http://placehold.it/250x250" width="250" height="250" alt="image of an egg" />
</figure>
<h2> Essay as Easy as 1,2,3 </h2>
<p>What? There are rules in writing an essay?? Read more</p>
</section>
</article>
</aside>
CSS:
#featPost {
padding:70px 0px 0px 51.2px;
/* background-color: orange;*/
}
#featPost section {
width: 750px;
overflow: auto;
border: 4px double black;
}
#featPost figure {
float:left;
}
#featPost h1 {
font-family:"Calibri", Helvetica, sans-serif;
}
#featPost h2 {
margin-top: 50px;
font-size: 30px;
text-align: center;
font-family:"Calibri", Helvetica, sans-serif;
}
#featPost p {
font-size: 20px;
}
DEMO

h2 and p tag takes full width automatically that's why you are not able to float image.

Related

Positioning elements inside DIV

I have the following HTML:
<div class="Section__item">
<div class="Section__item__title">Title</div>
<div>
<img
class="Section__item__image"
width="120px"
src="/static/images/test.jpeg"
>
<i class="Section__item__icon icon-right-nav-workflow"/>
</div>
<div class="Section__item__text">This is a descritption</div>
</div>
And this is my style using scss:
.Section {
&__item{
border: #EEF3F7 solid 1px;
padding: 10px;
height: 150px;
margin-bottom: 15px;
box-shadow: 3px 3px #EEF3F7;
&:hover {
background-color: #E3F4FE;
cursor: pointer;
}
&__title {
text-align: left;
color: black;
font-size: 16px;
font-weight: 900;
}
&__image {
padding-top: 5px;
float: left;
}
&__icon {
float: right;
font-size: 40px;
}
&__text {
float: left;
}
}
}
The result is the following:
And what I need to get is the following:
I need the text to be under the image and where you see a "red" line in the right the text can't go further, if text is bigger then wrap text.
Also if you see right icon has to be positioned exactly on the same top level as the image.
Any clue?
There's loads of ways to do this (flexbox, grid, tables, absolute positioning). The oldschool way would be a clearfix but really you should avoid floats altogether. The simplest solution to what you have so far is to remove ALL of the float's; make the div that holds the image and the icon position:relative; and set the icon to position:absolute; top:0; right:0;.
.Section__item {
border: #EEF3F7 solid 1px;
padding: 10px;
min-height: 150px; /* changed to min-height so that it expands if there's loads of text */
margin-bottom: 15px;
box-shadow: 3px 3px #EEF3F7;
width:400px;
}
.Section__item:hover {
background-color: #E3F4FE;
cursor: pointer;
}
.Section__item__title {
color: black;
font-size: 16px;
font-weight: 900;
}
.Section__item__imagewrap {
position: relative;
}
.Section__item__image {
margin-top: 5px;
}
.Section__item__icon {
font-size: 40px;
line-height: 40px;
position: absolute;
top: 0;
right: 0;
}
.Section__item__text {}
<div class="Section__item">
<div class="Section__item__title">Title</div>
<div class="Section__item__imagewrap">
<img class="Section__item__image" width="120px" src="https://placeimg.com/320/240/any">
<i class="Section__item__icon icon-right-nav-workflow">i</i>
</div>
<div class="Section__item__text">This is a description. If the text is long it will wrap and the section__item's height will increase to fit the content.</div>
</div>
Uh... don't use float? Or rather, only use float on the one thing you want to break out of normal flow, which is the icon.
PS: <i> is not an autoclosing tag, so writing <i /> is incorrect even if browsers will likely ignore your mistake. Also, putting padding on an image doesn't seem right, I switched to margin-top in this code.
.Section__item {
display: inline-block; /* so it doesn't take full width of the snippet */
border: #EEF3F7 solid 1px;
padding: 10px;
height: 150px;
margin-bottom: 15px;
box-shadow: 3px 3px #EEF3F7;
}
.Section__item:hover {
background-color: #E3F4FE;
cursor: pointer;
}
.Section__item__title {
text-align: left;
color: black;
font-size: 16px;
font-weight: 900;
}
.Section__item__image {
margin-top: 5px;
vertical-align: top;
}
.Section__item__icon {
font-size: 40px;
float: right;
}
<div class="Section__item">
<div class="Section__item__title">Title</div>
<div>
<img class="Section__item__image" width="120" height="120">
<i class="Section__item__icon icon-right-nav-workflow">Icon</i>
</div>
<div class="Section__item__text">This is a descritption</div>
</div>

text-align/margin-left/etc. not working for my animated header

I have an animated header that is basically one stagnant word and preceeding it is a carousel of many words (in the same position) that fade in and out (thanks to animate.css). I followed a tutorial on youtube to get the basic webpage so it may look familiar or simple.
However, the preceeding words are stuck in complicated div's and headers to attempt to get multiple animations (enter and exit for each).
The problem is that when a long word comes onto the screen, it overlaps on the second word.
(Picture included)
To explain briefly, the button and text are all in a "display:table;" div and the words were normally just one cohesive sentence and worked fine. However, I've had to split them up and the only way to prevent them from being above/below one another (VERY annoying) was to force them to float left and right. However, when I delete the floats now (after much 'debugging') it doesnt seem to actually change the design, which greatly worries me. I have included my code. Please help! My idea right now is to make the text right aligned and relative to the second word, but everything I try seems to do absolutely nothing. If there are any other solutions I am all ears.
<section class="intro">
<div class="inner">
<div class="content">
<section style="clear: both">
<div style="position:absolute" z-index="1">
<h1 z-index="inherit"display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="0s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="1s">Loving</div></h1>
</div>
<div style="position:absolute" margin-left="15%" z-index="2">
<h1 z-index="inherit" display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="1s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="2s">Enjoying</div></h1>
</div>
<div style="position:absolute" z-index="3">
<h1 z-index="inherit" display="inline-block" class="os-animation" data-os-animation="fadeInDown" data-os-animation-delay="2s">
<div text-align="right" z-index="inherit" class="os-animation" data-os-animation="fadeOutDown" data-os-animation-delay="3s">Exploring</div></h1>
</div>
<h1 style="float: right">Irelnd</h1>
</section>
<section style="clear:both" class="os-animation" data-os-animation="fadeInUp" data-os-animation-delay="5s">
Get Started
</section>
</div>
</div>
</section>
css:
#import url('https://fonts.googleapis.com/css?family=Yantramanav:100');
#import url('https://fonts.googleapis.com/css?family=Montserrat:400');
html,body{
margin:0;
padding:0;
height:100%;
width:100%;
}
#carousel {
background-color: green;
text-align: center;
vertical-align: middle;
float: left;
}
#Dubai{
background-color: red;
}
.intro{
height:100%;
width:100%;
margin:auto;
background: url(https://static.pexels.com/photos/470641/pexels-photo-470641.jpeg) no-repeat ;
display: table;
top:0;
background-size:cover;
}
.intro .inner{
display: table-cell;
vertical-align:middle;
width: 100%;
}
.content{
max-width:480px;
margin: 0 auto;
text-align: center;
padding-bottom: 28%;
padding-left: 4%;
}
.content h1 {
font-family: 'Yantramanav', sans-serif;
font-size: 600%;
font-weight: 100;
color: #E1efe9;
line-height: 55%;
}
.btn {
font-family: 'Montserrat', sans-serif;
font-size: 135%;
font-weight: 400;
color: #3c4f1f;
text-transform: uppercase;
text-decoration: none;
border: solid #3c4f1f;
padding:10px 20px;
border-radius: 9px;
transition: all 0.3s;
}
.btn:hover{
color: #a0afa8;
border: solid #a0afa8;
}
p{
font-size: 150%;
line-height: 120%;
font-family: sans-serif;
}
/*--- Media Queries --*/
#media screen and (max-width: 900px) {
.content{
padding-bottom: 30%;
max-width: 320px;
}
.content h1{
font-size: 450%;
}
.btn{
font-size: 130%;
padding: 9px 15px;
}
}
#media screen and (max-width: 768px) {
.content{
padding-bottom: 40%;
max-width: 210px;
}
.content h1{
font-size: 300%;
}
.btn{
font-size: 110%;
padding: 9px 15px;
}
p{
font-size: 120%;
line-height: 100%;
}
}
#media screen and (max-width: 480px) {
.content{
padding-bottom: 50%;
max-width: 173px;
}
.content h1{
font-size: 250%;
}
.btn{
font-size: 90%;
padding: 4px 12px;
}
p{
font-size: 100%;
line-height: 100%;
}
}

Logo doesn't float left in header?

I am trying to float my logo to the left in the header but it doesn't float to left at all. I would really appreciate if someone could point our my error since I am new to CSS.
This is my website if you would like to see my problem live: http://cashski.com/
Here is my HTML code:
<div id="navigation">
<div class="center_navigation">
Contact
Instagram Followers
Instagram Photo Likes
<img src="img/logo.png" />
</div>
</div>
Here is my CSS code:
body {
padding: 0px;
margin: 0px;
font-family: Optima, Segoe, "Segoe UI", Candara, Calibri, Arial, sans-serif;
}
#navigation{
width: 100%;
height: 50px;
margin: 0px auto;
position: relative;
background-color: #2d5b89;
border-bottom: 1px solid #244a75;
}
.center_navigation {
width: 960px;
height: 50px;
margin:0px auto;
font-size: 16px;
}
.center_navigation a {
padding: 10px 0 10px 30px;
float: right;
margin-top: 4px;
color: #babcc5;
text-decoration: none;
}
.center_navigation a:hover {
color: white;
}
.center_navigation a img {
float: left;
}
The problem is your all anchor tags are float:right and your image is inside a anchor tag, so making img float:left doesn't change much.
So you either need to put the style on the container of image ie. anchor tag like this
<a href="index.php" style="float: left;">
<img src="img/logo.png">
</a>
or if your image is always in last anchor tag then you can also use this
.center_navigation a:last-child{
float: left;
}
Js Fiddle Demo

How I can set a different font size for my text by css?

My css code is
#footer .right {
font-weight: bold;
color: #ffffff;
margin: 0px auto;
padding: 10px 0px 0px;
float: right;
}
and the text is
<p class="right">Copyright © 2012 SiteName. All Rights Reserved.<br />
Powered By ScriptName</p>
I need to set :
text font size (12px) for "Copyright © 2012 SiteName. All Rights Reserved."
and text font size (11px) for "Powered By ScriptName"
It should be exactly look like that
How i can do that please ?
Update
Thanks everyone for your useful help :)
My Regards
Using a span would be the easiest. Like this...
<p class="right">Copyright © 2012 SiteName. All Rights Reserved.<br />
<span class="small">Powered By ScriptName</span></p>
And the css
#footer .right {
font-size: 12px;
}
.small {
font-size: 11px;
}
Use two different paragraphs for each line. Give each one their own class. Apply their specific styles by targeting those classes.
Wrap them in a div and apply the common styles to it:
HTML
<div class="footerTxt">
<p class="copyright">Copyright © 2012 SiteName. All Rights Reserved.</p>
<p class="poweredBy">Powered By ScriptName</p>
</div>
CSS
.footerTxt {
font-weight: bold;
color: #ffffff;
margin: 0px auto;
padding: 10px 0px 0px;
float: right;
}
.copyright {
font-size: 12px;
}
.poweredBy {
font-size: 11px
}
HTML:
<p class="right">Copyright © 2012 SiteName. All Rights Reserved.<br />
<span>Powered By ScriptName</span></p>
CSS:
#footer .right {
...
font-size: 12px;
}
#footer .right span {
font-size: 11px;
}
Example: http://jsfiddle.net/4CpRk/
In order to get your footer to look identical to the image you supplied some additional styling was necessary apart from the font sizing, however it was also necessary to wrap the second line in order to be able to reference it in the css. After doing so the <br /> was no longer necessary.
Here is the example
http://jsfiddle.net/UmFkv/2/
html:
<div id="footer">
<p class="right">Copyright © 2012 SiteName. All Rights Reserved.
<span id="secondline">Powered By ScriptName<span>
</p>
</div>​
css:
#footer {
background:#25B5EA;
width: 421px;
height: 46px;
font-family:Verdana, Geneva, sans-serif;
}
#footer .right {
color: #ffffff;
margin: 0px auto;
padding: 7px 0px 0px;
width: 330px;
font-size: 12px;
float: right;
line-height: 16px;
}
#footer #secondline {
font-size: 11px;
}
​

CSS Looks Great in FF and Chrome but not in IE8

Yes another question that is a little Unique because I cant find the same question anywhere. I am trying to make a website and so far it looks great in FF and Chrome but in IE8 it looks like crap. I dont know how to fix it been looking up others to see if they are like mine but are not.
the site is funspot.zxq.net yeah I will be changing that up too that is just my start but this is the code
<html>
<head>
<title>The Fun Spot </title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container">
<div id="header">
</div>
<div id="horizontalnav">
<div class="navlinks ">
<ul>
<li>Facebook</li>
<li>Gaia</li>
<li>Roblox</li>
<li>Adventure Quest </li>
<li>Anime Freak</li>
<li>Youtube</li>
</ul>
</div>
</div>
<div id="leftnav">
<p>Info: Love the Knicks as you can see so when I post some stuff here about this. This site would be about me and get better as I become a better developer. </p>
</div>
<div id="theMeat" >
<p><img src="AmareStoudemireNY.jpg" alt="Amare Stoudemire" > This is my favorite Knicks Player right now. Even though Carmelo Anthony is awesome, Stoudemire started the road to the playoffs not really 100% by himself but by himself. </p>
<p> <img src="ewing_knicks.jpg" alt="Patrick Ewing" > This is the man and my favorite player of all times! He was great and I wish that they never traded him his final year because that was an a injustice. He gave them all he ever had and they dissed him, if you agree send me a email. Daddy</p>
<p><img src="favoriteKnicksTeam.jpg" alt="1994 Team" > Now this here is the team you dont forget about. I think the Knicks put together alot of awesome teams but this one was my Favorite. The starters were Patrick Ewing, Anthony Mason, Derek Harper, John Starks, and Charles Oakley. Oh and Pat Riley as the coach. Yeah baby.</p>
</div>
<div id="rightnav">
<p>There will be site's that helped me create this site OOH Rah </p>
</div>
<div id="footer">
<p align="center">Date Edited 20110408</p>
</div>
</div>
</body>
</html>
and for the CSS
#container {
width: 100%;
}
#header{
width: 89%;
height: 15%;
position: relative;
background-image: url(Header.jpg);
border-bottom: 2px solid #000000;
}
#horizontalnav {
width: 89%;
height: 30px;
position: relative;
background-color: #00008B;
border-bottom: 2px solid #000000;
}
.navlinks {
position: absolute; top: 4px; left:240px;
}
.navlinks ul {
margin: auto;
}
.navlinks li {
margin: 0px 18px 0px 0px;
list-style-type: none;
display: inline;
}
.navlinks li a {
color: #FF8C00;
padding: 5px 12px 7px;
text-decoration: none;
font-size: 16px;
font-family: Courier New;
}
.navlinks li a:hover{
color: #ffffff;
text-decoration: underline;
}
#header p {
color: #000000;
font-family: Courier New;
font-weight: bold;
}
#leftnav {
float: left;
width: 10%;
height: 70%;
background-color: #00008B;
border-right: 1px dashed #694717;
}
#leftnav p{
color : #FF8C00 ;
font-family : Courier New ;
font-size : 16px ;
}
#rightnav {
float: left;
width: 9.9%;
height: 70%;
background-color: #00008B;
border-left: 1px dashed #694717;
}
#rightnav p{
color : #FF8C00 ;
font-family : Courier New ;
font-size : 16px ;
}
#theMeat {
background-color: #FF8C00 ;
overflow : auto ;
float: left;
width : 68.9% ;
height : 70% ;
padding: 0px 0px 0px 0px;
}
#theMeat p {
color : #00008B ;
font-family : Courier New ;
font-size : 16px ;
}
#footer {
clear: both;
background-color: #00008B;
width : 88.9% ;
}
#footer p{
color : #FF8C00 ;
font-family : Courier New ;
font-size : 16px ;
}
Here I fixed how it looks in ie8. I change the height from percentage to pixels and it worked.
If that works for you, use it.
here is how it looks http://i.stack.imgur.com/en1P0.png
The HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The Fun Spot</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type><LINK
rel=stylesheet type=text/css href="/style.css">
<META name=GENERATOR content="MSHTML 8.00.6001.19019"></HEAD>
<BODY>
<DIV id=container>
<DIV id=header></DIV>
<DIV id=horizontalnav>
<DIV class="navlinks ">
<UL>
<LI><A href="http://www.facebook.com/" target=_blank>Facebook</A>
<LI><A href="http://www.gaiaonline.com/" target=_blank>Gaia</A>
<LI><A href="http://www.roblox.com/" target=_blank>Roblox</A>
<LI><A href="http://www.adventurequest.com/" target=_blank>Adventure Quest</A>
<LI><A href="http://www.animefreak.tv/" target=_blank>Anime Freak</A>
<LI><A href="http://www.youtube.com/" target=_blank>Youtube</A>
</LI></UL></DIV></DIV>
<DIV id=leftnav>
<P>Info: Love the Knicks as you can see so when I post some stuff here about
this. This site would be about me and get better as I become a better developer.
</P></DIV>
<DIV id=theMeat>
<P><IMG alt="Amare Stoudemire" src="stack_files/AmareStoudemireNY.jpg"> This is
my favorite Knicks Player right now. Even though Carmelo Anthony is awesome,
Stoudemire started the road to the playoffs not really 100% by himself but by
himself. </P>
<P><IMG alt="Patrick Ewing" src="stack_files/ewing_knicks.jpg"> This is the man
and my favorite player of all times! He was great and I wish that they never
traded him his final year because that was an a injustice. He gave them all he
ever had and they dissed him, if you agree send me a email. Daddy</P>
<P><IMG alt="1994 Team" src="stack_files/favoriteKnicksTeam.jpg"> Now this here
is the team you dont forget about. I think the Knicks put together alot of
awesome teams but this one was my Favorite. The starters were Patrick Ewing,
Anthony Mason, Derek Harper, John Starks, and Charles Oakley. Oh and Pat Riley
as the coach. Yeah baby.</P></DIV>
<DIV id=rightnav>
<P>There will be site's that helped me create this site OOH Rah </P></DIV>
<DIV id=footer>
<P align=center>Date Edited 20110408</P></DIV></DIV></BODY></HTML>
THE CSS
#container {
WIDTH: 100%
}
#header {
BACKGROUND-IMAGE: url(http://funspot.zxq.net/Header.jpg); BORDER-BOTTOM: #000000 2px solid; POSITION: relative; WIDTH: 89%; HEIGHT: 100px;}
#horizontalnav {
BORDER-BOTTOM: #000000 2px solid; POSITION: relative; BACKGROUND-COLOR: #00008b; WIDTH: 89%; HEIGHT: 30px
}
.navlinks {
POSITION: absolute; TOP: 4px; LEFT: 240px
}
.navlinks UL {
MARGIN: auto
}
.navlinks LI {
LIST-STYLE-TYPE: none; MARGIN: 0px 18px 0px 0px; DISPLAY: inline
}
.navlinks LI A {
PADDING-BOTTOM: 7px; PADDING-LEFT: 12px; PADDING-RIGHT: 12px; FONT-FAMILY: Courier New; COLOR: #ff8c00; FONT-SIZE: 16px; TEXT-DECORATION: none; PADDING-TOP: 5px
}
.navlinks LI A:hover {
COLOR: #ffffff; TEXT-DECORATION: underline
}
#header P {
FONT-FAMILY: Courier New; COLOR: #000000; FONT-WEIGHT: bold
}
#leftnav {
BACKGROUND-COLOR: #00008b; WIDTH: 10%; FLOAT: left; HEIGHT: 400px; BORDER-RIGHT: #694717 1px dashed
}
#leftnav P {
FONT-FAMILY: Courier New; COLOR: #ff8c00; FONT-SIZE: 16px
}
#rightnav {
BORDER-LEFT: #694717 1px dashed; BACKGROUND-COLOR: #00008b; WIDTH: 9.9%; FLOAT: left; HEIGHT: 400px;
}
#rightnav P {
FONT-FAMILY: Courier New; COLOR: #ff8c00; FONT-SIZE: 16px
}
#theMeat {
PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ff8c00; PADDING-LEFT: 0px; WIDTH: 68.9%; PADDING-RIGHT: 0px; FLOAT: left; HEIGHT: 400px; OVERFLOW: auto; PADDING-TOP: 0px
}
#theMeat P {
FONT-FAMILY: Courier New; COLOR: #00008b; FONT-SIZE: 16px
}
#footer {
BACKGROUND-COLOR: #00008b; WIDTH: 88.9%; CLEAR: both
}
#footer P {
FONT-FAMILY: Courier New; COLOR: #ff8c00; FONT-SIZE: 16px
}
You are in quirks mode and IE won't attempt to perform like the other far more modern browsers. Add this to your first line: <!doctype html>. Then see where we stand.

Resources