CSS to hide element in order to prevent wrapping - css

Ok, I'm aware of media queries but they are strictly related to a certain width. Sometimes it's not convenient. Say I have bootstrap navbar with logo image and h1 in one line, like here
<nav class="navbar">
<a class="navbar-brand">LOGO</a>
<h1 class="d-inline">Long enough header</h1>
</nav>
https://jsfiddle.net/zzmaster/qno7utp0/2/
On a certain screen width it wraps into two lines. I'd prefer to hide the logo and make this process independent of the width of the second element. Ideally I think of a class of hiding priority like this
<div class="container">
<div class="prio-1">one</div>
<div class="prio-2">two</div>
<div class="prio-3">three</div>
</div>
meaning preventing line wrap by hiding less priority-objects. Is it possible?

I believe this is the solution. So as per this css
If width is more than 500px all the three prio-3, prio-2, prio-1 will be visible.
If width is between 200px and 500px both prio-2, prio-1 will be visible.
If width is less than 200px only prio-1 will be visible.
#media screen and (max-width: 500px) {
prio-3 {
display: none;
}
}
#media screen and (max-width: 200px) {
prio-2 {
display: none;
}
prio-3 {
display: none;
}
}

Related

Make WooCommerce Product Images smaller into mobile view?

I work on small project , and need to make product images smaller when is seen from mobile view. Currently images are too big, and spacing between each other (i have two products in line) is too small, so want to make separated so the client can get a better overview of the products.
image from smartphone
i tryed to play with image CSS, like this:
#media only screen and (max-width: 600px) {
.woocommerce ul.products li.product a img {
height:265px; //to make image smaller so can get more spacing between.
}
}
but that seems to make images smaller, but also cut it off, so its not ok. Can someone to help me, how to make images smaller, but image do not crop? Example from site here.
A rule of thumb is to let the browser render as much as possible on its own, to stay responsive and keep the performance up. The more you do yourself, the less well suited your site will be.
Using flex boxes make this really handy:
#media only screen and (max-width: 500px) {
.item {
max-width: 150px;
}
}
.item {
max-width: 200px;
}
#container {
display: flex;
flex-wrap: wrap;
}
img {
width: 100%;
}
<div id="container">
<div class="item">
<img src="https://reinigungsmittel-grass.de/wp-content/uploads/2018/06/Carwash-foam_20-500x597.png">
</div>
<div class="item">
<img src="https://reinigungsmittel-grass.de/wp-content/uploads/2018/06/Carwash-foam_20-500x597.png">
</div>
<div class="item">
<img src="https://reinigungsmittel-grass.de/wp-content/uploads/2018/06/Carwash-foam_20-500x597.png">
</div>
<div class="item">
<img src="https://reinigungsmittel-grass.de/wp-content/uploads/2018/06/Carwash-foam_20-500x597.png">
</div>
<div class="item">
<img src="https://reinigungsmittel-grass.de/wp-content/uploads/2018/06/Carwash-foam_20-500x597.png">
</div>
</div>
Note: As you have a resolution bigger then 500px all such boxes will be at maximum 200 pixels wide, if it is smaller they shrink to 150px. Everything in that box will resize and by setting the image width to 100% it does also resize according to its parent box. That way you won't have to mess around with all those values across your css and html.
Of cause you can replace the pixel values by percentages as you did on your side, resulting in the style you wanted to have.
Here is a nice summary on flex boxes and what you can do with them: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Most phone devices are 425px or less in width. Because your images are size hard-coded, I'm going to provide a hard-coded solution aswell
#media only screen and (max-width: 425px) {
.woocommerce ul.products li.product a img {
height: 200px;
width: 70%;
margin: 0 auto;
}
}
You can tweak the values as you want.
You need to adjust both height and width accordingly to not cut the images off.

How to make 3 to 2 column responsive design with variable heights?

Making 3 column responsive design using media queries is simple, but in case I want the middle column to stay in mid with 100% height and the right column goes on the left column it gets tricky.
The problem emerge because mid column height is variable, therefore it will be impossible to give negative margin-top to the transformed right column.
here is css code example:
/* 3 columns css */
.colLeft, .colRight, .colMid{
width: 280px;
float: left;
}
.colMid{
width: 500px;
}
.colRight{
width: 240px;
}
.container{
width: 1020px;
margin: 0 auto;
}
/* Media queries */
#media screen and (max-width: 1020px) {
.container {
width: 780px!important;
}
.rightCol{
width: 280px;
}
}
Html:
<div class="container">
<div class="leftCol">
</div>
<div class="midCol">
</div>
<div class="rightCol">
</div>
</div>
this code works fine, But mid column height push the transformed right column down.
My question: Is there HTML/CSS solution for this issue? or do I have to change HTML rendering when screen re-size?
Thanks,
Looks like your float: left is being applied to your .colRight class. This could be what is causing your right column to display on your left column.
I found the solution, using only CSS/HTML. Here is the explanation:
I created a duplicate rightCol div and placed it inside leftCol div, and named it righCol-left.
Initially the rightCol-left is set to "display:none"
when media screen is lower than 1020px, hide rightCol (display:none), and display rightCol-left (display:block)
here is the CSS:
.rightCol-left{display:none;} /*duplicate div*/
#media screen and (max-width: 1020px) {
.container {
width:780px!important;
}
.rightCol{
display:none;
}
.rightCol-left{
display:block;
width:280px;
}
}
here is the HTML:
<div class="leftCol">
/*Left column content*/
<div class="rightCol-left"> /* will be displayed when screen is below 1020px */
</div>
</div>
<div class="midCol">
/* mid column content */
</div>
<div class="rightCol"> /* gets hidden when screen is below 1020px */
</div>
This works perfect, the only bad thing would be the repeated HTML code. But this is not noticeable and very minor, after all, HTML code produce far less load to the webpage compared to JavaScript or anything else.

target border style inside css

okay...
I would like to know if it's possible to target a border style that's inside a class.
I would like to do this so that when the browser window gets resized the border gets hidden or display:none.
sample of my code:
<div id="chuck" class="descr-text col-lg-6 col-md-6 col-sm-4">
some content goes here
</div>
And my css
.descr-text {
display:none;}
#media screen and (max-width: 991px){
border-right.img_beef{
display:none;
}
}
I know I could probably just wrap it in another div and then then target it when the window gets to that size, But I was wondering if there isn't a more clean simpler way to do that.
It's kind of hard to decipher exactly what you want since your class names don't match up to your markup. But if you want the border to be hidden when it reaches a certain breakpoint:
.chuck {
border: 2px solid #BADA55;
}
#media screen and (max-width: 991px) {
border: 0;
}

How do I make the background color responsive on mobile devices?

I have created a website using bootstrap and the responsive features works fine, except for the background color of the div. The elements (images) are stacked but the background color remains only behind the first image in the row. I am looking for a way to extend the background-color on mobile devices.
HTML:
<div id="omos">
<div class="row">
<div class="col-md-6 col-xs-12">
<h2>Kristoffer Andreasen</h2>
<img style="height:280px; width:420px;" src="http://i.imgur.com/874qJmM.png" class="img-responsive">
<div class="Krille">
<p>Indhold</p>
<p>Marketing</p>
<p>Webdesign</p>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="Kalli">
<h2>Kasper Hjortsballe</h2>
<img style="height:200px; width:200px;" src="http://i.imgur.com/kTleong.png" class="img-responsive">
<p>Programmør</p>
<p>Layout</p>
<p>Grafik</p>
</div>
</div>
</div>
</div>
CSS:
#omos {
background-color: #f7f7f7;
height: 80vh;
clear: both;
text-align: center;
}
I have tried several options but no one seems to solve the problem. Does anyone know what to do?
Remove the height property of the div, and it should work.
Bootstrap uses media queries to show things differently on differnet sized screens. If you're saying your CSS works on desktop but not on mobile, it would be because you're not using media queries.
/* Custom, iPhone Retina */
#media only screen and (min-width : 320px) {
}
/* Extra Small Devices, Phones */
#media only screen and (min-width : 480px) {
}
/* Small Devices, Tablets */
#media only screen and (min-width : 768px) {
/* your mobile css, change this as you please */
#omos {
background-color: #f7f7f7;
height: 80vh;
clear: both;
text-align: center;
}
}
/* Medium Devices, Desktops */
#media only screen and (min-width : 992px) {
}
/* Large Devices, Wide Screens */
#media only screen and (min-width : 1200px) {
/* your desktop css */
#omos {
background-color: #f7f7f7;
height: 80vh;
clear: both;
text-align: center;
}
}
let's think about what your style sheet does,
height: 80vh;
that makes us do something that is 80% of the viewports height, so if our div stacks outside of that when switching to 12 col it is not going to get the color, as your color is not based on the div, but is based relative to the viewport, twitters media queries however will change your child elements and override this wrapping divs height, so you get stuck, I'd see if min-height will work, or remove height all together if possible(not sure what you're vision is exactly)
Set the height property to auto, it will work fine.
height: auto

override bootstrap container width

I have an easy HTML template using bootstrap 3. Template has following structure: static header, static footer and content which is in the bootstrap's class "Container". In the middle of content I have bootstrap'w "Well" and i want it make looks like header and footer. I mean I want it to be the full width of the screen on any screen.
I created easy fiddle.
Here's a question, is there any way to override container's width inside this container?
<header>
<div class="container">
<div class="content">
</div>
<div class="well">
</div>
<div class="content">
</div>
</div>
<footer>
Here theres a simpler trick that works like a charm: https://css-tricks.com/full-width-containers-limited-width-parents/
Look for: "No calc() needed"
HTML
<header>
<div class="container">
<div class="content"></div>
<div class="well full-width"></div>
<div class="content"></div>
</div>
<footer>
CSS
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
The div container has the following max-width specified in media query as default by bootstrap.
#media (min-width: 768px){
.container{
max-width:750px;
}
}
#media (min-width: 992px){
.container{
max-width:970px;
}
}
To override this add the below style in your stylesheet
// This should be added in default styles, not within media query
.container{
margin:0;
padding:0;
}
#media (min-width: 768px){
.container{
max-width:100%;
}
}
#media (min-width: 992px){
.container{
max-width:100%;
}
}
ORIGINAL + BEST PRACTICE: always move the .well outside of .container to stay idiomatic with Bootstrap.
UPDATE + IF ABOVE IS NOT AN OPTION: Given that you cannot easily modify .container styles and/or move the .well outside of .container, your best bet is JavaScript. Here I have made a script that makes .well expand as the width of the window changes.
Here is a jsFiddle
The idea is that you want a negative value for margin-left and margin-right so that .well expands across the screen.

Resources