I am running with a minor CSS problem. I want to have a dual lined text right aligned but they should be intended in a single line. No matter How long the text in the first line grows, the text "Small" should follow and indent itself to the left with the Long text. Both should be aligned to the right though.
ACTUAL
EXPECTED
My js fiddle here
<div>
<div id="blocker">
ABCD
</div>
<div id="wrapper">
<p id="inner">
<h3>A very very long text</h3>
<h3>Small</h3>
</p>
</div>
</div>
#blocker{
background-color: green;
float: left;
width: 30%;
height: 100px;
}
#wrapper{
text-align: right;
background: grey;
height: 100px;
}
#inner{
text-align: left;
}
just make these changes in your csss and html:
CSS:
#inner{
display: inline-block;
float: right;
text-align: left;
}
HTML:
<div id="inner">
<h3>A very very long text</h3>
<h3>Small</h3>
</div>
Demo: http://jsfiddle.net/ykmupf1r/6/
You need to put a containing div around the text in the right section like below;
<div class="txt">
<p id="inner"> </p>
<h3>A very very long text</h3>
<h3>Small</h3>
<p></p>
</div>
And add styles like below;
.txt {
float: right;
text-align: left;
width: auto;
}
There is no logical reason at all to put an <h3> inside a <p>. That's about as un-semantic as you can get. You should use tags to best suit your content. If you don't have any headers, don't use any header tags. Just don't ever put a header inside a paragraph.
Demo
css
#blocker{
background-color: green;
float: left;
width: 30%;
height: 100px;
}
#wrapper{
background: grey;
height: 100px;
}
#inner{
float: right;
text-align: left;
font-size: 18px;
font-weight: bold;
}
html
<div>
<div id="blocker">
ABCD
</div>
<div id="wrapper">
<p id="inner">
A very very long text
<br/>
Small
</p>
</div>
</div>
try this:
HTML
<div>
<div id="blocker">
ABCD
</div>
<div id="wrapper">
<p id="inner">
<h3>A very very long text</h3>
<h3>Small</h3>
</p>
</div>
</div>
CSS
#blocker{
background-color: green;
float: left;
width: 30%;
height: 100px;
}
#wrapper{
text-align: right;
background: grey;
height: 100px;
}
#wrapper > h3{ text-align:left}
Also you can add a new div for say the margin-left
Related
I have 2 divs that contain an image and some text. When I try floating the image to the left using float:left; the other elements have weird formatings . Below is my code and an image of what happens:
HTML
<div class="skills">
<h2>My Skills.</h2>
<div class="skill-row">
<img class="muscle"src="images/strong.png" alt="muscle">
<h3>Physical Capabilities</h3>
<p>I am physically fit, tall and lean from years of playing outside.</p>
</div>
<div class="skill-row">
<img class="brain" src="images/brainstorm.png" alt="brain">
<h3>Intelligence</h3>
<p>I am able to perform mathematical calculations with ease, and understand advanced concepts.</p>
</div>
</div>
CSS
.skill-row{
width: 50%;
margin: 100px auto 100px auto;
text-align: left; line-height: 2;
}
.muscle {
width: 25%;
float: left;
}
.brain {
width: 25%;
float: left;
}
Image of Site
What can I do to float the image to the left while keeping the rest of my webpage in tact?
Float affects other inline elements. You can clear the float on the other elements, in this case:
h3 {
clear: left;
}
More about css 'clear'
https://www.w3schools.com/cssref/pr_class_clear.asp
.skill-row{
width: 50%;
margin: 100px auto 100px auto;
text-align: left; line-height: 2;
}
.muscle {
width: 25%;
float: left;
}
.brain {
width: 25%;
float: left;
}
h3 {
clear: left;
}
<div class="skills">
<h2>My Skills.</h2>
<div class="skill-row">
<img class="muscle"src="images/strong.png" alt="muscle">
<h3>Physical Capabilities</h3>
<p>I am physically fit, tall and lean from years of playing outside.</p>
</div>
<div class="skill-row">
<img class="brain" src="images/brainstorm.png" alt="brain">
<h3>Intelligence</h3>
<p>I am able to perform mathematical calculations with ease, and understand advanced concepts.</p>
</div>
</div>
I am trying to align two divs beside each other using the inline-block technique. My code is fairly simple, but I am not sure why is it not working, I don't know what the issue might be.
Here's my code:
.content .sidebar, .content .section {
display: inline-block;
border: none;
min-height: 200px;
width: 250px
}
.sidebar {
background: blue;
}
.section {
background: red;
}
<div>
<div class="header-area">
<h3 id="genericpartTitle">Our album</h3>
</div>
<div class="content">
<div class="sidebar"> hello! </div>
<div class="section">
<h5 class="item-title">Welcome to my section</h5>
<p style="white-space: pre" class="description"> Hello, anything will go here </p>
</div>
</div>
</div>
Aren't they supposed to be aligned beside each other? what's going wrong here? any help would be great.
You just need to add vertical-align: top; for both sidebar and section classes. checkout the code below.
.content .sidebar, .content .section{
display: inline-block;
border: none;
min-height: 200px;
width: 250px
}
.sidebar{
background: blue;
vertical-align: top;
}
.section{
background: red;
vertical-align: top;
}
<div>
<div class="header-area">
<h3 id="genericpartTitle">Our album</h3>
</div>
<div class="content">
<div class="sidebar">
hello!
</div>
<div class="section">
<h5 class="item-title">Welcome to my section</h5>
<p style="white-space: pre" class="description">
Hello, anything will go here
</p>
</div>
</div>
</div>
When my a text string gets too long, it goes under an image, when instead, I'd like it to just go to a new line and remain to the right of the image. How do I make the text continue to stay to the right of the image instead of going beneath that "race2.jpg" image when it becomes too long? I suppose it could be done with line breaks if all else fails, but is there another way?
JSFiddle: http://jsfiddle.net/fgGyF/
HTML:
<div id="rightcolumn">
<div id="supportus">
<h6>Support Us</h6>
<div style="float: left">
<img src="images/race2.jpg" width="180" height="360" />
</div>
<div style="float:left; text-align: left">
Test text here. And here and here and here and here and here.
</div>
</div>
CSS:
#leftcolumn {
width: 50%;
float: left;
}
#rightcolumn {
width: 50%;
float: left;
}
#twitter {
min-height: 250px;
margin-top: 10px;
margin-right: 15px;
}
#whatsnew {
min-height: 500px;
background: #f0f7cb;
outline:#FFFFFF solid thick;
margin-top: 15px;
margin-right: 15px
}
#supportus {
min-height: 445px;
margin-top: 10px;
margin-bottom: 20px;
background: #f0f7cb;
outline:#FFFFFF solid thick;
}
#dianerehm {
min-height: 200px;
background: #f0f7cb;
outline:#FFFFFF s
Just Assign the div with text a set width.
<div style="float:left; width:140px; text-align: left">
Test text here. And here and here and here and here and here.
</div>
Remove some markup:
<div id="supportus">
<h6>Support Us</h6>
<img src="images/race2.jpg" width="180" height="360" style="float: left" />
Test text here. And here and here and here and here.
</div>
(removed wrapper DIVs and put float on IMG)
UPDATE: The answers have got me close, but they still don't align vertically as the text div is larger, how can I make them both the same height and therefore align?
I would like to have two DIVs next to each other, one containing an image and one containing text, both sitting in a container DIV.
The image should be 15% of the width of the container div, with the text using the remaining 85%
The image and text should be aligned vertically within their respective DIVs, so it looks like they are aligned with each other.
I've tried to work this out but can't seem to do it! Can anyone help?
#picture {
float: left;
width: 15%;
line-height: auto;
}
#text {
width: auto;
padding-left: 16%;
line-height: auto;
vertical-align: middle;
margin-top: auto;
margin-bottom: auto;
}
#text p {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
and
<div id="quotes">
<div id="picture">
<img style="width: 100%; vertical-align: middle" src="tom.jpg" >
</div>
<div id="text">
<p>"Christiaan was one of the stand out candidates throughout, therefore there was no hesitation in offering him a place on this highly sort after scheme..."</p>
</div>
</div>
Here's a fiddle with your code in it: http://jsfiddle.net/hQ6Vw/1/
The only changes I made was to assign matching top/bottom margins to the img and p tags. I think that will give you the effect you're looking for.
If you use float and verticl-align, those two won'nt work together.
Float extract itself from regular flow and go slide on one side or the other on top of next line right after any content within the regular flow.
Vertical-align works:
in betweem inline-boxes (inline-block-level element or displayed so with display:inline-block;)
inside td or it's CSS default display : display:table-cell;
here jsfiddle #TXChetG updated
Using display:inline-block; http://jsfiddle.net/GCyrillus/hQ6Vw/2/
Using display:table/* table-cell*/;
http://jsfiddle.net/GCyrillus/hQ6Vw/3/
This should get you close:
<div>
<div style="background: grey; width: 15%; float:left"></div>
<div style="background: blue; width: 85%; float:left"></div>
</div>
Replace the grey background div with your image and the blue with your text.
Check this out
HTML:
<section>
<div id="one"></div>
<div id="two"></div>
</section>
CSS:
section {
width: 80%;
height: 200px;
background: aqua;
margin: auto;
padding: 10px;
}
div#one {
width: 15%;
height: 200px;
background: red;
float: left;
}
div#two {
margin-left: 15%;
height: 200px;
background: black;
}
Is this what you mean?
html
<div class="container">
<div class="images">
<img src="http://jsfiddle.net/img/logo.png" style="background-color:black">
</div>
<div class="text">
Example
</div>
</div>
<div class="container">
<div class="images">
<img src="http://jsfiddle.net/img/logo.png" style="background-color:black">
</div>
<div class="text">
Example
</div>
</div>
css
.container {
clear: both;
}
.images {
width: 15%;
float: left;
vertical-align: text-top;
}
.text {
width: 85%;
float: right;
vertical-align:text-top;
}
Why not just set the #text p display to display: inline or display:block; or use margins to align them?
<div id="quotes">
<div id="picture">
<img src="tom.jpg" />
</div>
<div id="text">
<p>"Christiaan was one of the stand out candidates throughout, therefore there was no hesitation in offering him a place on this highly sort after scheme..."</p>
</div>
</div>
Display the container div as table and the text and image divs as table-cell to make them the same heights. You can then centre the image vertically through vertical-align:middle.
#quotes {
display:table;
}
#picture {
width: 15%;
display:table-cell;
vertical-align: middle;
}
#text {
display:table-cell;
width:85%;
padding-left: 16%;
}
#picture img {
width: 100%;
}
http://jsfiddle.net/X3WsV/1/
I would like to know what the best way is to format the following layout:
(with eveything aligned and spaced neatly):
Here is the HTML:
<div class"wrapper">
<img alt="Image 1" src="images/image1.png" />
<div class="description">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
I tried the following but the vertical-align property does not seem to be working as I cannot align the top of the h1 with the top of the image:
img, div.description {
float: left;
}
div.description { margin-left: 10px; vertical-align: top; }
h1 { background: blue; }
p { background: red; }
What if instead of how the right hand side part is displayed below,
we wanted the right hand side to also be vertically centered instead
of being top aligned?
Here is the JSFiddle link:
http://jsfiddle.net/johngoche99/ZPKZj/1/
OK, to keep the text from dropping down below when the browser is resized it is necessary to specify the width of the wrapper element to something like 700px. Then it works.
Thanks.
in css you need to do this
img{
float: left;
height: 300px
}
div{
float: left;
}
h1{
padding: 10px;
background-color: #584480;
color: #fff;
font-weight: normal;
font-size: 25px;
margin: 0 0 10px 10px;
}
p{
padding: 10px;
background-color: #E24480;
color: #fff;
font-weight: normal;
font-size: 25px;
margin: 0 0 10px 10px;
}
nothing more ...
Hope this will help you ...
This can be accomplished with simple CSS.
img, div{
float: left;
margin: 10px;
}
http://jsfiddle.net/ZPKZj/2/
IRL, do NOT use this CSS. It is far too generic to be useful in any production environment. You might give your elements IDs or classes to allow the rules to be much more specific.
It looks you markup need a little change to be more, khm right;
HTML:
<div id="all">
<div id="sidebar">
<img class="side_image" alt="Image 1" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
</div>
<div id="main">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
CSS:
#sidebar { float: left; }
#sidebar { margin-right: 40px; }
h1 {
margin-bottom: 30px;
margin-top: 0;
}
link to look how it will be:
http://jsfiddle.net/56Z7C/1/
I think you want something like this:
JSFIDDLE
You want to use css here. You will add an ID to the first div like <div id="wrapper"> this is your main div. Then in the second div you add <div id="headings"> for the headings. then in your css add the beneath code. (note: this isn't the best css code ever. but it works :))
html:
<div id="wrapper">
<img alt="Image 1" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
<div id="headings">
<h1>Heading 1</h1>
<p>Paragraph 1</h1>
</div>
</div>
css:
#wrapper{
width: 960px;
margin: 0 auto;
}
#wrapper img{
float: left;\
margin-right: 40px;
padding-right: 40px;
}
#headings{
position: relative;
float: left;
}
h1{
margin-top: -5px;
}
Hope it helps!
Vertical-align only works on tables. If you want to do that with divs, you could try using display: table:
<div class="table">
<div class="row">
<div class="cell">
<img alt="Image 1" width="100" src="http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/green-iguana_563_600x450.jpg" />
</div>
<div class="cell" id="stuff">
<h1>Heading 1</h1>
<p>Paragraph 1</p>
</div>
</div>
</div>
And the CSS:
.table { display: table; }
.row { display: table-row; }
.cell { display: table-cell; }
#stuff { vertical-align: middle; }
This has the advantage of not being dependent on sizes/margins of elements, but is unsupported in IE7 and below. As all things in life, display: table is a tradeoff.