I have a 'contact' page with three icons laid out horizontally for 'phone', 'email', and 'facebook'. Below each icon is some text, like the phone number, email address, and facebook link.
They're all centered up, except the email address text is bumped to the right a bit. I can't figure out whats causing it. Everything else is centered. Its probably something obvious that I am overlooking.
#contact {
clear: both;
position: relative;
width: 100%;
float: left;
display: block;
}
#contact img {
width: 100%;
overflow: hidden;
}
#phone {
background: yellow;
width: 300px;
height: 30px;
display: block;
float: left;
}
#email {
background: cyan;
width: 300px;
height: 30px;
display: block;
float: left;
}
#fbc {
background: pink;
width: 300px;
height: 30px;
display: block;
float: left;
}
#contactcont {
display: block;
clear: both;
height: 350px;
width: 960px;
margin-left: auto;
Margin-right: auto;
}
<!--Contact-->
<div id="contact">
<img src="Images/contactbanner.jpg" alt="contactbanner">
</div>
<a name="contanch"></a>
<div id="contactcont">
<div id="phone">
<img src="Images/phone.jpg" alt="phone" width="300" height="195">
<br>
<h5 align="center">1-800-759-5275</h5>
</div>
<div id="email">
<img src="Images/email.jpg" alt="email" width="300" height="195">
<br>
<h5 align="center"><a href="mailto:sales#company.com">
sales#company.com</a></h5>
</div>
<div id="fbc">
<img src="Images/fbcont.jpg" alt="fbcont" width="300" height="195">
<br>
<h5 align="center">Like us on Facebook!</h5>
</div>
</div>
After a quick look at your css it doesn't look to me like you are using text-align. If you use text-align:center in your css for each icons parent div you should get the result you are looking for.
Related
I have a portfolio website and I'm trying to align the pictures in the center of the page. I've tried
text-align
and
margin
but nothing seems to work. The code and CSS are as follows:
<div class="body">
<div class=responsive>
<div class=image>
<img class="gallery" src="../pics/placeholder.png">
<p></p>
</div>
</div>
and
.body {
text-align: center;
padding-top: 20px;
float: left;
}
.responsive {
padding: 5px;
float: left
}
.gallery {
width: 250px;
height: 250px;
}
Remove float:left from .responsive and add width:100% to .body
Then you don't need float on .body also.
But it all depends how you want to design your page.
Right now the float: left without the set width is messing up your ability to center things.
Are you looking for something like this?
.body {
padding-top: 20px;
float: left;
width: 100%;
}
.responsive {
padding: 5px;
float: left;
width: 100%;
}
.image {
margin: 0 auto;
width: 250px;
}
.gallery {
width: 100%;
height: auto;
}
<div class="body">
<div class="responsive">
<div class="image">
<img class="gallery" src="https://img1.wsimg.com/fos/sales/cwh/8/images/cats-with-hats-shop-02.jpg">
<p></p>
</div>
</div>
</div>
I'm trying to write a homepage with this little effect on a hover.
It should look something like this:
How would you do this? My code does not work like it should.
.stage_wrapper {
margin: 0 auto;
width: 1100px;
height: auto;
}
.work {
margin-left: 8px;
margin-right: 5px;
margin-bottom: 15px;
display: inline-block;
height: 350px;
width: 350px;
}
.work img {
width: 350px;
height: auto;
}
<div class="stage_wrapper">
<div class="stage">
<div class="work">
<a href="#" target="_blank">
<img src="//dummyimage.com/350" class="media" alt="#" />
<div class="caption">
<div class="work_title">
<h1>Something in 3 rows</h1>
</div>
</div>
</a>
</div>
</div>
</div>
Something like this?
.work {
width: 300px;
height: 300px;
line-height:300px;
text-align: center;
background-color: #2d3e50;
border: 10px solid #2a81b9;
color: white;
display: inline-block;
}
.work span {
display: none;
vertical-align: middle;
}
.work:hover span {
display: inline-block;
}
.work:hover img {
display: none;
}
<div class="work">
<span>Some text</span>
<img class="portfolio-image" src="http://dummyimage.com/300.png/09f/fff" width="300" height="300" />
</div>
During learning CSS I tried to make the exact example as you can see on the link below using clearfix (sorry for non-English text, but I have no other)
http://htmlbook.ru/files/images/layout2/3-41.png
I need to make it using float and clearfix hack
My code is:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Learning float</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="float.css">
</head>
<div class="col1 clearfix"><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p>This text should be below photos</p>
</div>
<p>This text should go below the columns</p>
<div class="footer">Подвал</div>
</body>
</html>
CSS
.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}
.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}
.photo {
float: left;
margin-right: 10px;
width: 170px;
}
img {
width: 150px;
height: 150px;
}
.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}
What's wrong with using of clearfix.
Will appreciate any answer!
the clearfix:after 'method' is used to wrap floatting child when the container is not in position absolute or fixed, floatting or in display:inline-block,inline-table or table.
In your case, the element you want to clear stands after a floatting element, you only need to clear them. both, left or right.
http://www.w3.org/wiki/CSS/Properties/clear
.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}
.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}
.photo {
float: left;
margin-right: 10px;
width: 170px;
}
img {
width: 150px;
height: 150px;
}
.clearfix {
clear: both;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}
/* add some space to clear the footer */
body {
padding-bottom:2em;/* average height of current footer: tune it if needed */
min-width:800px;
}
<div class="col1 "><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p class="clearfix">This text should be below photos</p>
</div>
<p class="clearfix">This text should go below the columns</p>
<div class="footer">Подвал</div>
I want to have a div with two images on the left, some centered text and some text on the right.
One of the many attempts:
http://jsfiddle.net/yu8bz4h4/
The problem is that I cant figure out how to get the p elements in the same line while keeping center and right the alignments
HTML:
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<p class="center" >centered</p>
<p class="right" >right</p>
</div>
CSS:
.outer {
height: 50px;
width: 800px;
}
.icon {
width: 44px;
height: 44px;
}
.outer p {
margin 0;
}
.center {
text-align: center;
width: auto;
}
.right {
text-align: right;
width: auto;
}
Replace all p with div.Then write css code.The text comes in one line.
Hope this works.
.outer {
height: 50px;
width: 800px;
}
.icon {
width: 44px;
height: 44px;
}
.outer p {
margin 0;
}
.center {
margin-left:50%;
width: auto;
position:absolute
}
.right {
margin-left:100%;
width: auto;
position: absolute;
}
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<div class="center" >centered</div>
<div class="right" >right</div>
</div>
I am pretty much sure you wanted something like this. Though your question is not clear. Never forget to write codes with semantic meaning. Here's your solution following more semantic way: codepen.
Or here:
.outer {
height: 50px;
width: 800px;
overflow: hidden;
}
.column {
width: 33.33%;
float: left;
}
.icon {
width: 44px;
height: 44px;
margin-right: 10px;
}
.center {
text-align: center;
}
.right {
text-align: right;
}
<div class="outer">
<div class="column">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
</div>
<div class="column">
<p class="center">centered</p>
</div>
<div class="column">
<p class="right">right</p>
</div>
</div>
Revised code in response to OP's comments:
.outer {
height: 50px;
width: 300px;
position: relative;
}
.icon {
width: 44px;
height: 44px;
float: left;
}
.center {
text-align: center;
width: 100%;
position: absolute;
left: 0;
}
.right {
position: absolute;
right: 0;
width: auto;
}
<div class="outer">
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<img class="icon" src="http://www.mobafire.com/images/champion/icon/leona.png" />
<p class="center">centered</p>
<p class="right">right</p>
</div>
In short, I'm trying to achieve a design similar to this:
Where the white boxes are images, and the red brushes are lines of text (the top line would hold a name and underneath their specialty) but using divs has proven to be problematic as I can't get the content to line up in a proper row - I'm not too keen on using a table for something like this due to compatibility problems, so I'm hoping someone on here would be able to assist me in trying to get it to work with divs before I fall back to that.
Below is the code I have so far and a jsfiddle accompaniment.
<div id="design-cast">
<h4>Design</h4>
<div class="member">
<img src="http://i.imgur.com/OBUL7se.jpg" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
<div class="member">
<img src="http://i.imgur.com/OBUL7se.jpg" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
<div class="member">
<img src="http://i.imgur.com/zmPeyso.png" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
</div>
CSS
.member {
display: inline;
}
.name {
display: inline;
}
.member img {
width: 13%;
display: block;
}
jsfiddle
Set a width on the .member elements, and float them.
jsFiddle example - it works responsively.
Notice, as pointed out in the comments, this also aligns the text at the bottom if the images are of differing demensions.
Updated CSS
#design-cast {
position: relative;
overflow: hidden;
}
.member {
float: left;
width: 31%;
margin: 1% 1% 45px 1%;
}
.name {
position: absolute;
bottom: 0px;
}
.member img {
width: 100%;
display: block;
}
An inline-block solution (this way you can put the whole thing in a text-align: center container if you want):
.member {
display: inline-block;
width: 150px;
height: 200px;
vertical-align: top;
}
.name {
display: inline;
}
.member img {
width: 100%;
display: block;
}
http://jsfiddle.net/MhRnz/2/
Just what you wanted and the text is centered.
.member {
display: inline-block;
width: 150px;
height: 200px;
vertical-align: top;
text-align:center;
}
.name {
display: inline;
}
.member img {
width: 100%;
display: block;
}
jsfiddle: http://jsfiddle.net/skoltyno/MhRnz/4/