I have tried coding the HTML layout in the image below, but as a result does not seem to be working correctly. Any help with the error would be appreciated.
HTML:
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra rutrum tem <br> por. Curabitur at rhoncus orci. Donec ante velit, scelerisque vitae tincidunt sit amet.</p>
</header>
<section>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</section>
CSS:
body {
font-family: 'open sans';
text-align: center;
color: #333;
}
section {
display: block;
}
h1, h2 {
font-weight: 300;
}
Desired Layout:
You should split your section into two, by headings, so that you can float them separately:
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra rutrum tem <br> por. Curabitur at rhoncus orci. Donec ante velit, scelerisque vitae tincidunt sit amet.</p>
</header>
<section>
<article>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</article>
<article>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</article>
</section>
And for your CSS:
body {
font-family: 'open sans';
text-align: center;
color: #333;
}
section {
display: block;
overflow: hidden;
}
section > article {
box-sizing: border-box;
float: left;
width: 50%;
}
h1, h2 {
font-weight: 300;
}
I recommend using box-sizing: border-box because it will not break the layout when you add padding to the <article> element.
See fiddle here - http://jsfiddle.net/teddyrised/XPGb7/
Wrap your content in left & right containers as:
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra rutrum tem <br> por. Curabitur at rhoncus orci. Donec ante velit, scelerisque vitae tincidunt sit amet.</p>
</header>
<section>
<div class="left">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
<div class="right">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
</section>
And apply the following style
body {
font-family: 'open sans';
text-align: center;
color: #333;
}
section {
display: block;
}
h1, h2 {
font-weight: 300;
}
.left, .right{
width: 50%;
}
.left{
float: left;
}
.right {
float: right;
}
Working example:
http://jsbin.com/aragem/1/
You will need to wrap your section into two div blocks:
<section>
<div>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur.
<br>Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
<div>
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur.
<br>Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
</section>
So you can apply the following style:
section > div {
display: inline-block;
width: 45%;
}
http://jsfiddle.net/samliew/8XJ7F/3/
this will work :
html :
<header>
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam pharetra rutrum tem <br> por. Curabitur at rhoncus orci. Donec ante velit, scelerisque vitae tincidunt sit amet.</p>
</header>
<section>
<div class="left">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
<div class="right">
<h2>Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur. <br> Curabitur at rhoncus orci. Lorem ipsumm.</p>
</div>
</section>
css :
body {
font-family: 'open sans';
text-align: center;
color: #333;
}
section {
display: block;
}
h1, h2 {
font-weight: 300;
}
.left, .right{
width: 50%;
}
.left{
float: left;
}
.right {
float: right;
}
Related
Right now the text is like this:
Lorem ipsum dolor sit amet consectetur adipiscing
elit vitae orci elementum dictum
I want to be like that:
Lorem ipsum dolor sit amet consectetur adipiscing
elit vitae orci elementum dictum
I want the second text line to start where the first line starts.
the first text line is aligned to right.
try this out. May be helpful
<p>Lorem ipsum dolor sit amet consectetur adipiscing<br>
<span>elit vitae orci elementum dictum</span></p>
<style>
p { float: right; }
span { float: left; }
</style>
Another simple way of doing it is using 2 p tags
In HTML:
<p class="text">Lorem ipsum lorem ipsum</p>
<p class="author">Author</p>
In Css:
.text{
font-size: 15px;
}
.author{
font-size: 12px;
color: grey;
}
I would like to ask you something that has been bothering me for a while. I currently learn HTML and CSS and we got this homework where we have to create a blog that has one article in the middle and two sidebars on the right, the background color of the site should be gray. the problem is that the main article and the two sidebars should have a white background color, so when I change the article's background color to white, it automatically takes control over 75% of the website, even outside the article. here is a screenshot.
What I am trying to make
https://f.v1.n0.cdn.getcloudapp.com/items/0k300n0O0J0c1l1B3K2J/blog-1.png
What I get when I change the background color of the sidebars to white
https://ctrlv.sk/WF4e
.main-image {
height: 260px;
width: 670px;
}
.main {
text-align: center;
padding: 40px;
margin-top: -10px;
}
.main2 {
background-color: white;
}
body {
background-color: rgb(243, 243, 243)
}
.line {
margin-top: 50px;
}
hr {
margin-top: -20px;
}
.back {
background-color: white;
}
.box-post {
background: white;
margin-left: 70px;
}
.sideimage {
float: right;
margin-top: -340px;
width: 350px;
margin-right: 100px;
display: block;
}
.sidetext {
text-align: right;
margin-top: -180px;
margin-right: 160px;
}
<title>Blog</title>
<link rel="stylesheet" href="styles.css">
<header>
<div class="main2">
<h1 class="main">
<strong>Dopetrope</strong>
</h1>
</div>
<hr>
</header>
<section id="main">
<article class="box-post">
<img class="main-image" src="pic01.jpg" alt="obrazocek">
<header>
<h1>Right sidebar</h1>
<h3>Lorem ipsum dolor sit amet feugiat</h3>
<div>
</div></header>
<p>
</p><section class="box">
<img class="sideimage" src="pic09.jpg">
<h1 class="sidetext2">Sed etiam lorem nulla</h1>
<p class="sidetext">
Lorem ipsum dolor sit amet sit veroeros <br>
sed amet blandit consequat veroeros <br>
lorem blandit adipiscing et feugiat <br>
phasellus tempus dolore ipsum lorem <br>
dolore.
</p>
</section>
<p>
Vestibulum scelerisque ultricies libero id hendrerit. Vivamus malesuada quam faucibus ante <br>
dignissim auctor hendrerit libero placerat. Nulla facilisi. Proin aliquam felis non arcu molestie at <br>
accumsan turpis commodo. Proin elementum, nibh non egestas sodales, augue quam aliquet est, <br>
id egestas diam justo adipiscing ante. Pellentesque tempus nulla non urna eleifend ut ultrices nisi <br>
faucibus. <br><br><br>
Praesent a dolor leo. Duis in felis in tortor lobortis volutpat et pretium tellus. Vestibulum ac ante <br>
nisl, a elementum odio. Duis semper risus et lectus commodo fringilla. Maecenas sagittis convallis <br>
justo vel mattis. placerat, nunc diam iaculis massa, et aliquet nibh leo non nisl vitae porta lobortis, <br>
enim neque fringilla nunc, eget faucibus lacus sem quis nunc suspendisse, nec lectus sit amet <br>
augue rutrum vulputate ut ut mi. Aenean elementum, mi sit amet portittor lorem ipsum dolor sit <br>
amet, consecteur adipiscing elit. Lorem ipsum dolor sir amet nullam consequat feugiat dolore <br>
tempus.
</p>
</article>
</section>
Any idea on how to change this? I hope you understand what I am trying to acheive here. Also please don't mind the code too much if it's wrong, I am still pretty new to this stuff :D
I think you may need to change your layout , by using one DIV on the left, and two DIVs on the right, as follows
.main {
text-align: center;
padding: 40px;
margin-top: -10px;
border-bottom:1px solid #DDDDDD;
}
.main2 {
background-color: white;
}
body {
background-color: rgb(243, 243, 243);
margin:0;
}
.container {
width:100%;
padding:20px;
}
.leftbox {
width:68%;
float:left;
background:#FFFFFF;
}
.image1 {
padding:0px;
background-image:url("https://i.stack.imgur.com/nhPHk.jpg");
height:160px;"
}
.image2 {
padding:0px;
background-image:url("https://i.stack.imgur.com/Vqklg.jpg");
height:50px;
}
.leftboxcontent {
padding:20px;
}
.middlespace {
width:3%;
float:left;
}
.rightbox {
width:25%;
float:left;
}
.rightboxcontent1 {
background-color:#FFFFFF;
width:100%;
}
.rightboxcontent1a {
padding:20px;
}
.rightboxcontent2 {
background-color:#FFFFFF;
width:100%;
}
.rightboxcontent2a {
padding:20px;
}
<title>Blog</title>
<body>
<div class="main2">
<h1 class="main">
<strong>Dopetrope</strong>
</h1>
</div>
<div class=container>
<div class=leftbox>
<div class=image1> </div>
<div class=leftboxcontent>
<h1>Right sidebar</h1>
<h3>Lorem ipsum dolor sit amet feugiat</h3>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
<h4>Lorem ipsum dolor sit amet feugiat</h4>
</div>
<div> </div>
</div>
<div class=middlespace> </div>
<div class=rightbox>
<div>
<div class=image2> </div>
<div class=rightboxcontent1>
<div class=rightboxcontent1a>
TESTTEST<BR>TESTTEST<BR>
TESTTEST<BR>TESTTEST<BR>
TESTTEST<BR>TESTTEST<BR>
TESTTEST<BR>TESTTEST<BR>
TESTTEST<BR>TESTTEST<BR>
TESTTEST<BR>TESTTEST<BR>
</div>
</div>
</div>
<br><br>
<div>
<div class=rightboxcontent2>
<div class=rightboxcontent2a>
TESTTEST2<BR>TESTTEST2<BR>
TESTTEST2<BR>TESTTEST2<BR>
</div>
</div>
</div>
</div>
</div>
</body>
It is good practise to start with a strong structure before filling it with content. If you have a good structure, then you have less debugging. Something like the template below.
Tip. The display:flex is more flexible then the float:left
* {
margin: 0;
box-sizing: border-box;
}
#header {
width: 100%;
}
#main {
float: left;
width: 70%;
}
#aside {
float: left;
width: 30%;
}
#footer {
clear: both;
width: 100%;
}
/* for test purpose only */
.test {
height: 80px;
border: 1px solid orange;
}
<header id="header" class="test">
</header>
<section id="main" class="test">
<article>
</article>
</section>
<aside id="aside" class="test">
</aside>
<footer id="footer" class="test">
</footer>
I have to display span tag content in one line inside li tag. Would you help me in this?
I am getting output like this.
I need output like this.
ul {
list-style: none;
}
ul li {
display: inline;
}
ul li h2 {
display: inline-block;
}
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
You have to provide display: inline-block to your li, h2 and span.
Give your span appropriate width so that it gets accommodated within the space between both the li.
To view in full screen, check fiddle: https://jsfiddle.net/nashcheez/s4tqwcmr/
Refer code:
ul {
list-style: none;
}
ul li {
display: inline-block;
width: 49%;
}
ul li h2 {
display: inline-block;
margin: 0;
height: 100%;
vertical-align: top;
}
span {
display: inline-block;
width: 110px;
}
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
Add inline-block to your li this will let them have a specific width and not acting like an inline element...
ul
{
list-style: none;
}
ul li{
display: inline-block;
width: 40%;
margin: 10px;
}
ul li h2{
display: inline-block;
width:40%;
vertical-align: top;
}
ul li span{
display:inline-block;
width:39%;
vertical-align: top;
}
ul li button{
display: inline-block;
width: 19%;
min-width: 60px;
vertical-align: top;
}
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
<button>button</button>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
<button>button</button>
</li>
</ul>
ul
{
list-style: none;
}
ul li{
width: 40%;
display: -webkit-inline-box;
}
ul li h2{
display: inline-block;
}
<ul>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
<li>
<h2>Lorem ipsum dolor sit</h2>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tellus nisl, molestie vitae nibh nec, dictum dignissim dui.Lorem </span>
</li>
</ul>
I have a list of n items.
I'm trying to align the a element having child img, next to sibling p element.
I've tried setting both to display:inline-block, but I don't see any change. My code looks like this:
<li>
<h3>Header 3</h3>
<img src="example.img" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate interdum lacus in hendrerit. Donec libero metus, maximus sit amet.</p>
</li>
My goal is to create a sort of panel where the a element is to the left with the text next to it, and the h3 centered in that same panel.
<li>
<h3>Header 3</h3>
<a href="#">
<img src="example.img" alt="">
</a>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate interdum lacus in hendrerit. Donec libero metus, maximus sit amet.</p>
</li>
I didn't understand what your question goal. But, tell me if my answer was wrong :)
li{
list-style: none;
}
h3{
text-align: center;
}
img{
float: left;
}
p{
text-align: right;
}
<li>
<h3>Header 3</h3>
<img src="example.img" alt="">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate interdum lacus in hendrerit. Donec libero metus, maximus sit amet.</p>
</li>
use display:inline-block in a and p and set some width, use text-align:center in h3
body,
h3,
p {
margin: 0;
font-size:16px /* restore font-size inline-block fix*/
}
h3 {text-align: center}
ul {
margin: 0;
padding: 0;
font-size: 0
/*inline-block fix gap*/
}
li {
background: red;
}
a,
li,
p {
display: inline-block;
vertical-align: top;
width: 50%
}
img {
width: 100%;
display: block
}
<ul>
<li>
<h3>Header 3</h3>
<a href="#">
<img src="//lorempixel.com/100/100" alt="">
</a>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate interdum lacus in hendrerit. Donec libero metus, maximus sit amet.</p>
</li>
<li>
<h3>Header 3</h3>
<a href="#">
<img src="//lorempixel.com/100/100" alt="">
</a>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vulputate interdum lacus in hendrerit. Donec libero metus, maximus sit amet.</p>
</li>
</ul>
I want to position a text and image like this:
This is what I have now
http://jsfiddle.net/vzovk7xd/
<section class="feature">
<div class="container">
<article class="feature-item design">
<h2>Web Design</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rhoncus, lacus ac commodo volutpat, felis odio pulvinar enim, non dapibus mauris nulla sed ipsum.</p>
READ MORE
</article>
<article class="feature-item media">
<h2>Social Media</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rhoncus, lacus ac commodo volutpat, felis odio pulvinar enim, non dapibus mauris nulla sed ipsum.</p>
READ MORE
</article>
<article class="feature-item apps">
<h2>Mobile Apps</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rhoncus, lacus ac commodo volutpat, felis odio pulvinar enim, non dapibus mauris nulla sed ipsum.</p>
READ MORE
</article>
</div>
</section>
CSS
.feature {
margin-top: 100px;
text-align: center;
line-height: 25px;
}
.feature-item {
width: 33.3%;
float: left;
}
.design {
background: url(https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png) no-repeat center center;
}
Don't set background image to your .design div, put another div between the heading and paragraph, give it width and height, and set background image to that div.
<article class="feature-item design">
<h2>Web Design</h2>
<div class="image"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rhoncus, lacus ac commodo volutpat, felis odio pulvinar enim, non dapibus mauris nulla sed ipsum.</p>
READ MORE
</article>
css
.image { width: 100%; height: 140px; background: url(https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png) no-repeat center center; }
https://jsfiddle.net/vzovk7xd/1/
add this css:
.design, .media, .apps {
background: url(https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png) no-repeat top center;
background-position:75px 90px;
}
.feature-item p {margin-top:200px}
http://jsfiddle.net/vzovk7xd/6/
Don't put it as background (if you want to do that, you need to set width and height for .design box).. instead, add another div element between h2 and p elmenets:
<h2>Web Design</h2>
<div class="design"><img src="https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png"/></div>
<p>Lorem ipsum dolor sit amet</p>
Working fiddle: http://jsfiddle.net/vzovk7xd/7/
You try to put an inline (in the elments flow order) element with the background style (out of the elements flow)... Better use an inline element to present it like an inline element.
Solution A: (modify CSS, remove background)
.feature-item h2:after {
content: url('https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png');
margin: 24px 0 0 0;
display: inline-block;
}
http://jsfiddle.net/vzovk7xd/9/
Solution B: (modify HTML)
<article class="feature-item design">
<h2>Web Design</h2>
<figure></figure>
figure {
background: url(https://31.media.tumblr.com/avatar_b0a905e3eb32_128.png)
no-repeat center center;
width: 100px;
height: 100px;
}
http://jsfiddle.net/vzovk7xd/3/