jsfiddle: https://jsfiddle.net/hfnmspwa/3/
I have floating DIVs with text in that resize as browser window resized. This is working however I cannot get these text boxes to center in the middle of the page. There is no float center! Please see the jsfiddle for further info - I have put some further notes in the JS quadrant.
.infos_div {
background-color: #FFF;
}
.infos_div::after {
content: "";
clear: both;
display: table;
}
.infos_container_div {
background-color: #9FC;
display: inline-block;
}
.info_div {
display: inline-block;
cursor: pointer;
float: left;
text-align: center;
width: auto;
height: auto;
min-height: 80px;
max-width: 30%;
min-width: 200px;
padding: 10px;
margin: 10px;
z-index: 1;
background-color: #FFF;
white-space: normal;
}
<div class="infos_div">
<div class="infos_container_div">
<div class="info_div">
<strong>Feature 1</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 2</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 3</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 4</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div" o>
<strong>Feature 5</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>SFeature 6</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
</div>
</div>
You could give the parent element center text alignment and remove the float.
So add text-align: center; to .infos_container_div and remove float: left; from .info_div.
https://jsfiddle.net/hfnmspwa/4/
If you take the
float:left;
Off of .info-div they should center.
You can use grids, if you necessarily need the 3 paragraphs to be centered.
* {
margin: 0;
padding: 0;
}
.infos_div {
background-color: #FFF;
}
.infos_div::after {
content: "";
clear: both;
display: table;
}
.infos_container_div {
background-color: #9FC;
display: grid;
grid-template-areas: ". . .";
text-align: center;
grid-gap: 10px;
padding: 10px;
}
.info_div {
display: inline-block;
cursor: pointer;
text-align: center;
width: auto;
height: auto;
padding: 10px;
z-index: 1;
background-color: #FFF;
white-space: normal;
}
<div class="infos_div">
<div class="infos_container_div">
<div class="info_div">
<strong>Feature 1</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 2</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 3</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>Feature 4</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div" o>
<strong>Feature 5</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
<div class="info_div">
<strong>SFeature 6</strong>
<div class="info_text">blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah, blah blah blah</div>
</div>
</div>
</div>
Related
I am trying to make a hero image on my wordpress site (genesis theme). I do not want to use a plugin, I want to make it from scratch. I am trying to have the title of the page and a quick blurb contained in the hero image section at all times (like below)
IMG 1
My current set up works fine at full screen, but when the screen is smaller, the blurb moves out of the hero image and the hero image gets smaller and blocked by the navbar (see below)
I want the blurb to be in the hero image at all times. When I move the blurb div into the same div as the hero image, the blurb ends up under the footer for some reason.
I have left my code below. Please let me know if you guys would like more info
<div style="width:100%">
<div style="position: absolute; top: 99px; overflow: auto; z-index: -1; width:100vw" aria-live="polite">
<img style="/*height: 100%;*/ max-height:100% ;min-width: 100%; object-fit: cover;" src="https://mywordpress.site.com/wp-content/path-to-img/hero-image-scaled.jpg" alt="" />
</div>
<div class="our-process-header">
<div style="display: flex; align-items: center; justify-content: center; padding-top: 20px;">
<p style="text-align: center;">
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.
</p>
</div>
<p> </p>
</div>
</div>
The style for our-process-header is below
#media screen and (max-width: 1070px) {
.our-process-header {
width: 100%;
}
}
#media screen and (min-width: 1300px) {
.our-process-header {
width: 50%;
}
}
I have a flexbox layout in my app similar to the snippet below, a set of lis with three divs in each
.container {
width: 500px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
li {
border: solid 1px black;
flex: 1;
}
.title {
border: solid 1px red;
margin-bottom: 1em;
}
.content {
border: solid 1px yellow;
margin-bottom: 1em;
}
.footer {
border: solid 1px blue;
}
<div class="container">
<ul>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
</ul>
</div>
I'm looking to have the children divs start at the same level across the times, e.g. the yellow div tops are equal, and the blue div tops are equal. Previously I've done this by making the children divs absolute positioned, and then have them be fixed height, with fixed tops. However, doing this, I have to set the heights based on the guessed maximum size of the text they will contain, which, when combined with the page being responsive (There is single breakpoint where it goes from side by side columns to a carousel), this can lead to a lot of empty space in the columns.
Most examples I've found (as I apparently don't really know the right terms to google this...) involve either Javascript, or rearranging the markup to have the rows at the top of the hierarchy, instead of the columns. I would like to stick with columns, they're set up to handle the cases of 1, 2, or 3 columns, and also serve as a carousel on small devices.
Am I missing how to do this, or am I stuck with Javascript?
You're looking for display:flex-box. Here is some documentation: https://css-tricks.com/snippets/css/a-guide-to-flexbox/.
I have had a go at your current situation, one thing to point out is you're going to need to use both flex directions (row & column).
Another would be if you're using borders and trying to get boxes to align along one row you will need to introduce box-sizing:border-box (includes borders and padding into the declared width). I have also used a calculation on the width of your columns to use the maximum amount of space available in the row reducing any guess-work.
You can apply this to your needs:
.container * {
box-sizing: border-box;
}
.container {
width: 500px;
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
flex-direction: row;
align-items: stretch;
justify-content: center;
}
li {
width: calc(100% / 3);
border: solid 1px black;
box-sizing: border-box;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
li > div {
width: 100%;
padding: 0;
margin: 0;
}
li > div + div {
margin-top: 20px;
}
.title {
border: solid 1px red;
}
.content {
border: solid 1px yellow;
}
.footer {
border: solid 1px blue;
}
<div class="container">
<ul>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
<li>
<div class="title">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</li>
</ul>
</div>
If you change your HTML markup to this (remove ul li) you could do this with Flexbox. You can set flex: 0 0 33% on each item and flex-wrap: wrap so when flexbox wrap items to new row it will keep same height of items in each row. You then need to adjust order of elements to column with nth-child() selector.
* {
box-sizing: border-box;
}
.container {
width: 500px;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
div > div {
flex: 0 0 33%;
}
div > div:nth-child(3n-2) {
order: 1;
}
div > div:nth-child(3n-1) {
order: 2;
}
div > div:nth-child(3n) {
order: 3;
}
.title {
border: solid 1px red;
margin-bottom: 1em;
}
.content {
border: solid 1px yellow;
margin-bottom: 1em;
}
.footer {
border: solid 1px blue;
}
<div class="container">
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
<div class="title">
Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
<div class="title">
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="content">
Blah Blah Blah Blah Blah Blah Blah Blah
</div>
<div class="footer">
Some other stuff here
</div>
</div>
Part of a mockup I'm working on is the following.
I'm trying to get the triangular right end of the "Delay Your Payments" div to match the mockup, if possible using CSS without using any sliced images and without using using any absolutely valued pixels or anything that will screw up if the dimensions of the container change after more text is added.
Attempt: http://jsfiddle.net/a7L3tytp/
HTML:
<div class="delay-your-payments">
<h3>Delay Your Payments</h3>
<p>Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p>
</div>
CSS:
div.delay-your-payments { background: #1AA3B4; padding: 20px; position: relative; width: 80%; }
div.delay-your-payments:after { color: #1AA3B4; right: 0; position: absolute; content: "\25B6"; top: 50%; transform: translateY(-50%); right: -11px; }
div.delay-your-payments > h3 { color: #FFF; }
div.delay-your-payments > p { color: #FFF; }
Here's my solution
div.delay-your-payments { float:left;background: #1AA3B4; padding: 20px; height:200px;position: relative; width: 80%; }
div.delay-your-payments > h3 { color: #FFF; }
div.delay-your-payments > p { color: #FFF; }
.arrow-right {
width: 0;
height: 0;
border-top: 100px solid transparent;
border-bottom: 100px solid transparent;
border-left: 100px solid green;
float:left;
}
*{
box-sizing:border-box;
}
<div class="delay-your-payments">
<h3>Delay Your Payments</h3>
<p>Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p>
</div>
<div class="arrow-right"></div>
I'm trying to do an iphone style swipey thing on my webpage. The idea is that in my sidebar, if I click a link it will side the sidebar to the left to reveal where that link would go to. To do this, I am creating two sidebars side by side, the visible sidebar and the next sidebar that will be hidden behind another element.
An example of the sidebars can be found at http://jsfiddle.net/gpcC6/7/
The problem I'm having, is when the window is resized, the second sidebar goes under the first. I want to to stay to the right, even if it means that it goes off the side of the screen. Is this possible?
Thanks
Put the sidebars in a container that has white-space: nowrap and make them display: inline-block instead of floating them and it should work as per your instructions.
Note that white-space: nowrap in some browsers will interpret the space between two divs in the HTML as an actual space
<div>
</div><!-- SPAAAAAACE -->
<div>
</div>
To remove that spacing you need to place them on the same line
<div>
</div><div>
</div>
Alternatively, you can add a font: 0; to the parent element, in this case the container that will remove the spacing as well, but beware that you need to explicitly define the font size for all elements before you do that, otherwise all the child elements will have a font size of 0 as well. ;)
See this question and this article for more information.
Sample | Code
CSS
div{
font-size: 16px;
}
#topbar {
height: 40px;
background-color: blue;
}
.wrapper{
white-space: nowrap;
font-size: 0;
}
.sidebar {
width: 200px;
display: inline-block;
white-space: normal;
}
.title {
height:30px;
background-color: red;
}
.main {
height: auto;
overflow: scroll;
}
HTML
<div id="topbar">
hello
</div>
<div class='wrapper'>
<div class="sidebar">
<div class="title">
title
</div>
<div class="main">
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
</div>
</div>
<div class="sidebar">
<div class="title">
title
</div>
<div class="main">
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
</div>
</div>
</div>
Put a wrapping div around your bars and give it a fixed width or a min-width. Then you must only look that your sidebars fit in this wrapping container next to each other. That guarantees that they stay next to each other even when the window is smaller and you can scroll horizontally.
I want a format html using CSS so that I get the following:
Image on the left, with subject and
body next to it on the right. I want
subject to be on one line and the body
to be on the other.
With One message after each other
on subsequesnt blocks downs the page.
However I'm getting the subject and the body one one line and a cacade effect down the
page.
Here is what I seem to be getting.
I just cannot seem to get the hang of what's needed.
My html is :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>messages to/from someone</title>
<link rel="stylesheet" type="text/css" href="messages.css" />
</head><body>
<div class'message'>
<span class='to'>
<img class='floatimgleft' src='../code/images/arrow-right.png' width='64' height='64' border='0' />
<span class='subject'>subject</span>
<span class='body'>body</span>
</span>
</div>
<div class'message'>
<span class='to'>
<img class='floatimgleft' src='../code/images/arrow-right.png' width='64' height='64' border='0' />
<span class='subject'>subject</span>
<span class='body'>body</span>
</span>
</div>
<div class'message'>
<span class='to'>
<img class='floatimgleft' src='../code/images/arrow-right.png' width='64' height='64' border='0' />
<span class='subject'>subject</span>
<span class='body'>body</span>
</span>
</div>
</body></html>
My CSS is:
.floatimgleft {
float:left;
margin-top:10px;
margin-right:10px;
margin-bottom:10px;
}
.message{
display: block;
}
.subject {
display: inline;
}
.body {
display: inline;
}
Edit: I've edited the code to show where I started from. I was under the impression that div class='message' would cause a line break between messages but I'm getting a cascade effect.
Add:
class="floatimgleft"
to your img tags:
<img src='../code/images/arrow-right.png' width='64' height='64' border='0' class="floatimgleft" />
Also, seems you are not using to class either and you are missing = in the <div class'message'>.
Here's a jsfiddle to test it out:
http://jsfiddle.net/CdBSU/
EDIT: For having it clear, add clear: left to message. See the fiddle:
http://jsfiddle.net/CdBSU/2/
for a demonstration.
For the layout you were looking for, I would probably go with something more like:
Index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>messages to/from someone</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<ul id="messages">
<li>
<div>
<span class="icon"></span>
<h2>Subject</h2>
<p>Body.. Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</p>
</div>
</li>
<li>
<div>
<span class="icon"></span>
<h2>Subject</h2>
<p>Body.. Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</p>
</div>
</li>
</ul>
</body>
</html>
Style.css:
h2, p { clear: none; padding: 0px; margin: 0px; }
ul#messages { text-align: left; }
ul#messages li { margin-bottom: 25px; }
ul#messages li > div > span.icon { float: left; display: block; width: 64px; height: 64px; border: 1px solid #111; /* border added to demonstrate */ background-image: url('../code/images/arrow-right.png'); }
Demonstrated at: http://jsfiddle.net/j7KHg/2/