Responsive div's on one line - html

I've been struggling for this a couple of days now. I googled a lot but can't find the right answer. I'm building an website and want to make it full responsive. On my homepage i have 3 blocks of tekst (300 width each). On screens bigger then 1000 pixels they are centered. Until this point i didn't had any issues.
But when the screens become smaller then 1000 pixels i want the blocks to be underneath each other and center to the screen it's been seen from. For an example of my idea visit http://www.t-mobile.nl.If you make your browser smaller the 3 promotion blocks will automatically change to fit your screen.
I also want the blocks to be in formation all the time. Or 3 blocks vertical or 3 blocks horizontal. Not 2 blocks on 1 row and the other on the row below them.
I tried to set the div container to width: 60% but then i get an big space at the left side on a smaller screen. The blocks also don't line up as i would hope.
I made an JSFiddle of the part i already have. You can visit it here: https://jsfiddle.net/gertjan2805/vj0grfpy/
Does anyone know how to fix this? It would be a great help :)
This is my HTML:
<div class="container">
<div class="containersmall">
<div class="top">DIV Test</div>
<div class="text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.</div>
</div>
<div class="containersmall">
<div class="top">DIV Test</div>
<div class="text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.</div>
</div>
<div class="containersmall">
<div class="top">DIV Test</div>
<div class="text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.</div>
</div></div>
body {
background-color: #EDEDED;
font-family: 'Verdana';
margin-left: 0px;
margin-top: 20px;
margin-right: 0px;
}
.container {
width: 1005px; /*1005px or 59%*/
margin: auto;
position: relative;
text-align:center;
}
.containersmall {
width: 310px;
float: left;
margin-left: 25px;
}
.top {
width: 310px;
background-color: #67B3BD;
text-align: center;
font-size: 22px;
color: #FFFFFF;
height: 50px;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px#888;
box-shadow: 0 0 5px #888;
margin: auto;
padding-top: 20px;
float: left;
}
.text {
width: 300px;
text-align: justify;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px #888;
box-shadow: 0 0 5px #888;
margin: auto;
padding: 5px;
background-color: #FFFFFF;
float: left;
}

There are two ways: media queries or flexbox.
For media queries, something like this may suffice (not tested):
#media (max-width : 1000px){
.containersmall {
clear:both;
width:100%;
}
}
For flexbox, I'm going to refer you to a tutorial: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Hope this helps,
Chris

What you need are media queries - for anything below 1000px (inclusive), you will want to set width container boxes at 100%, something like:
#media only screen and (max-width: 1000px) {
.container {
width: 100%;
}
.containersmall {
width: 100%;
}
.top {
width: 100%;
}
etc...
}
So you should have no fixed values for any element within box.

Related

How to display four li tag in one row with equal height?

I have an item list which is coming dynamically from the database so I don't have any idea about the content. I have to display the four li in a single row with equal height. I tried below code but it's not working.
I tried display:flex to the ul but all the li tags are displaying in one line. I also try display: table and display: table-cell; but the same issue all are displaying in one line.
body {
margin: 0;
padding: 0;
}
.List {
max-width: 1140px;
margin: auto;
}
.List ul {
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
.List ul li {
width: 24%;
padding: 20px;
box-shadow: 1px 1px 12px 0px #EBE8E8;
border-radius: 03px;
background-color: #fff;
margin: auto 07px 14px auto;
display: inline-block;
}
<div class="List">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
</ul>
</div>
My expected output is
1 2 3 4
5 6
try this:
body {
margin: 0;
padding: 0;
}
.List {
max-width: 1140px;
margin: auto;
}
.List ul {
list-style: none;
margin: 0;
padding: 0;
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.List ul li {
padding: 20px;
box-shadow: 1px 1px 12px 0px #EBE8E8;
border-radius: 03px;
background-color: #fff;
margin: 0 10px;
flex: 1 0 19%;
max-width: 19%;
}
codepen
Your code is almost right but needs some enhancement...You have to remove add display flex property on ul and flex warp property also...flex wrap automatically break the element according to view port..And there is no need to add margin in li..
CSS:
.List ul {
list-style: none;
margin: 0;
padding: 0;
width: 100%;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
}
.List ul li {
width: 20%;
padding: 20px;
box-shadow: 1px 1px 12px 0px #EBE8E8;
border-radius: 03px;
background-color: #fff;
margin-bottom: 20px;
}
I've put together a sample for you, let's check it out:
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.List {
max-width: 1140px;
margin: auto;
}
.List ul {
list-style: none;
margin: 0;
padding: 0;
width: 100%;
display: flex;
flex-flow: row wrap;
}
.List ul li {
flex: 0 0 auto;
width: 25%;
padding: 20px;
box-shadow: 1px 1px 12px 0px #EBE8E8;
border-radius: 3px;
background-color: #fff;
}
<div class="List">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
</ul>
</div>
Let's break it down a bit so you can understand it more clearly.
First, we reset the box-sizing property with this:
* {
box-sizing: border-box;
}
This ensures that the column width won't be affected by border-width and padding properties, which you are using with padding: 20px;
By default, using display: flex will make its direct children equal height, by removing margin CSS margin: auto 0.5% 1% auto; will resolve the issue. The issue with your margin CSS is auto value will align the flex item to vertically center, no wonder you don't get equal height.
Let me know if you need some more help,
Since you know that you want only 4 columns in a row, set the width of each li element to 25%. But considering that you're applying padding and margins as well, reduce the width of the lis by the amount of padding and margin you're giving.
Also, try to be consistent in using units of values, such as %, px, em, etc. Mixing and matching these in the same element can give unexpected results.
So here, setting the padding to be 1% on each side, and margin to be 0.5% and 1% on the right and left respectively will take up a total of 3.5% of total width for each li. So just set the width to something less than 21.5% and you'll get 4 elements per row.
body {
margin: 0;
padding: 0;
}
.List {
/*max-width: 1140px;*/
margin: auto;
}
.List ul {
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
.List ul li {
width: 21.5%;
padding: 1%;;
box-shadow: 1px 1px 12px 0px #EBE8E8;
border-radius: 03px;
background-color: #fff;
margin: auto 0.5% 1% auto;
display: inline-block;
}
<div class="List">
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean </li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo sociis natoque
</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque
</li>
</ul>
</div>
You can achieve this by using display: flex; for this you don't need to give minimum height as well. And also layout is easy to manage and make it responsive.
.cstm-row {
display: flex;
flex-wrap: wrap;
list-style: none;
padding-left: 0;
}
.cstm-column {
flex: 1;
}
.orange-column {
background-color: #ffc04d;
}
.blue-column {
background-color: #4d4dff;
}
.green-column {
background-color: #00ffc0;
}
.cstm-row .cstm-column:first-child {
margin-right: 10px;
margin-bottom: 10px;
}
.cstm-row .cstm-column {
margin-right: 10px;
margin-bottom: 10px;
}
.cstm-row .cstm-column:last-child {
margin-right: 0;
margin-bottom: 10px;
}
.cstm-row li {
flex: 1;
padding: 10px;
border-radius: 3px;
}
.cstm-row li:first-child {
margin-right: 10px;
margin-bottom: 10px;
}
.cstm-row li {
margin-right: 10px;
margin-bottom: 10px;
}
.cstm-row li:last-child {
margin-right: 0;
margin-bottom: 10px;
}
<ul class="cstm-row">
<li class="orange-column">
<p>The passage experienced a surge in popularity during the 1960s when Letraset used it on their dry-transfer sheets, and again during the 90s as desktop publishers bundled the text with their software. Today it's seen all around the web; on templates, websites, and stock designs. Use our generator to get your own, or read on for the authoritative history of lorem ipsum.</p>
</li>
<li class="blue-column">
<p>Until recently, the prevailing view assumed lorem ipsum was born as a nonsense text.</p>
</li>
<li class="green-column">
<p>Until recently, the prevailing view assumed lorem ipsum was born as a nonsense text.</p>
</li>
<li class="blue-column">
<p>Until recently, the prevailing view assumed lorem ipsum was born as a nonsense text.</p>
</li>
</ul>

How to line through all links of a certain div id and bold mark specific paragraph without affecting others [duplicate]

This question already has an answer here:
How to line-through all links inside a border and bold mark certain text of a paragraph
(1 answer)
Closed 3 years ago.
This is the end-product i'm supposed to make and i'm at this-stage.
How do i line-through in css all porttitor>/a> that is in
without affecting .
And how do i bold mark the last paragraph of both borders as shown in the end-product without bold marking everything?
Also if you want you can tell me if i shouldve written everything in a different way.
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="utf-8" />
<title>Uppgift 4E</title>
<style>
html {
background-color: lightslategrey;
}
body {
margin: auto;
width: 500px;
padding-bottom: 0.1px;
/*knep för div margin */
background-color: #f0ffff;
text-align: center;
font-family: sans-serif;
}
h1 {
Color: purple;
}
#billy {
color: darkred;
border-style: solid;
border-color: purple;
border-width: 1.5px;
border-radius: 5px;
text-align: left;
margin: 10px;
}
#bob {
color: darkgreen;
border-style: solid;
border-color: purple;
border-width: 1.5px;
/* border tjockhet */
border-radius: 5px;
/* rundiga kanter på border */
text-align: left;
margin: 10px;
}
p {
margin-left: 5px;
margin-right: 5px;
}
.two {
font-size: large;
}
.three {
font-size: small;
}
#bob>.two>a {
text-decoration: overline underline;
}
</style>
</head>
<body>
<h1>Uppgift 4E</h1>
<div id="billy">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p class="two">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p class="three">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
</div>
<div id="bob">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p class="two">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p class="three">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Suspendisse imperdiet velit sit amet neque tempor et imperdiet augue porttitor.
</p>
</div>
</body>
</html>
Use the <s></s> (strike-through) tag or <del> . The <strike> tag is obsolete is HTML5.
example:
.two a {
text-decoration: line-through;
font-weight: bold;
}
<p>Rachel</p>
<!--Rachel in paragraph tags-->
<p><s>Rachel</s></p>
<!--Rachel in paragraph tags with inner 's' tags-->
<p class="two">I my name is Rachel</p>
<!--line-through css-->
You can also use css
.yourclass a{text-decoration: line-through;}
Regarding bolding text, use font-weight:bold;
Hope this helps
If you can add a class to an HTML element, then you could make a class specifically for bold or line-through, then apply it to what paragraphs that you need to.
Use the text-decoration: line-through; style. It's not obvious what your criterion is for what to affect with this, so I can't suggest a selector.
To mark the last paragraph of each div:
div>p:nth-last-of-type(1) { font-weight: bold; font-size: 110%; }
And you might find fitting the parts together a little easier if you always use:
* { box-sizing: border-box; }
so that container sizes will actually be what a reasonable person would expect them to be.
try this
#bob p:last-child {
font-weight:bold;
}
#bob p:not(.two) a {
text-decoration:line-through;
}

CSS: Right-aligned portion of text with flexible horizontal space

I have an interesting layout issue in CSS. My scenario: Imagine a standard paragraph of text with justified alignment. The last word, however, is the authors name, which needs to be aligned to the right border. Depending on the length of text and the width of the paragraph, this could require a longer distance between the last word of the text and the author's name. It could also happen that the paragraph fills the last line completely, and then the author's name should appear one line below, and still aligned to the right.
I have an image here that illustrates this behavior, see the footnotes:
See that in the first footnote the author ("Der Herausgeber") is aligned to the right, but remains in the last line of the text, while in the second footnote the author ("D. H.") jumps one line down, due to text length.
I have tried to emulate this with the following HTML/CSS:
p {
width: 350px;
text-align: justify;
}
span.author {
display:inline-block;
text-align:right;
max-width:100%;
font-style: italic;
white-space: nowrap;
}
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. <span class="author">The Author</span></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor massa. <span class="author">The Author</span></p>
So far, the author comes as a separate element, and it jumps to the next line as a separate unit (no wraps allowed). But I have problems aligning it to the right border. I have tried min-width and max-width, which did not work. I have also tried to approach this with flexbox, but until now I did not come even close to a solution. Maybe the HTML code needs to be modified as well. Is there any hint you could give me?
You can try something like this using float:right
p {
width: 350px;
text-align: justify;
}
span.author {
display:inline-block;
text-align:right;
font-style: italic;
white-space: nowrap;
float: right;
}
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. <span class="author">The Author</span></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor massa. <span class="author">The Author</span></p>
just set float: right; to author span tag
p {
width: 350px;
text-align: justify;
}
span.author {
display:inline-block;
text-align:right;
max-width:100%;
font-style: italic;
white-space: nowrap;
float: right;
}
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. <span class="author">The Author</span></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor massa. <span class="author">The Author</span></p>
You want something like this? I separated the .author from the p
p {
clear: both;
width: 350px;
text-align: justify;
margin-bottom: 0;
}
.author {
display: inline-block;
float: right;
max-width: 100%;
font-style: italic;
white-space: nowrap;
}
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. </p><span class="author">The Author</span>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor massa. </p><span class="author">The Author</span>

Why does one div height change in px but not in percent?

Just practicing around with div positioning. In this code, the green colored child div (the last fourth one from left), whenever I try to increase/decrease its height in %, there is no effect. However, when I try to increase/decrease its height in pixels the div expands/contracts accordingly. Why is that? I am talking about .child4 { }
html,body {
margin: 0px;
height: 100%;
width: 100%;
left: 0px;
top: 0px;
}
.parent {
background-color: rgba(0,0,0,1);
height: 100%;
width: 100%;
position: absolute;
}
.child1 {
background-color: rgba(153,153,153,1);
height: 200%;
width: 25%;
margin-right: 2%;
margin-left: 0%;
display: block;
/* [disabled]margin-bottom: 2%; */
float: left;
position: relative;
}
.child2 {
background-color: rgba(255,0,0,1);
height: auto;
width: 25%;
margin-left: 0%;
display: block;
float: left;
position: relative;
top: 0%;
margin-top: 0%;
}
.child3 {
height: auto;
width: 25%;
background-color: rgba(0,0,255,1);
float: left;
}
.child4 {
height: 50%;
width: 20%;
background-color: rgba(0,255,0,1);
float: left;
position: relative;
top: 0%;
}
----------
<div class="parent">
<div class="child1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis
dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a
libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis eeeeeeeeeeeeeeeeeeeeeeeee
</div>
<div class="child2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis
dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a
libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis
</div>
<div class="child3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis
dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a
libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis
</div>
<div class="child4">
kdkldkldkdkld
</div>
</div>
You set the height to 50% but 50% of what? What value is that? It's always the value of the parent. In this case .parent.
So what is the value of .parent? You have it set to auto which leads to what value in its height for .parent? Zero.
What is 50% of zero?
Get it? Good.
So set .parent to a height of, say, 300px. Then see what you get.
It's not working, because the parent doesn't have any height.
You can't take 25% of auto, but you can take 25% of 700px for example. The parent height should be in px to be able to make the child height in %.
Edit :
Now that you added height 100% to parent, it's looking weird, because it take 100% of the snippet container.
Have you tried setting the width of the .parent to a fixed size e.g. 500px? That way you can make the height a percentage based off of the width. There does need to be some fixed attribute to base the percentage off of. This works the same for width % so if you set a fixed height you can use % on the width
I don't understand very well what you want, but I saw that you need add some fix on your CSS code to show the .parent background because you are using float:left on .child. Maybe this solve your problem. This is the fix code:
.parent:after{
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both !important;
height: 0;
}

What to do to align text as shown in the image using HTML and CSS?

I'm trying to align a block of text so it looks like in the image. However, without acceptable result. The text is located in the floating div which is repeating. Same divisions are floating next to each other.
My HTML code:
<div id="bottomPanel">
<div class="bottomItem">
<img src="image.png" alt="mouse" class="imgBottom">
Lorem ipsum dolor sit amet
<p class="item_bottomAbout">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur gravida, massa ut suscipit suscipit, massa elit sollicitudin eros, nec lacinia neque odio a est. Phasellus tincidunt nulla eget lorem sodales</p>
</div>
</div>
My CSS code:
#bottomPanel {
float: left;
width: 100%;
text-align: center;
}
.bottomItem {
float: left;
width: 100%;
margin-top: 10px;
background-color: #e6e6e6;
}
.imgBottom {
float: left;
padding-top: 25px;
padding-left: 14px;
}
.item_bottomDesc {
float: left;
font-family: Arial;
font-weight: bold;
font-size: 12px;
text-decoration: none;
color: #133855;
padding-top: 42px;
padding-left: 18px;
display: block;
}
.item_bottomAbout {
float: left;
font-family: Arial;
font-size: 12px;
width: 376px;
height: auto;
text-align: justify;
display: block;
padding-top: 50px;
color: #7b7a79;
}
This is how the elements should look like:
The text I can't align properly is the long one.
Division has 100% width which is approx. 774px. bottomPanel is a div where all floating .bottomItem are located.
Any ideas?
So not much wrong here overall. Just that you have a few extra things you don't need.
Namely, bottomDesc and bottomAbout do not need to be floated, and the padding-top for those two elements need adjusting too.
I have also added an explicit width/height for the image, feel free to adjust as needed but it's a good idea to define it. I also replaced its padding with appropriate margins.
Finally, I removed the #bottomPanel styles altogether - again float is not needed here, and width:100% is default anyway. Also, the text-align:center was unnecessary.
Here's the revised code for you to look at:
.bottomItem {
float: left;
width: 100%;
margin-top: 10px;
background-color: #e6e6e6;
}
.imgBottom {
float: left;
margin: 14px;
width: 100px;
height: 100px;
}
.item_bottomDesc {
font-family: Arial;
font-weight: bold;
font-size: 12px;
text-decoration: none;
color: #133855;
padding-top: 14px;
padding-left: 18px;
display: block;
}
.item_bottomAbout {
font-family: Arial;
font-size: 12px;
width: 376px;
height: auto;
text-align: justify;
display: block;
}
<div id="bottomPanel">
<div class="bottomItem">
<img src="http://placehold.it/100x100" alt="mouse" class="imgBottom">
Lorem ipsum dolor sit amet
<p class="item_bottomAbout">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur gravida, massa ut suscipit suscipit, massa elit sollicitudin eros, nec lacinia neque odio a est. Phasellus tincidunt nulla eget lorem sodales</p>
</div>
</div>
Instead of float i suggest you use flexbox for this, and you dont have to use padding to get vertical align.
.bottomItem {
display: flex;
flex-direction: row;
align-items: center;
margin: 10px;
}
.right {
max-width: 60%;
margin: 0 10px;
}
<div id="bottomPanel">
<div class="bottomItem">
<img src="http://placehold.it/150x150">
<div class="right">
Lorem ipsum dolor sit amet
<p class="item_bottomAbout">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur gravida, massa ut suscipit suscipit, massa elit sollicitudin eros, nec lacinia neque odio a est. Phasellus tincidunt nulla eget lorem sodales</p>
</div>
</div>
<div class="bottomItem">
<img src="http://placehold.it/150x150">
<div class="right">
Lorem ipsum dolor sit amet
<p class="item_bottomAbout">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur gravida, massa ut suscipit suscipit, massa elit sollicitudin eros, nec lacinia neque odio a est. Phasellus tincidunt nulla eget lorem sodales</p>
</div>
</div>
<div class="bottomItem">
<img src="http://placehold.it/150x150">
<div class="right">
Lorem ipsum dolor sit amet
<p class="item_bottomAbout">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur gravida, massa ut suscipit suscipit, massa elit sollicitudin eros, nec lacinia neque odio a est. Phasellus tincidunt nulla eget lorem sodales</p>
</div>
</div>
</div