Unaligned images with text underneath? CSS / HTML - html

unaligned images and text
I have attempted to input suggestions from previous questions but it just seems I have been able to successfully find the correct way to align these images with their text underneath.
<section id="boxes">
<div class="container">
<div class="box">
<img src="./images/dayporter2.jpeg">
<h3>DAYPORT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box">
<h3>FLOOR CARE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="box">
<img src="./images/janitor2.jpeg">
</div>
</section>
/* boxes */
#boxes{
margin-top: 20px;
}
#boxes .box{
float: left;
text-align: center;
width: 30%;
padding: 10px;
}
#boxes .box img{
width: 90px;
}`

You seem to have an unnecessary div tag.
remove the div tag after your 'floorcare1.jpeg' img, here:
<img src="./images/floorcare1.jpeg">
<div class="box"> //remove this

<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box"> <!-- The probleme is here -->
<h3>FLOOR CARE</h3>
Because the .box element which is direct below the image is float left, it will force the image to be float left, because their sibling .box take 30% of the parent and there are remaining 70% width of their .box parent element. You must remove the .box element and every thing will work like you expecting.
Another problem you must close all you open markup
<section>
<div class="container">
<div class="box">
<!-- First box -->
</div>
<div class="box">
<!-- Second box -->
</div>
<div class="box">
<!-- Third box -->
</div>
</div>
</section>

Related

Colspan of css display table did not work [duplicate]

This question already has answers here:
HTML colspan in CSS
(16 answers)
Closed 3 years ago.
I have already tired to fix the colspan in the display table in CSS.
.table {
display: table;
table-layout: fixed;
width: 100%;
border-collapse: collapse;
}
.table-row {
display: table-row;
border-collapse: collapse;
}
.table-cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
}
.table-row.colspan {
display: block;
}
.table-row.colspan .table-cell {
display: block;
width: 200%;
box-sizing: border-box;
}
<div class="table">
<div class="table-row">
<div class="table-cell">
top left cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
</div>
<div class="table-row">
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="table-row">
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
</div>
</div>
How can I take the colspan behavior of the second row in the table? Thanks in advance.
https://codepen.io/mdshohelrana/pen/WNNxBqP
What do you mean with "colspan behaviour"?
It's not possible to reproduce the HTML colspan attribute in tables in CSS und display: table-*, because it's a structural thing not a style thing. Plus colspan requires a number parameter to determine the number of columns to span, which you don't have.
What are you trying to do anyway? If you want to use a table (for tabular data) then use HTML table/tr/td elements and the colspan attribute.
If you want to have a table like (page) layout, then you should be using css grid with which you can do colspan-like designs.
In any case you shouldn't be alot of divs and using class names such as table-row/celletc. Class names should semantically describe the content not the look of elements.
The issue was discussed here
There is no simple CSS property that we can provide for colspan (As far as I know).
I think using table tag is more efficient and understandable.
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
https://www.w3schools.com/tags/att_td_colspan.asp You can refer here.
Well you can solve it by two approaches:
Use display:table-row-group and then for cell specify display:table-caption. but I am struggling with setting border on right side in this case.
Fiddle for same is below:
http://jsfiddle.net/hsbokxv4/
You can manipulate using javascript. Fiddle is below (Though I am not fan of this approach):
http://jsfiddle.net/emilianolch/5nvxv5ko/
I could simulate a hack with setting float and width. Maybe it can be used in your design. But I'm not sure if it'll work the same on all platforms. Adding a width to the whole table and setting the colspan width the same with the table would be a bit more secure for this. Updated the answer with the width set.
The important part for width's to match is the box-sizing: border-box setting. As it would differ the gaps between two cells and one cell in a row, this should be set.
.table {
display: table;
table-layout: fixed;
width: 600px;
border-collapse: collapse;
box-sizing: border-box;
}
.table-row {
display: table-row;
border-collapse: collapse;
box-sizing: border-box;
}
.table-row.colspanned
{
float: left;
margin: -1px 0;
width: 600px;
}
.table-cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
box-sizing: border-box;
}
.table-cell.colspan {
margin-top: -1px;
margin-bottom: -1px;
width: 200px !important;
}
<div class="table">
<div class="table-row">
<div class="table-cell">
top left cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
<div class="table-cell">
top right cell
</div>
</div>
<div class="table-row colspanned">
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="table-cell colspan">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</div>
<div class="table-row">
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
<div class="table-cell">
bottom left cell
</div>
<div class="table-cell">
bottom right cell
</div>
</div>
</div>

Why doesn't my css grid columns work on my navigation?

I'm brushing up on Responsive Grid CSS on YouTube. Following along with the instructors lesson. I'm having trouble formatting my nave grid. I've included both the html and css code along with pictures of his nav results vs mine. Any help would be appreciated.
I'm trying to get the navigation bar in a 4 column grid. I'm trying to see what I'm missing here.
Instructor Results:
My Results:
/* CSS Variables */
:root {
--primary: #ddd;
--dark: #333;
--light: #fff;
--shadow: 0 1px 5px rgba(104, 104, 104, 0.8);
}
html {
box-sizing: border-box;
font-family: Arial, Helvetica, san-serif;
color: var(--dark);
}
body {
background: #ccc;
margin: 30px 50px;
line-height: 1.4;
}
.btn {
background: var(--dark);
color: var(--light);
padding: 0.6rem 1.3rem;
text-decoration: none;
border: 0;
}
img {
max-width: 100%;
}
.wrapper {
display: grid;
grid-gap: 20px;
}
/* Navigation */
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<div class="wrapper">
<!-- Navigation -->
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
<!-- Top Container -->
<section class="top-container">
<header class="showcase">
<h1>Damn That Looks Delicious</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquam sem et tortor consequat id porta.
</p>
Read More
</header>
<div class="top-box top-box-a">
<h4>Membership</h4>
<p class="price">$199/mo</p>
Buy Now
</div>
<div class="top-box top-box-b">
<h4>Pro Membership</h4>
<p class="price">$299/mo</p>
Buy Now
</div>
</section>
<!-- Boxes Section -->
<section class="boxes">
<div class="box">
<i class="fas fa-pizza-slice fa-4x"></i>
<h3>Restaurants</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-utensils fa-4x"></i>
<h3>Chefs</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-hamburger fa-4x"></i>
<h3>Catering</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-ice-cream fa-4x"></i>
<h3>Sweets</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
</section>
<section>
<img src="images/dtld.jpg" alt="">
<div>
<h2> Your Business On DTLD</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Learn More
</div>
</section>
<!-- Portfolio Section -->
<section class="portfolio">
<img src="https:/source.unsplash.com/random/200x200" alt="">
<img src="https:/source.unsplash.com/random/201x200" alt="">
<img src="https:/source.unsplash.com/random/202x200" alt="">
<img src="https:/source.unsplash.com/random/203x200" alt="">
<img src="https:/source.unsplash.com/random/204x200" alt="">
<img src="https:/source.unsplash.com/random/205x200" alt="">
<img src="https:/source.unsplash.com/random/206x200" alt="">
<img src="https:/source.unsplash.com/random/207x200" alt="">
<img src="https:/source.unsplash.com/random/208x200" alt="">
</section>
<!-- Footer -->
<footer>
<p> Damn That Looks Delicious © 2005</p>
</footer>
</div>
<!-- Wrapper Ends -->
Once you add the closing tag to your anchor elements the layout works as you expect.
This is what you have now:
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
Because the anchor elements are left open (creating invalid HTML code), the browser generates four additional grid items. Now the grid container has eight children: 4 li and 4 a.
Since your code allows for only four items per row, a second row is created to accommodate the other four items. In fact, you always had a four-column grid.
Once you close the anchor tags (creating valid HTML code), only four grid items are rendered.
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
Also, you may want to see my answer here for a brief analysis and suggestion regarding unordered lists inside nav elements.
There is missing of closing anchor </a> tag in your code so once you add closing anchor tag in it. Your code will run perfectly.
screenshot of missing anchor tag

How to do word-break in a non-rectangle div?

My Problem
I'm working on website which has comments that look like Facebook's comments. The text and user's name in the comments can be edited dynamically.
I can't figure out how to break a long text correctly after the user's name.
What I've Tried
Using 'word-break: break-all' on my wrapper div.
Examples
What i'm trying to achieve:
What i get:
My Code (Simplified)
html:
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder"></div>
<div class="text"></div>
</div>
</div>
relevant css:
.text_wrapper{
word-break: break-all;
}
.space_holder{
width: /*Equals to name's width + 10px. Changes dynamically with
javascript when the name is edited. */
}
Help much appreciated!
EDITED: SOLUTION
This worked for me:
html:
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder"></div>
<div class="text"></div>
</div>
</div>
relevant css:
.text_wrapper{
word-break: break-all;
}
.space_holder{
width: /*Equals to name's width + 10px. Changes dynamically with
javascript when the name is edited. */
float: left;
}
.text{
display: inline;
}
If you add a float: left; to .space_holder you can wrap the floated name.
.text_wrapper {
word-break: break-all;
}
.space_holder {
width: 75px;
float: left;
}
<div class="comment_wrapper">
<div class="name"></div>
<div class="text_wrapper">
<div class="space_holder">John Doe</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</div>
</div>
</div>

I have a huge space between two lines of code how do i remove?

Between:
<h2>Menu</h2>
and
<h5>Hover to see more!</h5>
I have this huge gap, is there a way to remove it?
For more references this is my code before heading 2:
<div class="container">
<img src="Lato Font Test.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text"><p>About Us // Origin</p><p>Sample Text</p><p>Sample Text</p><p>Sample Text</p></div>
</div>
</div>
<br></br>
And after heading 5:
<ul id="accordion">
<li>
<h2>MENU // SOUPS</h2>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
</div>
</li>
Picture Reference: http://i.imgur.com/Imc3DPb.png
Thanks in advance!
One of your elements has a default padding or margin. You can inspect your elements with your browsers dev tools to figure out which if not both is causing the issue. Adjust your paddings and margins using padding: x; and margin: x; x being the amount of pixels [ex. 5px] you want.

CSS - floating issue for a responsive design

Problem: http://i.snag.gy/TYvi4.jpg
Fiddle: http://jsfiddle.net/CadDC/7/
As you can see in the problem image above, I would like to position the image alongside the title but keeping the structure of the html for a responsive layout.
<div class="listingWrapper clearfix">
<div class="headlineText">FLOAT: RIGHT</div>
<div class="subText">FLOAT: RIGHT</div>
<div class="logo">FLOAT: LEFT (ALONGSIDE HEADLINE)</div>
<div class="introduction">FLOAT: RIGHT</div>
Look at this fiddle: http://jsfiddle.net/caprella/7kbVX/
I propose to add one more wrapper .heading for .headlineText and .subText. It will give us opportunity to move the whole header. But that .heading steel needs fixed width:(
Check the Js fiddle
http://jsfiddle.net/CadDC/9/
<div class="listingWrapper clearfix">
<div class="logo">
<img class="listingImage" src="http://media-cdn.tripadvisor.com/media/photo-s/02/d0/d7/ed/hotel-du-vin-york.jpg" />
</div>
<div class="headlineText"><h2>Hotel name</h2></div>
<div class="subText">Mars - 0.7 miles from Mars City Centre</div>
<div class="introduction">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nost
</div>
</div>
Cant you just:
.listingImage{
max-width: 190px;
float: left;
}
I think this is your perfect answer http://jsfiddle.net/CadDC/14/ .
If you want it to be responsive you must give width and all in %.