I'm in the process of creating a website, and am trying to align text beside an image. It sounds easy, but for some reason, I just can't seem to get it.
Here is an image of how I'm trying to get the images and text to appear:
So far I've tried the following HTML:
<div class="example">
<div class="eg1">
<img src="eg1.gif" />
<h2>Example 1</h2>
<p>This is an example</p>
</div>
<div class="eg2">
<img src="eg2.gif" />
<h2>Example 2</h2>
<p>This is another example</p>
</div>
</div>
and CSS:
.example {
display: inline-block;
}
.eg1, .eg2 > img {
float: left;
}
.eg1, .eg2 > h2 {
float: left;
}
.eg1, .eg2 > p {
float: left;
}
At the moment is appears all messed up. They appear underneath each other, and the text appears on the wrong side of the image.
What is the best way to achieve this?
may be like this?
<div class="block">
<figure><img src="http://lorempixel.com/100/100/" alt=""></figure>
<h1 class="title">the title here</h1>
<p class="excerpt">the text goes here</p>
</div>
<div class="block">
<figure><img src="http://lorempixel.com/100/100/" alt=""></figure>
<h1 class="title">the title here</h1>
<p class="excerpt">the text goes here</p>
</div>
http://jsfiddle.net/g57bB/7/
I recently set up navigation on a site like that. The key is in setting the image as the background and offsetting it with the center left no-repeat Though it was in a ul and a li format, I used the CSS in this format:
CSS
li a {
font-size:20px;
color:#f6f9db;
padding-left:75px;
background:url(icon-up.png) center left no-repeat;
text-decoration:none;
line-height:30px;
text-shadow: -2px 2px 1px #551508;
}
li a:hover {
color:#551508;
display:inline-block;
padding-left:75px;
background:url(icon.png) center left no-repeat;
text-shadow: -1px 1px 0px #f6f9db;
}
Related
(If there is a simpler solution to this problem, please tell me)
I want this website to have 2 sections of text, one on each side of the screen.
I did this successfully. I used text align and translate3d to move the text to the right, then up.
The only problem was that the width of the the text on the right blocked the text on the left from being interacted with.
I decided to change the width of the text on the right side, and when I did, the text alignment wasn't working, because of the margins (the inspect said margins).
I decided to change the margins to 0, and nothing happened.
I have no idea why, but here is some code:
.mid{
margin: 0px 0px 0px 0px;
font-family:myfont;
font-size:150px;
}
.midl{
text-align:left;
}
.midr{
width:625px;
text-align:right;
transform:translate3d(0,-181px,0)
}
</div>
<div id="midwlink">
<p id="games" class="mid midl">Games</p>
<p id="calculators" class="mid midr">Calculators</p>
<p id="animations" class="mid midl">Animations</p>
<p id="pictures" class="mid midr">Pictures</p>
</div>
I later added this, but still nothing happened:
#calculator{
margin: 0 !important;
}
So, is there any possible way to have text on both sides of the screen at the same time, with them being separate from each other?
Or is there a way to COMPLETELY remove margins?
.mid {
margin: 0;
font-family: myfont;
font-size: 50px;
float: left;
width: 50%;
}
.mid:nth-child(even) {
text-align: right;
}
<div id="midwlink">
<p id="games" class="mid">Games</p>
<p id="calculators" class="mid">Calculators</p>
<p id="animations" class="mid">Animations</p>
<p id="pictures" class="mid">Pictures</p>
</div>
There are many ways to achive side by side layouts in HTML. One of the simplest is to use two divs side by side, as in this snippet.
div {
width: 49%;
display: inline-block;
}
div.right {
text-align: right
}
<div class="left">
Hello left
</div>
<div class="right">
Hello right
</div>
Could it be the wrong <div> tag in the beginning? You have started with a closing div tag.
If you fix that, then you get what you want it to do.
.mid{
margin: 0px 0px 0px 0px;
font-family:myfont;
font-size:50px;
}
.midl{
text-align:left;
}
.midr{
width:625px;
text-align:right;
transform:translate3d(0,-181px,0)
}
<div>
<div id="midwlink">
<p id="games" class="mid midl">Games</p>
<p id="calculators" class="mid midr">Calculators</p>
<p id="animations" class="mid midl">Animations</p>
<p id="pictures" class="mid midr">Pictures</p>
</div>
This is my css code
.my-works {
margin-top:0;
width: 100%;
background-color: orange;
}
.my-works h3 {
text-align:center;
}
here's my html code
<section class="my-works">
<h3> MY WORKS </h3>
<article>
<h4>My Blog</h4>
<img src="blog.png">
</article>
<article>
<h4>A Tambay Inspired Flappy Bird - Yotni Bird</h4>
<img src="flappybird.png">
</article>
</section>
This is the result of the site
I already change the css margin to 0 but still it has space between the two.
You need to set the h3 to have margin-top:0
.my-works h3 {
margin-top:0;
}
Not the container
I know this is amateur stuff but I've been trying and trying to get this right and i can't seem to get a fix.
Please take a look at the website screenshot. I'm attempting to make the "call..." text to be inline and to the right of the best#flooring logo.
Here's the code HTML:
<div class="level0">
<div class="topbar">
<h1><% title_content %></h1> <div class="facebookbutton"></div>
<div class="phonetop">Customer services: <strong>0844 209 1560</strong></div>
</div>
</div>
<div class="header">
<div class="level0">
<div class="logonumber">
<img src="<% secure_url %>images/logo.png?r=1" alt="<% title_content %>" />
<div class="headernumber">
<h2>Call <br /> 01132 186 212 <br />for the best prices</h2></div>
</div>
<div class="headfloat">This contains all of the content located on the right hand side </div>
CSS
.level0{
width:970px;
margin:0px auto;
clear:both;
}
.topbar{
height:41px;
color:#747474;
/*text-shadow: 1px 1px 2px #000;*/
}
.header{
background:#fff;
height:166px;/*was 126*/
}
.logonumber {
float:left;
display:inline-block;
}
.logo{
display:block;
}
.headernumber{}
contains the nav, the card images, basket and search.
Any help would be much appreciated.
You need
.headernumber {
float: left;
}
and you also need to decrease the size of the .headfloat element because its width does not allow all three elements in the same line
so change the .headfloat rule to
.headfloat {
float: right;
padding-top: 13px;
text-align: right;
width: 350px; /*was 460px*/
}
I'm trying to create a line of text followed by an image on the same line of a grid with 12 columns.
For some reason image 2 is displaying in line with image 1 text and then image 2 is showing with image 1 text.
It looks like the text and image elements within the div are above/below each other. What I want is them to be side by side.
How do I resolve this? I've posed the code here
http://jsfiddle.net/Dano007/P7nzy/embedded/result/
http://jsfiddle.net/Dano007/P7nzy/
HTML
<div class="grid_6">
<p class="text">"The best selection of cheese I've ever seen! Cannot wait for our next order!"</p>
<p class="image omega"><img src="img/cheese1.jpg" alt="Contact us"></p>
</div>
<div class="grid_5">
<p class="image"><img src="img/cheese2.jpg" alt="Contact us"></p>
<p class="text omega" id="text_left">"Wow, amazing cheese selection and very fast delivery!"</p>
</div>
CSS
.text {
display:inline-block;
font-size: 3.0em;
text-align: right;
}
#text_left {text-align: left; }
.image {
display:inline-block;
text-align: center;
border:solid 4px #6b5221;
}
You can try adding a width to your text content like shown below.
.text {
display:inline-block;
font-size: 3em;
text-align: right;
width: 80%; /* added this */
}
Demo Fiddle
You can use it the way Ollie has mentioned in his answer also. It depends on how you want the appearance to be.
Like this fiddle: http://jsfiddle.net/Hive7/P7nzy/2/
What you needed to do was set the display of the text elements to inline like this:
display: inline;
Also add:
white-space: nowrap;
How about:
CSS:
div.newSection {
overflow: hidden;
}
div.floatLeft {
float: left;
margin-right: 10px;
}
img { height: 50px; }
HTML:
<body>
<div class="newSection">
<div class="floatLeft">
<img src="img/cheese1.jpg" alt="Contact us" />
</div>
<div class="floatLeft">"The best selection of cheese I've ever seen! Cannot wait for our next order!"</div>
</div>
<div class="newSection">
<div class="floatLeft">
<img src="img/cheese2.jpg" alt="Contact us" />
</div>
<div class="floatLeft">"Wow, amazing cheese selection and very fast delivery!"</div>
</div>
</body>
JSFiddle: http://jsfiddle.net/markwylde/P7nzy/6/
Can anyone guide me, How can I create a 'almost' square background in CSS?
I want to get the brown background and have text on it with the error bullets and how to create the dotted yellow on the top right in CSS?
My working progress is here:
HTML:
<body>
<div id="contentContainer">
<div id="setBackground">
<div id="header"> <span class="style1">This is LOGO </span>
<hr />
<div id="body_block">
<p class="intro">Introduction</p>
<h1> Back </h1>
Click Here
<h2> Next </h2>
Click Here
<p>More about Web Design:</p>
<p>• Bla bla bla... .</p>
<p>Contact:</p>
<p>• Bla bla bla...</p>
<div id="footer">
<!--hr class="footer"/-->
<p>© Copyright 2013
sample.com |
More Site
</p>
</div>
</div>
</div>
</div>
</div>
</body>
CSS:
#charset"UTF-8";
/* CSS Document */
hr {
clear:both;
border: 0;
height:12px;
width:100%;
background-color: #993300;
}
.intro {
color: #1e2a74;
font-size:16px;
font-weight:bold;
font-family:Arial, Helvetica, sans-serif;
}
#footer {
background-color:#6994AF;
clear: both;
color: #FFFFFF;
font-size: 0.8em;
margin: 0;
padding: 0;
font-family:Arial, Helvetica, sans-serif;
}
#footer p {
border-top: 1px solid #83CDE1;
margin: 0;
padding: 15px 0;
text-align: left;
}
#footer a {
text-align:right;
}
.style1 {
font-size: 24px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
background-color: #FFFFFF;
}
the border radius CSS attribute can help you obtain rounded corners - specifically something like this should do the trick for the pink element containing everything else.
div {
/* border-radius: Top-Left , Top-Right, Bottom-Right, Bottom-Left */
border-radius: 20px 5px 20px 5px;
}
i would personally break this up into a few divs, a header and body. put the background yellow dots with color on the top div and apply border radius to the top pieces.
then place the content other divs within the body and apply those border styles for each case.
this however is just one way to do it I am sure there are plenty of other wayas.
more info about CSS Rounded borders here
Try this out.
border-bottom-right-radius:20px;
Border radius is what you want to look at: http://www.w3schools.com/cssref/css3_pr_border-radius.asp
In your case, it would go something like this:
border-radius: 100px 0 100px 0; /*top-left top-right bottom-right bottom-left */
http://jsfiddle.net/spKMM/
Here's the jsFiddle
Your design is really poor. You don't have to nest all divs inside one another. I changed your html a bit(just rearranged your divs and added two new divs leftDiv and rightDiv)
HTML:
<body>
<div id="contentContainer">
<div id="setBackground">
<div id="header"> <span class="style1">This is LOGO </span>
<hr />
</div>
<div id="body_block">
<p class="intro">Introduction</p>
<h1> Back </h1>
Click Here
<h2> Next </h2>
Click Here
</div>
<div id="leftDiv">
<p>More about Web Design:</p>
<p>• Bla bla bla... .</p>
</div>
<div id="rightDiv">
<p>Contact:</p>
<p>• Bla bla bla...</p>
</div>
<div id="footer">
<!--hr class="footer"/-->
<p>
© Copyright 2013
sample.com |
More Site
</p>
</div>
</div>
</div>
</body>
Add these rules to your CSS:
#leftDiv{
clear:both;
width:200px;
background:brown;
float:left;
border-top-left-radius:25px;
}
#rightDiv{
margin-left:20px;
border-bottom-right-radius:25px;
background:brown;
float:left;
}
Try border-radius properties
Example 1
Div{border-radius:10px;}
Example 2
Div{border-radius:10px 15px;}
For better information visit:-
CSS-TRICKS
What about this? You can create a "pseudo" "hr" tag with a div :P
//IN HTML
<div id="CUSTOM_HR_WITH_TEXT">SAMPLE TEXT // Custom "hr" tag with text.</div>
//AND IN CSS
#CUSTOM_HR_WITH_TEXT {
border-radius: 10px 10px 10px 10px;
border: 0;
height: auto;
width: auto;
background-color: #993300;
color: #fff;
text-align: center;
}