I have a job site designed with with css grid. The job listings and email subscribe are divided bygrid-template-columns: (3fr, 1fr), the problem is is that the email subscribe box is the same height as the job listings (if there are 10 listings for example this is quite a large email subscribe box), how can I change this? (Note: jsfiddle included at bottom will make it much more clear and I have tried to set a height value on #item2 and this did not work) Thanks in advance!
.grid {
display: grid;
grid-template-columns: 3fr 1fr;
}
#item1 {
margin-left: 15px;
}
#item1>h1 {
text-align: center;
}
#list_of_jobs {
list-style: none;
}
#item2 {
text-align: center;
margin-right: 15px;
border: 3px solid #eeeeee;
}
<div class="grid">
<div id="item1">
<h1>Jobs in 10529</h1>
<table>
<tbody>
<div>
<ul id="list_of_jobs">
<li>
<h2>Job 1</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 2</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 3</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 4</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
</ul>
</div>
</tbody>
</table>
</div>
<div id="item2">
<form>
<p>Subscribe to recieve job alerts near 105</p>
<!-- query stores zip code-->
<input type="text" placeholder="Email">
<button class="btn" type="submit">Subscribe</button>
</form>
</div>
</div>
<!-- close grid div-->
http://jsfiddle.net/bmy0s93k/2/
Add this to your code:
#item2 {
align-self: start;
}
revised fiddle
A default setting in a grid container (like in a flex container) is align-items: stretch. This means that grid items (like flex items) will stretch the full length of the relevant axis in the container.
You need to override the default.
References:
§ 6.2. Block/Cross-Axis Alignment: the align-self property
How to disable equal height columns in Flexbox?
Related
This question already has answers here:
:empty selector not working in css
(3 answers)
Closed 3 years ago.
I work in Twig on symphony and have an empty div that should be hidden in print mode.
<div class="form-fields__list">
</div>
The thing is that on screen the :empty selector works just fine, but is being ignored in print mode. Even tried to wrap the block mentioned above in {% spaceless %} block in order to remove any possible whitespaces. Anyone have an idea why this might be happening?
The :empty pseudo selector will select elements that contain either nothing or only an HTML comment.
Will Match
<div></div>
<div><!-- test --></div>
Will Not Match
<div> </div>
<div>
<!-- test -->
</div>
<div>
</div>
.container {
margin: 40px auto;
max-width: 700px;
}
#media print {
p:empty {
background-color: linen;
padding: 15px;
}
}
.pseudo::before {
content: "I am a piece of generated content inside a paragraph. The paragraph is still considered empty and gets a background color.";
}
<div class="container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, in, odit autem tempora fuga neque quos expedita repudiandae labore iure. Rem, blanditiis natus unde nisi explicabo odio pariatur maxime earum.
</p>
<p></p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque, tempora, ratione ad distinctio iusto illum accusamus qui porro inventore commodi voluptates tenetur dolor sed harum excepturi nemo aperiam beatae sint!
</p>
<p class="pseudo"></p>
<p>
<!-- COMMENT HERE -->
</p>
<p></p>
</div>
I using Bootstrap 3 and im trying to reorder the columns position in mobile and tablet.
How is this possible?
this is my code:
<div class="row main-row">
<div class="col-md-6">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quia illum recusandae delectus assumenda adipisci minima eaque! Tempore sit eius error, enim, voluptatem repudiandae dolorem atque fugiat aperiam placeat, corporis consequuntur.
</div>
<div class="col-md-6">
</div>
</div>
I want to Bootstrap to show
Text
Image
Text
Image
Right now it shows
Image
Text
Text
Image
Is there a way to handle this?
What it looks like right now
Can use flex in the mobile version.
.main-row {
display: flex;
flex-flow: column;
}
.main-row .col-md-6 {
display: flex;
order: 1;
}
.main-row .col-md-6 +.col-md-6 {
display: flex;
order: 0;
}
<div class="row main-row">
<div class="col-md-6">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quia illum recusandae delectus assumenda adipisci minima eaque! Tempore sit eius error, enim, voluptatem repudiandae dolorem atque fugiat aperiam placeat, corporis consequuntur.
</div>
<div class="col-md-6">
IMGES
</div>
</div>
Unfortunately in Bootstrap 3 you cannot change the order of columns in smaller screens but you can do that in large screens. In Bootstrap 4 you can now change the order of columns in smaller screens. Below you can see one way of doing this.
<div class="row flex-column-reverse flex-md-row">
<div class="col-md-3">
sidebar
</div>
<div class="col-md-9">
main
</div>
</div>
I know this topic has already get an answer here, but there is a little difference in my case.
You have to know that unfortunately I can't edit the HTML because I use Visual Composer for WordPress that generate its own HTML. I can only add classes or IDs on HTML tags via Visual Composer in the WordPress backoffice. It will be so long to edit the HTML of every Visual Composer blocks (with the WordPress text mode). So I have to find another efficient way to do it.
So, to align all the items between them I tried many solutions:
I first tried to use a min-height on the parent div that is set to a relative position, then I put the buttons at absolute position with a bottom of 0.
It worked for the buttons alignment but I want it to be automatic and managed by itself in case when there is more text content and I don't want to change several times the min-height in several responsive modes.
So I tried the FlexBox solution of the link I shared above.
This solution works when we have only an image, a text and a button,
but in my case I have a title between each of the images and text contents, so it means we can have a title on 1 line or 2 lines or more... The problem with that is a misalignment of the titles between themselves and the "Lorem Ipsum" texts as well.
How can I manage it?
Thank you for the help.
I provided the code snippets to see my issue:
.sameblockheight, .wpb_wrapper {
display: flex;
flex-direction: column;
}
.vc_column-inner {
flex-grow: 1;
display: flex;
}
.wpb_wrapper {
flex-grow: 1;
justify-content: space-between;
}
.subrow {
display: flex;
}
.subrow > div {
width: 200px;
}
.vc_column-inner {
padding: 6% 8%;
}
.button-blue {
text-align: center;
}
.alignnone {
margin-left: auto;
margin-right: auto;
display: block;
}
<div class="subrow">
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896965169">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 1 line</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur beatae officiis ea, corporis eos quas temporibus asperiores iste impedit laborum et non, itaque eaque dignissimos. Distinctio, quaerat vel consectetur! Pariatur.</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner ">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 2 lines ...............................</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque quas in quod quae magni eligendi dicta totam, placeat eveniet facere cupiditate natus aut, impedit incidunt error veritatis libero suscipit nisi.</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896977260">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 3 lines ................ ................. ......................... ............... ...........</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. In ullam optio quia nam aliquam numquam ipsa incidunt possimus consequatur sed animi hic facere mollitia facilis libero cupiditate eaque, molestiae voluptas!</p>
<a class="button-blue" href="https://staging.unify.com/en/solutions/voice-platforms/preconfigured-unified-communications">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896983086">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui provident eum voluptas veritatis ducimus iste enim recusandae aliquid sequi ad sapiente dolore similique nihil eos placeat, consectetur odit beatae voluptatum?</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
</div>
The only solution i can think of with only CSS is to add a min-height to your titles h5. For example i added min-height:40px and now, all the h5 are equal in height. You can set a bigger/smaller one.
The downsize is that if a title is larger that the min-height you set you have that problem again.
One fullproof solution would be to add a little javascript/jQuery to make the h5 equal in height without setting a 'hardcoded' min-height.
If you want/can use javaScript/jQuery let me know and i'll make a solution with that. If not, and you want to use only CSS, the below solution is the only one that i can think of.
h5 {
min-height:40px;
margin-top:0;
}
.sameblockheight, .wpb_wrapper {
display: flex;
flex-direction: column;
}
.vc_column-inner {
flex-grow: 1;
display: flex;
}
.wpb_wrapper {
flex-grow: 1;
justify-content: space-between;
}
.subrow {
display: flex;
}
.subrow > div {
width: 200px;
}
.vc_column-inner {
padding: 6% 8%;
}
.button-blue {
text-align: center;
}
.alignnone {
margin-left: auto;
margin-right: auto;
display: block;
}
<div class="subrow">
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896965169">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 1 line</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur beatae officiis ea, corporis eos quas temporibus asperiores iste impedit laborum et non, itaque eaque dignissimos. Distinctio, quaerat vel consectetur! Pariatur.</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner ">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 2 lines ...............................</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Neque quas in quod quae magni eligendi dicta totam, placeat eveniet facere cupiditate natus aut, impedit incidunt error veritatis libero suscipit nisi.</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896977260">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title on 3 lines ................ ................. ......................... ............... ...........</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. In ullam optio quia nam aliquam numquam ipsa incidunt possimus consequatur sed animi hic facere mollitia facilis libero cupiditate eaque, molestiae voluptas!</p>
<a class="button-blue" href="https://staging.unify.com/en/solutions/voice-platforms/preconfigured-unified-communications">Learn more</a>
</div>
</div>
</div>
<div class="sameblockheight grid-col-3">
<div class="vc_column-inner vc_custom_1530896983086">
<div class="wpb_wrapper">
<p>
<img class="alignnone" src=http://a1.mzstatic.com/us/r30/Purple/v4/47/1b/54/471b54ad-a6cf-f61e-2f33-11ffc6bd8215/icon100x100.jpeg>
</p>
<h5 style="text-align: center;">Title</h5>
<p class="p-height" style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui provident eum voluptas veritatis ducimus iste enim recusandae aliquid sequi ad sapiente dolore similique nihil eos placeat, consectetur odit beatae voluptatum?</p>
<a class="button-blue" href="#">Learn more</a>
</div>
</div>
</div>
</div>
There are a lot of examples for how to have a fixed width sidebar on Bootstrap 4, but I haven't found one that will cause the main content to disappear on mobile.
I've tried the following:
<div class="row no-gutters flex-nowrap">
<div class="col-md col-12 d-none d-xs-block d-sm-block ">
Main area
</div>
<div class="col-md-4 col-12 sidebar">
Sidebar
</div>
</div>
.sidebar {
max-width: 600px; min-width: 600px
}
And this mostly works, but what happens is that between 768 to 576 pixels the sidebar disappears entirely.
What I'm after is for the sidebar to be a fixed width with the main area shrinking and eventually disappearing.
With few lines of CSS you can achieve this with Flexbox. Please have a look in snippet I added with this answer.
To know more about Flexbox you can checkout those links.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://yoksel.github.io/flex-cheatsheet/
.wrapper {
display: flex;
height: 100vh;
}
.sidebar {
min-width: 150px;
max-width: 150px;
height: 100%;
background: grey;
padding: 20px;
}
.content {
padding: 20px;
height: 100%;
background: lightgrey;
}
<div class="wrapper">
<div class="sidebar">
sidebar
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores, dolores eligendi.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis modi adipisci autem illo labore ipsum numquam explicabo excepturi similique, perspiciatis doloremque, quo asperiores at veniam culpa aperiam maiores
</div>
</div>
I believe you're looking for this:
#media (min-width:768px) {
.sidebar {
max-width: 600px; min-width: 600px;
}
}
.sidebar {
background-color: #f5f5f5;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row no-gutters flex-nowrap">
<div class="col d-none d-md-block">
Main area
</div>
<div class="col sidebar">
Sidebar
</div>
</div>
I wrapped the fixed size rule in a #media query condition only applying on md and up and I revised classes applied to columns accordingly.
Since you're setting the custom width of your sidebar anyway, you don't need col-* classes on your columns.
In the top bar, How can the green and the red "li" area be made with width 3em?, I tried my css as in the code but all the 3 list items remain with equal width.
It will be displayed in a mobile app webView.
Thank you
ul {
text-align: center;
}
li {
height: 2em;
line-height: 2em;
}
.menuIconLeft {
width: 3em;
background-color: green;
}
.menuIconRight {
width: 3em;
background-color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RRR</title>
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.css"/>
<link rel="stylesheet" href="css/myStyle.css"/>
<script src="js/jquery-1.11.3.js"></script>
<script src="js/jquery.mobile-1.4.5.js"></script>
<meta name="viewport" content="width=device-width"/>
</head>
<body>
<section id="firstpage" data-role="page">
<div data-role="header" data-position="fixed">
<nav data-role="navbar">
<ul class="center">
<li class="menuIconLeft">
☰
</li>
<li>
Activity label
</li>
<li class="menuIconRight">
⋮
</li>
</ul>
</nav>
</div>
<div class="ui-content">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi, temporibus, dolore! Doloribus, at repellendus sunt consectetur modi natus suscipit magni explicabo optio sequi, assumenda delectus perferendis excepturi nisi nobis ratione.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos repellendus aliquam sint atque aliquid, tempore voluptatum recusandae et rerum, qui quasi ex at aspernatur. Temporibus voluptatum exercitationem sit modi assumenda!Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam voluptatum illum maxime hic ipsa odio eaque cum. Optio cumque sequi recusandae. Nihil voluptatibus soluta ad saepe, quia optio laudantium molestiae.contents of this activity Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores nulla facere soluta tempore nihil, voluptatibus nostrum sequi, voluptate, incidunt distinctio reiciendis qui at totam alias. Culpa fuga rem vitae nesciunt?
</p>
</div>
<div data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul class="center">
<li>
NO
</li>
<li>
EXTRA
</li>
<li>
YES
</li>
</ul>
</nav>
</div>
</section>
</body>
</html>
To adhere to the result you where looking for you needed to:
Set your list items display attribute to display: inline-block.
Set your unordered list to list-style-type: none so the list item bullets do not show.
Set your left and right list elements to float: left and float: right respectively, this helps a lot because your left and right list elements will be center aligned (due to your ul { text-align: center }), so they will not flush left and right unless you tell them to.
I added a new class menuIconCenter to the middle list element. This applies a width of width: calc(100% - 6em);, since the left and right list elements are each 3em in width, then substracting both these widths by 100% will yield the remaining width of your center list element.
"How can the green and the red "li" area be made with width 3em?"
Added a header and footer class, to help differentiate how the footer and header sections work. This is an important architectural change, can you tell why?
Added <b> to bold the text in the footer.
Suggestion: if you want to make these list elements clickable or work like buttons do the following (this is in pseudocode!):
<li>
Something here
</li>
li > a {
display: block;
width: 100%;
}
Any questions please ask in the comments below :-)
ul {
text-align: center;
min-width: 320px;
}
li {
height: 2em;
line-height: 2em;
display: inline-block;
margin: 0;
}
.menuIconLeft {
float: right;
width: 3em;
}
.menuIconCenter {
width: calc(100% - 6em);
}
.menuIconRight {
float: left;
width: 3em;
}
.center {
list-style-type: none;
padding: 0;
margin: 0;
}
.header .menuIconLeft {
background-color: green;
}
.header .menuIconRight {
background-color: red;
}
.header .center {
border: 1px solid lightgray;
}
.footer .center {
background-color: lightgray;
}
<section id="firstpage" data-role="page">
<div class="header" data-role="header" data-position="fixed">
<nav data-role="navbar">
<ul class="center">
<li class="menuIconLeft">
☰
</li>
<li class="menuIconCenter">
Activity label
</li>
<li class="menuIconRight">
⋮
</li>
</ul>
</nav>
</div>
<div class="ui-content">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi, temporibus, dolore! Doloribus, at repellendus sunt consectetur modi natus suscipit magni explicabo optio sequi, assumenda delectus perferendis excepturi nisi nobis ratione.Lorem ipsum
dolor sit amet, consectetur adipisicing elit. Eos repellendus aliquam sint atque aliquid, tempore voluptatum recusandae et rerum, qui quasi ex at aspernatur. Temporibus voluptatum exercitationem sit modi assumenda!Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Laboriosam voluptatum illum maxime hic ipsa odio eaque cum. Optio cumque sequi recusandae. Nihil voluptatibus soluta ad saepe, quia optio laudantium molestiae.contents of this activity Lorem ipsum dolor sit amet, consectetur adipisicing
elit. Asperiores nulla facere soluta tempore nihil, voluptatibus nostrum sequi, voluptate, incidunt distinctio reiciendis qui at totam alias. Culpa fuga rem vitae nesciunt?
</p>
</div>
<div class="footer" data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul class="center">
<li class="menuIconLeft">
<b>NO</b>
</li>
<li class="menuIconCenter">
<b>EXTRA</b>
</li>
<li class="menuIconRight">
<b>YES</b>
</li>
</ul>
</nav>
</div>
</section>