How to get a specific layout in a row of different elements containing pictures and text in CSS/HTML? - html

I'm trying to create an overview that is spaced as the image that refers to my design. Currently I can't figure out how to make the items stay at the same spot when the length of the name variable will differ meaning the lay out is inconsistent.
This is my current attempt, I've tried working with a table but I could not figure out how to do it that way. I'm hoping someone can help we with my CSS code to get my website to match my design.
HTML code responsible for the printing
#wrapper {
border: 0px solid blue;
}
#Plant {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
width: 60px;
height: 60px;
}
#RoomNumber {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
width: 20px;
height: 20px;
border: 1px solid rgb(88, 163, 104);
}
#Roomname {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
width: 100;
height: 20;
}
#Whitespace {
display: inline-block;
width: 80px;
}
#RoomEdit {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
color: #bdbdbd;
width: 40px;
}
#RoomRemove {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
color: #e6555f;
width: 50px;
}
{% for plants in plants %}
<div id="Plant">
<img src="{{ url_for('static',filename='src/TestPlant.png') }}" width="70" height="70">
</div>
<div id="Roomname"> {{ plants.name }} </div>
<div id="Whitespace"> </div>
<div id="RoomEdit"> Edit </div>
<div id="RoomRemove"> Remove </div>
<hr style=color:#bdbdbd;>
{% endfor %}

I would wrap the row in a div and make it flex, then give sizes to all but the room name, which I would give flex-grow: 1
Below I have changed the following:
added row wrapper (align-items vertically centres the text)
added the border to the row and removed the hr (optional)
removed heights
removed whitespace div and used margin instead
changed ids to classes
removed width and height from img tag and given it 100% width (it seemed to be larger than the div it was in)
.row {
display: flex;
align-items: center;
border-bottom: 1px solid #bdbdbd;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
}
.Plant {
width: 60px;
height: 60px;
}
.Plant img {
display: block;
width: 100%;
}
.RoomNumber {
width: 20px;
border: 1px solid rgb(88, 163, 104);
}
.Roomname {
flex-grow: 1;
margin-right: 80px;
}
.RoomEdit {
color: #bdbdbd;
width: 40px;
}
.RoomRemove {
color: #e6555f;
width: 50px;
}
<div class="row">
<div class="Plant">
<img src="{{ url_for('static',filename='src/TestPlant.png') }}">
</div>
<div class="Roomname"> {{ plants.name }} </div>
<div class="RoomEdit"> Edit </div>
<div class="RoomRemove"> Remove </div>
</div>

Related

How to display container that is centered with content that is in the far left and far right of it

I would like to display the price of an object on my html website. This is what I would like it to look like:
Dynamic
The container is centered on the page with a max width of 400px
The "price" string is on the far left while the actual price is on the right of the centered content
This is what my html looks like:
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
</div>
This is what my css looks like:
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: white;
font-weight: 700;
font-size: 20px;
width: 90%;
max-width: 400px;
}
.price{
float: left;
}
.price-number{
float: right;
}
If you want to center it horizontally, you need to add margin:auto. I also cleared the floats for you.
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: black;
font-weight: 700;
font-size: 20px;
width: 90%;
max-width: 400px;
margin: auto;
border: 1px solid red;
}
.price{
float: left;
}
.price-number{
float: right;
}
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
<div style="clear:both"></div>
</div>
We can also write like this:
<div class="price-container">
<div class="price">price:</div>
<div class="price-number">{{ event.price }}.00</div>
</div>
CSS:
.price-container{
font-family: Montserrat;
text-transform: uppercase;
color: black;
font-weight: 700;
font-size: 20px;
width: 90%;
margin: 0 auto;
max-width: 400px;
border: 1px solid red;
display: flex;
justify-content: space-between;
}

Adding Thumbnail Image With CSS Border

I am trying to recreate what Lynda.com does with their course listing thumbnail image (see here). I am not sure how to place the image inside of my already existing code here. What I am not sure of is the dimensions of what the image should be each time and I am not sure how to handle the image resizing if my description is really long and widens the border. How would I do this?
If worse comes to worse, I will keep the descriptions small. I also realize that if the image also gets bigger if the description gets longer, the image getting bigger as a side effect will not look consistent with the other thumbnail images on the page.
HTML:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
<a class="course_list_link" href="">
<p class = "course_list_border">
<strong> Title </strong> <br/> <br/>
description <br/> <br/>
skill_level  
date  
Views: views  
subject </p> </a>
CSS:
.course_list_border{
border-style: solid;
border-width: 1px;
border-color: #DCDCDC;
padding: 10px;
word-wrap: break-word;
}
.course_list_border:hover{
background-color: #F8F8F8;
cursor: pointer;
}
.course_list_link{
color: black;
}
.course_list_link:hover{
text-decoration: none;
color: black;
}
body {
min-height: 400px;
margin-bottom: 100px;
margin-top: 0%;
clear: both;
padding-top: 55px;
font-family: 'Roboto', sans-serif;
font-size: 16.5px;
}
I have made some changes in your css and HTML file
.course_list_border{
border-style: solid;
border-width: 1px;
border-color: #DCDCDC;
padding: 10px;
word-wrap: break-word;
}
.course_list_border:hover{
background-color: #F8F8F8;
cursor: pointer;
}
.course_list_link{
color: black;
display: inline-block;
width: 30%;
}
.course_list_link:hover{
text-decoration: none;
color: black;
}
body {
min-height: 400px;
margin-bottom: 100px;
margin-top: 0%;
clear: both;
padding-top: 55px;
font-family: 'Roboto', sans-serif;
font-size: 16.5px;
}
<a class="course_list_link" href="">
<p class = "course_list_border">
<strong> Title </strong> <br/> <br/>
description <br/> <br/>
<img src="https://via.placeholder.com/200X150" alt="Lights" style="width:100%"/>
skill_level  
date  
Views: views  
subject </p>
</a>
As you are using bootstrap you can also make use of existing classes for creating this kind of image thumbnails
https://getbootstrap.com/docs/4.0/content/figures/
Generally, it's far better to separate all items into elements, instead of concatenating them into a single paragraph. For example:
<style>
a.course_list_link {
display: block;
width: 300px;
border: 1px solid #DCDCDC;
border-radius: 5px;
text-decoration: none;
font-family: 'Roboto', sans-serif;
transition: all, 0.3s, ease;
}
a.course_list_link:hover .thumbnail {
filter: grayscale(50%);
}
a.course_list_link:hover {
background-color: whitesmoke;
}
a.course_list_link:active {
background-color: white;
}
a.course_list_link:hover p.description {
color: black !important;
}
.course_list_link .thumbnail {
background-color: grey;
background-size: cover; /* Guarantees your background always fits the thumbnail size, no matter its aspect ratio */
height: 150px;
}
.course_list_link .play-button {
opacity: 0.5;
height: inherit;
width: inherit;
background-size: 50px;
background-repeat: no-repeat;
background-position: center;
}
.course_list_link:hover .play-button {
background-image: url('https://www.drury.edu/images/socialmediaicons/play_button.png');
}
.course_list_link .content-area {
margin: 5px;
}
.course_list_link h2 {
color: black;
font-weight: 500;
font-size: 18px;
margin: 0;
}
.course_list_link p.description {
margin: 0;
margin-bottom: 5px;
font-size: 14px;
color: grey !important;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
color: black;
}
.metadata {
font-size: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.column {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.metadata .skill {
color: grey;
}
.metadata .date {
color: grey;
}
.metadata .views {
color: grey;
}
.metadata .subject {
font-weight: bold;
color: grey;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<a class="course_list_link" href="#">
<div class="thumbnail" style="background-image: url('https://img-aws.ehowcdn.com/560x560p/photos.demandstudios.com/getty/article/188/230/dv030463.jpg');"><!-- Set the bg image of this element in CSS -->
<div class="play-button"></div>
</div>
<div class="content-area">
<h2>Title</h2>
<p class="description">Description of the video, which may or may not be very long depending on the type of video, and what is chosen to display, and how many lines the space is allowed to occupy in the thumbnail.</p>
<div class="metadata">
<div class="column">
<div class="skill">Skill level</div>
<div class="views">Views</div>
</div>
<div>
<div class="date">Date</div>
</div>
<div>
<div class="subject">Subject That is Too Long And Will Inevitably Overflow to New Lines If Not Blocked by Some Sort of CSS Trick</div>
</div>
</div>
</div>
</a>
I also like to set the thumbnails in CSS. That way, even if your thumbnail changes size, it is always cropped at the same size within the HTML element. However, it's always good to ensure that images are not oversized so that the page loads quickly; therefore, making real thumbnails is always a good idea.
Just as a side note, it's general CSS good practice to use hyphens instead of underscores, so .course_list_link becomes .course-list-link.

how to align multiple <h1> tags

I wanted to make a header with a title in the center "Resources", left another title "HTML" and right another with "CSS" but I can not align them to put them in the right place and then add a border-right and border-left to separate the left and right title from the title to the center.
For the moment I have this:
header {
border: 2px solid white;
border-radius: 20px;
background-color: rgba(0, 0, 0, 0.2);
color: white;
}
h1 {
display: inline-block;
font-size: 30px;
font-family: Arial, sans-serif;
}
h1.html {
padding-left: 2%;
}
h1.res {}
h1.css {
padding-right: 2%;
}
<header>
<h1 class="html">HTML</h1>
<h1 class="res">Ressources</h1>
<h1 class="css">CSS</h1>
</header>
Because of the display: inline-block; it works better but I do not know how to do it.
It would be simpler to replace the <h1> tags with <span> elements because they are inline by default. The left and right separation can be accomplished several ways. See example below.
.header {
text-align: center;
border-radius: 20px;
background-color: rgba(0,0,0,0.2);
color:white;
font-family: Arial, Helvetica, sans-serif;
font-weight: bolder;
font-size: 24px;
}
.header span:nth-child(1) {
float: left;
width: 33%;
border-right: 2px solid white;
}
.header span:nth-child(3) {
float: right;
width: 33%;
border-left: 2px solid white;
}
<div class='header'>
<span>HTML</span>
<span>RESOURCES</span>
<span>CSS</span>
</div>
You can use a flex layout to position the headings. Add this to your existing header ruleset:
header {
display: flex;
justify-content: space-between;
}

How to set max-width for DIV contents but not the DIV itself?

UPDATE: Here's a Fiddle: https://jsfiddle.net/720v4zdy/8/
I'm customizing a tumblr blog to match someone's site and it's almost in good shape. We started with a theme that already matched it closely and then made some changes in CSS.
The last problem I can't solve is how to make the navigation bar stretch the entire page while containing all of the links in a max-width of 1024px.
Here's the tumblr blog WIP: http://craftysheepblog.tumblr.com/
I want the navigation bar to stretch the entire page, but the links to be contained with a max-width of 1024px. The trouble here is I only have one DIV to do this with, so I'm not quite sure how to make it happen.
I'm using this currently, which works somewhat. It gets ugly when you make the browser window smaller though.
#top nav {
background-color: rgb(45, 50, 51);
color: white;
text-align: left;
padding: 11px 22%;
margin-top: 20px;
width: 100%;
}
You can set the nav to max width: 1024px and fill the "gaps" on the sides with ::before and ::after pseudo elements. You'll need to hide the overflow on header#top to avoid sideways scrolling, because the pseudo elements are set wider than the content.
This does rely on you setting the height of your nav and following suit with the <a> (height, line-height, etc.) ...
Also - tweak some more; there is a 600px break point in your CSS on the live site that will interfere with this (along with a lot of your extra CSS that I didn't clean up).
body {
color: rgb(38, 39, 43);
font-family: "Open Sans", "sans-serif", Arial;
font-weight: 300;
font-size: 14px;
line-height: 1.42857143;
margin: 0;
}
#top {
overflow: hidden;
}
#top .title {
font-family: "Open Sans", "sans-serif", Arial;
font-size: 30px;
text-align: left;
font-weight: lighter;
margin-top: 18px;
display: block;
width: 100%;
max-width: 1024px;
margin-left: auto;
margin-right: auto;
}
#top nav {
background-color: rgb(45, 50, 51);
color: white;
text-align: left;
max-width: 1024px;
margin: 50px auto 20px;
height: 50px;
width: 100%;
border-width: 0;
padding: 0;
position: relative;
}
#top nav::before{
background: rgb(45,50,51);
content: "";
display: block;
position: absolute;
height: 50px;
width: 100%;
right: 100%;
}
#top nav::after{
background: rgb(45,50,51);
content: "";
display: block;
position: absolute;
height: 50px;
width: 100%;
left: 100%;
top: 0;
}
#top nav a {
border-bottom: 1px solid rgba(255, 255, 255, 0);
font-size: 13px;
letter-spacing: 1px;
font-weight: 600;
margin: 0px 15px;
}
#top nav a {
color: #fff;
font-size: 13px;
text-transform: none;
font-family: "Open Sans", "sans-serif", Arial;
font-weight: 300;
border: 0;
display: inline-block;
padding: 0 1em;
margin: 0;
height: 50px;
line-height: 50px;
}
#top nav a:hover {
color: #52A708;
}
#top .headimg {
display: none;
}
<header id="top">
<div class="row">
<div class="small-12 small-centered columns">
<a href="/" class="active">
<div class="title">Page Title</div>
</a>
<nav>
<a class="page" href="#">Link 1</a><a class="page" href="#">Link 2</a><a class="page" href="#">Link 3</a>
</nav>
</div>
</div>
</header>
How about using max-width: 1024px;
The best way to do this is to use a ul inside of a div as your navigation bar. The ul can contain all of your links. That way, the div can have a width that spans the entire page while the unordered list has a max width of 1024px.
Example code:
<html>
<head>
<style>
#nav {
width: 100%;
height: 20%;
}
#nav-links {
max-width: 1024px;
}
</style>
</head>
<body>
<div id="nav">
<ul id="nav-links">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>...</li>
</ul>
</div>
</body>
</html>
Then you can style your ul as a nav bar however you like. Here's a good link for that: http://www.w3schools.com/css/css_navbar.asp
With the amount of information you have shared it is hard to say. Obviously the cleanest way to accomplish this is to insert another element (div or otherwise) around these child elements, and assign it a max-width... however this does not sound as if it is an option for you?
If you know how many elements you want to make up the 1024px, you could assign their widths manually (i.e. give each of the four children a width of 256px, or something similar).
If you do not know any of these things, and your options for the space are limited, Javascript is your best option. You could write a script that counts the children, and either assigns their widths appropriately or inserts clears at the proper location.
If you expand your question to target a specific approach, I'm sure myself and the many gurus on here will be able to give you more specific guidance.
Use flexbox: https://philipwalton.github.io/solved-by-flexbox/
The links should stretch as normal but start to shrink when they each exceed 341px which is 1023px as a total width.
Note: Snippet best viewed in Full Page mode.
Relevant CSS
#top nav {
background-color: rgb(45, 50, 51);
color: white;
text-align: left;
padding: 11px 22%;
margin-top: 20px;
display: flex;
flex-flow: row nowrap;
justify-content: baseline;
#top nav a {
border-bottom: 1px solid rgba(255, 255, 255, 0);
font-size: 13px;
letter-spacing: 1px;
font-weight: 600;
margin: 0px 15px;
flex: 0 1 341px;
}
body {
color: rgb(38, 39, 43);
font-family: "Open Sans", "sans-serif", Arial;
font-weight: 300;
font-size: 14px;
line-height: 1.42857143;
}
.row {
max-width: 100%;
}
#top {
margin-top: 0px;
}
#top .title {
font-family: "Open Sans", "sans-serif", Arial;
font-size: 30px;
text-align: left;
font-weight: lighter;
margin-top: 18px;
display: block;
width: 100%;
max-width: 1024px;
margin-left: auto;
margin-right: auto;
}
#top nav {
background-color: rgb(45, 50, 51);
color: white;
text-align: left;
padding: 11px 22%;
margin-top: 20px;
display: flex;
flex-flow: row nowrap;
justify-content: baseline;
}
#top nav a {
border-bottom: 1px solid rgba(255, 255, 255, 0);
font-size: 13px;
letter-spacing: 1px;
font-weight: 600;
margin: 0px 15px;
flex: 0 1 341px;
}
#top nav a {
color: #fff;
font-size: 13px;
text-transform: none;
text-decoration: none;
font-family: "Open Sans", "sans-serif", Arial;
font-weight: 300;
}
#top nav a:hover {
color: #52A708;
}
#top .headimg {
display: none;
}
#posts {
width: 100%;
max-width: 1024px;
margin-left: auto;
margin-right: auto;
}
.column,
.columns {
padding: 0;
}
#posts article:nth-child(1) {
padding-top: 20px;
}
#posts article .title {
font-family: "Open Sans", "sans-serif", Arial;
font-size: 36px;
color: rgb(38, 39, 43);
text-align: center;
font-weight: 500;
}
#posts article footer {
display: none;
}
#paginate {
display: none;
}
#bottom {
border: none;
}
#bottom {
border: none;
max-width: 1024px;
width: 100%;
display: block;
margin-left: auto;
margin-right: auto;
}
<header id="top">
<div class="row">
<div class="small-12 small-centered columns">
<img class="headimg" src="http://assets.tumblr.com/images/x.gif?v=1">
<a href="/" class="active">
<div class="title">Page Title</div>
</a>
<div class="description"></div>
<nav>
<a class="page" href="/online-store">Shop NAO</a><a class="page" href="/nao-couture">NAO Couture</a><a class="page" href="/nao-experience">NAO Experience</a>
</nav>
</div>
<!--.columns-->
</div>
<!--.row-->
</header>

How do you align text vertically inside a container regardless of # of links inside them?

I need some assistance and I've tried almost everything I know. What I am trying to do (and it doesn't matter if I have to use tables on order to achieve this)
http:// img602.imageshack.us/img602/8769/verticalcentering .jpg
I've looked online and tried out several examples but they all seem to blow up or not align properly in IE.
What I need (if its possible, I don't even know anymore) is to have text links that will align vertically within the container its in regardless of whether there is only one link present, or four.
What's been happening is that when I set the margin to 50% it centers fine if there is only one link there, but the remainder will fall below it no longer centering the links within the container.
The actual thing I am working on is this:
I have a header title above that stretches across the container. The next row I have an image on the left that is 150px by 150px - and next to that I have another container that has a height of 150px as well as this is the maximum height of this container - inside this container is where I would like my links to hang out vertically centered.
Is this even possible? or is it a pipe dream to think it will work in IE and is cross browser compliant?
It doesn't matter anymore if I have to resort to tables and css to achieve this... I just need some assistance with it as I have never had to vertically center anything depending on its content before and I just can't wrap my head around how to achieve this effect.
Any help would be greatly appreciated :) Thanks in advance!
HERE IS THE CSS AND HTML BELOW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Link Module</title>
<style type="text/css">
<!--
.wrapper { height: 210px; width: 538px; background-color: #FFCCFF; }
.header { height: 47px; border-bottom: thin dotted #666; }
.txt-style {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
line-height: normal;
font-weight: bold;
color: #666666;
text-decoration: none;
text-align: left;
vertical-align: middle;
white-space: normal;
display: block;
}
.cos-sl-txt-cntr-two {
height: 150px;
}
.cos-sl-txt-cntr-two ul {
height: 150px;
margin-top: auto;
margin-bottom: auto;
}
.cos-sl-txt-cntr-two li {
margin-top: 50%;
margin-bottom: auto;
}
cos-sl-img-two {
width: 150px;
height: 150px;
background-color: #FF0033;
}
.learn-txt, .leader-txt {
color: #FF6666;
font-family: "Arial", Helvetica, sans-serif;
text-transform: uppercase;
font-size: 12px;
margin: 0;
padding-top: 2px;
padding-left: 10px;
letter-spacing: .75px;
}
.leader-txt {
color: #fff;
font-size: 23px;
font-weight: bold;
padding-top: 0px;
line-height: 24px;
letter-spacing: -0.25px;
}
.img-ctnr, .img-ctnr-two {
width: 150px;
height: 150px;
float: left;
padding-left: 12px;
}
/* IMAGE LOCATION */
.img-two {
width: 150px;
height: 150px;
display: block;
background-color: #FF99CC;
border: solid 3px #CCC;
}
.txt-cntr, .txt-cntr-two {
width: 406px;
height: 126px;
float: left;
}
.txt-cntr-two {
width: 250px;
height: 150px;
padding-left: 50px;
background-color:#CC99CC;
}
.txt-pos {
float: left;
width: 100px;
height: 50px;
padding-left: 20px;
}
/* NAME TEXT/TITLE TEXT */
.name-txt, .info-txt, .name-txt-title, .info-txt-link {
font-family: "Arial", Helvetica, sans-serif;
font-size: 13px;
color: #003466;
margin: 0;
padding-top: 18px;
padding-left: 13px;
}
.sl-name-txt-title {
color: #666;
font-size: 10px;
font-weight: bold;
}
/* INFO TEXT/TEXT LINK OVER-RIDE */
.info-txt, .info-txt-link {
padding-top: 0;
color: #333;
font-size: 12px;
line-height: 1.1;
}
.info-txt-link a {
color: #003466;
text-decoration: none;
}
/* Hover State for the web links */
.info-txt-link a:hover {
color: #ED1B24;
text-decoration: none;
}
-->
</style>
</head>
<body>
<div class="wrapper">
<!--CONTAINER HOLDING THE HEADER ELEMENTS-->
<div class="header">
<p class="learn-txt">Title</p>
<p class="leader-txt">Subtitle</p>
</div>
<div class="img-ctnr-two">
<div class="img-two">
</div>
</div>
<div class="txt-pos">
<p class="name-txt-title">Canada</p>
<p class="info-txt-link">www.mylinkhere.com</p>
</div>
</div>
</body>
</html>
.outer {
border: 1px solid red;
line-height: 5em;
}
.outer .inner {
display: inline-block;
vertical-align: middle;
line-height: 1.2em;
}
<div class="outer">
<div class="inner">
ABC
</div>
</div>
<div class="outer">
<div class="inner">
ABC<br>ABC
</div>
</div>
<div class="outer">
<div class="inner">
ABC<br>ABC<br>ABC
</div>
</div>