Horizontal aligning with CSS - css

this is my first post here on StackOverflow and I'm quite excited about it since Google has brought me here quite often in the search of comprehensive answers.
Anyways, my question is quite simple but I can't seem to figure it out. I am trying to align three small icons on the same line but to the right of my page/post title. The post heading code looks like this:
<div class="post-heading">
<h1>Title</h1>
</div>
The 3 icons need to have their own ID in order to function properly. They are inserted like this:
`#icon_container {
position: relative;
margin: 0;
padding: 0;
line-height: normal;
font-size: medium;
width: 50px;}
`#icon_container #icon_1 {
float: right;
background-image: url(icon.png);
background-repeat: no-repeat;}`
`#icon_container #icon_1 A {
width: 24px;
height: 24px;
display: block;}`
So all I am trying to achieve here is to have the h1 title to the left, and on the same alignmnet to the right the 3 icons inserted with the above CSS. Can anyone help me out? I'd appreciate it a lot :)
Thanks all
EDIT
I forgot to mention the HTML code for the icons; here it is:
<div id="icon_container"><div id="icon_1"></div><div id="icon_2....</div><div style="clear:both"></div></div>

The h1 and the images needs to have the
style="display:inline"
if you want the images to have the same horizontal alignment.

you need to float post-heading and the icon elements to the left.
<div class="post-heading" > < h1 >Title < /h1 > < /div>
<div id='icon_container'>
<div id='icon_1'></div>
<div id='icon_2'></div>
</div>
#icon_container, #icon_1, #icon_2, .post_heading {float:left;}

Try floating your #post-heading h1 to the left:
#post-heading h1 {
float: left;
}

You have two options.
Fist one is
<div class="post-heading">
<h1>Title</h1>
<span class="icon_container"> [icon] </span>
</div>
.post-heading *{
display:inline;
}
Example
2nd is
.post_heading h1{float:left;}
Example

Related

I am trying to wrap my text around my images by floating the images to the left and right but nothing is happening

I am still learning and trying to get my text to wrap around two images, one left and one right, but nothing seems to be changing. I'm not sure what I'm doing wrong! :( Any suggestions are very appreciated!
Here is what it looks like.
.skill-row {
display: inline-block;
width: 50%;
margin: 100px auto 100px auto;
text-align: left;
line-height: 2;
}
.layout-pic {
width: 25%;
float: left;
margin-right: 30px;
}
.phones-pic {
width: 25%;
float: right;
}
<div class="skills">
<h2>My Skills.</h2>
<div class="skill-row">
<img class="circular" "layout-pic" src="images/layout.png" alt="website-layout-pic">
<h3>Create Your Vision</h3>
<p>I create using a complementary focus on color palettes, typography, and quality content. All of these elements help to bring your vision to life and really make it SHINE.</p>
</div>
<div class="skill-row">
<img class="circular" "phones-pic" src="images/seo.jpg" alt="phone-screens">
<h3>Fine Tune Your Vision</h3>
<p>As a developer, I know how to fine tune your website to give your audience the best functionality and visual appeal across devices.</p>
</div>
</div>
Multi classes should be wrapped in one string like :
<img class="one two three"/> ✔
and not like <img class="one" "two" "three"/> this is wrong

BEM naming and positioning

I'm new to BEM and i'm trying to implement this:
.details-header {
margin-top: 10px;
padding-bottom: 0;
display: block;
&__heading-panel {
margin-top: 10px;
}
&__heading {
display: inline-block;
}
}
Defining the same margin-top inside details-header__heading-panel is wrong, i know, but because there is element between details-header and details-header__heading-panel, i need this margin, how do i solve this, and also keep the code DRY?
EDIT: Here is the html:
<div class="details-header">
<div>Something</div>
<div class="details-header__heading-panel">
<h1 class="details-header__heading">
<span>something</span>
</h1>
<a>
Link
</a>
</div>
</div>
I need margin between that div between details-header and details-header__heading-panel
There's nothing wrong with defining the same margin-top inside details-header and details-header__heading-panel. Just keep going with your original code.
It's not copy-paste but just coincidence.

strange firefox float positioning, works fine in chrome/safari (CSS)

I'm having a weird issue in Firefox that I can't seem to fix. In both Chrome and Safari my float: left and float: right columns are working properly and in the right position, but when I view it in Firefox it's wayyyy messed up. My bottom header is in the section above it, and my columns are overlapping! I've been searching around but can't really find any concrete solutions to floating differences in Firefox -- can someone take a look at my code and tell me what's going on? Or does someone have any facts about Firefox floats that I'm not aware of? Thank you!
Here is my JsFiddle with my code in it. The floaters seem to be okay in Firefox for the JsFiddle.. just not on my page. Ugh, I'll keep looking but I'm pretty sure it's an issue with the floats.. Removing them made everything align nicely on Firefox. At least the left column.
Here's the relevant float css:
.fourtextleft {
font-family: Roboto;
text-decoration: none;
text-transform: none;
font-weight: 300;
font-size: .5em;
color: #666;
float: left;
width: 38%;
height: auto;
text-align: justify;
margin: 0% 5% 2% 0%;
padding: 4% 2% 3.5% 0%;
vertical-align: middle;
}
.fourtextright {
font-family: Roboto;
text-decoration: none;
text-transform: none;
font-weight: 300;
font-size: 1em;
color: #666;
float: right;
width: 30%;
height: auto;
text-align: justify;
margin: 3% 15% 2% 0%;
padding: 4% 0% 3.5% 2%;
vertical-align: middle;
}
.floaters {
clear: both;
}
Thank you for any help you may provide!
ஃ Shanling
Without the issue being replicable it's hard to say what it is. However, just by reading the issue and from personal experiences I would say try adding clear: both to the fourth CSS class (your header). Additionally, it may not be necessary to float your second list to the right. Instead, set the margins once your first list is floating left.
Again, it's hard to say for sure if the issue can't be replicated. Just making educated guesses at this point. If you do find a way to replicate it, definitely bring it on back!
I finally found the issue and it was a negative margin in one of the sections above the problem section. Seems that firefox doesn't like negative margins very much.. Thanks for the help guys :-)
Seem like IE should have had the problem not firefox, but hey if it works it works right?
http://coding.smashingmagazine.com/2009/07/27/the-definitive-guide-to-using-negative-margins/
I had the same problem with a layout of divs and I resolved my problem adding a white border to the divs using css, my sample code:
<head>
<title>Sample Layout</title>
<style type="text/css">
.divToLeft
{
width: 49.5%;
float: left;
}
.divToRight
{
width: 49.5%;
float: right;
}
.divToCenter
{
width: auto;
float: none;
**border-color: #FFF;
border-width: 1px;
border-style: solid;**
}
</style>
</head>
<body>
<div id="pnlMainHolder" style="width: 100%">
<div id="Rep0" class="divToCenter">
Rep0
</div>
<div id="pnlLeft" class="divToLeft">
<div id="Rep1" class="divToCenter">
rep1
</div>
<br />
<div id="Rep3" class="divToCenter">
rep3
</div>
<br />
<div id="Rep5" class="divToCenter">
rep5
</div>
<br />
<div id="Rep7" class="divToCenter">
rep7
</div>
</div>
<div id="pnlRight" class="divToRight">
<div id="Rep2" class="divToCenter">
rep2
</div>
<br />
<div id="Rep4" class="divToCenter">
rep4
</div>
<br />
<div id="Rep6" class="divToCenter">
rep6
</div>
<br />
<div id="Rep8" class="divToCenter">
rep8
</div>
</div>
<div id="Rep9" class="divToCenter">
rep9
</div>
</div>
</body>
I hope this help!
add clear:both for container and div's, it will solve your problem
.fourtextleft, .fourtextright, .floaters {
clear: both;
}

Putting 2 images in the same line

i have 2 images.My constraint is that I have to put a new div after the end of the 1st image.But they come on different lines.I googled a lot and found that float:left does the trick
I am already using it,but still they are coming in different lines.I dont know where I am going wrong.
Jsfiddle
span.tab {
padding: 0 50px; /* Or desired space*/
}
.span.tab {
display: inline-block;
float:left;
}
#div23 {
display: inline-block;
float: left;
}
#topdiv1 {
display: inline-block;
float: left;
}
#topdiv3 {
display: inline-block;
float:left;
}
html
<br />
<div id='topdiv1'><div id="widget1" class="sticky1">
<div id='topdiv3'>
<img src="https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50" />
<div id='div23'>
<span class="tab"></span>
<img src='https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50'/>
</div> </div>
Please help.
You don't apply the float to the parent container. You apply the float to the child elements:
#topdiv3 > * {
float:left;
}
http://jsfiddle.net/samliew/b9TWE/1/
If you want to remove the space between the images, remove the span.
http://jsfiddle.net/b9TWE/2/ this fixes it, you just need to have the <a> containing the first image to float
#topdiv3 > a{
float: left;
}
More on how floats work (great article)
By floating the first <a> containing the image you remove it from the regular document flow. the <div> containing the seconds image will resume the normal flow and position itself next to the <a>
Your topdiv3 must be closed before div div23.
<div id='topdiv1'>
<div id="widget1" class="sticky1">
<div id='topdiv3'>
<img src="https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50" />
</div>
<div id='div23'>
<img src='https://lh3.googleusercontent.com/-TrGnsESMpDc/AAAAAAAAAAI/AAAAAAAAAAA/lcUg6MaCxmg/photo.jpg?sz=50'/>
</div>
</div>
</div>
http://jsfiddle.net/arunu/8gvvr/
I've tested it on firefox and it worked the way you did.
But anyway, your html markup is a little bit confuse, doesn´t it?

Using CSS to position text after an image

I've trying to do something that I'm sure is simple, but I can't do it.
All I want to do is have an image and then some text after that image, and be able to control accurately the amount of space between the image and the text.
Here's my code:
<div class="wrap"><div style="width:189px;""position:relative;float:left;top:5px;">
<img src="30000000_1.jpg" style="position:absolute" width="189">
</div>
In my style sheet, wrap has these attributes:
.wrap {
/*text-align: left;*/
width: 1100px;
height: 870px;
background-color: white;
color: black;
padding: 10px;
margin: auto;
}
I want my text to look like this directly below the image:
Username
Age
Location
Currently, I just add loads of break tags to control where I have the text, but that's messy and there must be a better way.
Thanks in advance for any help.
<div class="wrap">
<div style="width:189px;position:relative;float:left;top:5px;">
<img src="30000000_1.jpg" style="position:absolute" width="189" />
</div>
<br clear="all" />
<div id="bottomText">
Username
<br /><br />
Age
<br /><br />
Location
</div>
</div>
CSS:
.wrap {
/*text-align: left;*/
width: 1100px;
height: 870px;
background-color: white;
color: black;
padding: 10px;
margin: auto;
}
#bottomText{
margin-top: 10px;
}
Change margin-top: 10px to the desired distance.
Change bottomText to a class rather than an id, if you plan on having more than one.
(Note: I removed your "" from the second div because I'm not sure why that was there.
Check this solution jsfiddle. Personally I will not use inline style, because it becomes more messy. I have used <ul> for the text. This can give you better control over the position of the text.
Just use an Unordered List for the text since it is a list. ul are "block level elements" so they will self-clear. And definitely use an external stylesheet vs. inline styles. External is much cleaner and easier to work with and make changes to. Example: http://jsfiddle.net/codeview/Fk3EK/
HTML:
<div class="wrap">
<img src="30000000_1.jpg">
<ul>
<li>Username</li>
<li>Age</li>
<li>Location</li>
<ul>
</div>
CSS:
.wrap {
/*text-align: left;*/
width: 1100px;
height: 870px;
background-color: yellow;
color: black;
padding: 10px;
margin: auto;
}
ul { list-style-type:none; }
li { padding:5px 0; }
I can't get it to work. Probably because you guys can't see the other code I have going on. But maybe I was approaching the problem in the wrong way.
Here's my code before I started fiddling with css positioning:
<br><br>
<div class="imgleft">
</div>
<br><br><br><br><br><br><br><br><br><br><br>
<span style="font-weight: bolder;font-size: 12px;"></br><br><br></br>
<font color="green"> User69 </font> <img src="online01.gif" alt="" border="0" style="float:center"><br>
Location:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">document.write(geoip_region_name());</script></span>
</script></br>
<br><br>
The problem is, the images have a set width, but vary in height, so sometimes I'll use 8 break tags, other times 7, but the exact distance beneath each image (where the text goes) is different. And it looks bad.
There are 3 images on the page, so it goes image, text (well, there's an image as well, flashing gif) below image, then another image with text below it, and so on. From top to bottom on the left of the page.
Here are the relevant bits from my css:
.imgleft {
float: left;
width: 120px;
}
.imgleft img {
clear: both;
width: 175px;
padding-bottom: 0px;
}
I'm certain I'm making this way more complicated than it needs to be! Sorry.
I've put a link to my code in the comments to the first answer, if someone could take a look. Thanks.

Resources