While developing new website for our client (he delivered design and insisted on using flexbox), we've come to element that looks like this (the "Samochody Peugeot" section with 2 little boxes at right):
Grid starts at text in left box, and ends at end of image in right boxes. The only real solution that we can find is to create the gray background using absolute positioned :before pseudo-element, but it seems pretty hacky.
At bigger widths the gray bg should expand to left, but everything else should stay in grid.
Is there any better way to achieve this kind of layout than using :before?
<section class="boxes">
<div class="container">
<div class="boxes__box">
<h3>Samochody<br/>PEUGEOT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua.</p>
<a class="btn" href="">Przejdź do strony</a>
</div>
<div class="boxes__box-holder">
<div class="boxes__box boxes__box--small">
<h3>PONAD 20 LAT<br/>DOŚWIADCZENIA</h3>
<a class="btn" href="">O firmie</a>
</div>
<div class="boxes__box boxes__box--small">
<h3>POZNAJ NASZE<br/>USŁUGI</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<a class="btn" href="">Przejdź do strony</a>
</div>
</div>
</div>
</section>
.boxes {
.container {
display: flex;
}
&__box {
width: 68%;
background: orange;
position: relative;
&:first-child:before {
content: '';
height: 100%;
width: 100vw;
background: red;
position: absolute;
right: 100%;
z-index: -1;
top: 0;
}
}
&__box-holder {
width: 32%;
}
}
Related
I'm learning React by starting to build a simple webpage (I know, overkill.) but I ran across a weird issue.
So I have three "bubbles" on my homepage each containing an icon, title, and text. I am using flex in their parent container to align them as a row but when I do this I can only select the title and text of the last "bubble".
If I choose flex-direction: column; (or if I don't set a direction) I am able to select the text of all three bubbles. If I choose: flex-direction: row; and flex-wrap: wrap; and then make the window smaller so one of the bubbles goes to the next line, I am able to select the text from 1/2 of the bubbles on line one and the text from the bubble on line two.
Also the :hover is no longer working in that last section of CSS code.
Been at this problem for a couple of days and it makes no sense to me. Thanks in advance for the help. See code below.
.home-services {
padding: 50px;
background-color: bisque;
transform: skewY(-3deg) translateY(-55px);
z-index: -1;
}
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
user-select: all;
z-index: -1;
}
.home-services-bubble {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
margin: 10px;
padding: 10px 30px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 2px 3px #ddd;
width: 29%;
}
.bubble-icon {
display: flex;
justify-content: center;
align-items: center;
background-color: #f64a01;
height: 100px;
width: 100px;
font-size: 3vw;
text-align: center;
border-radius: 100px;
color: #ffffff;
}
.home-services-bubble:hover .bubble-icon {
transform: translateY(-5px);
background-color: black;
box-shadow: 2px 3px #ddd;
transition: 0.5s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" rel="stylesheet"/>
<div class="home-services">
<div class="home-bubbles">
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-search fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-wind fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-sign fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
</div>
The user-select property with the value all selects the whole text on a simple click. Just remove it like this:
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
z-index: -1;
}
This question already has answers here:
Understanding CSS selector priority / specificity
(4 answers)
Closed 3 years ago.
I have 6 col-lg-3 in my container. Each div including another div, h4 and p.
Included divs have background-image, and some properties in CSS.
And I want to change included div background-image on hovering col-lg-3 div
But it just ignore :hover and nothing happening.
Ive tried not only change background-images, but change color, add borders, etc. But no response. Heres one of div.col-lg-3...
.reasons .col-lg-3 div {
width: 99px;
height: 99px;
margin: 10px auto 5px auto;
background-size: 99px 99px;
background-repeat: no-repeat;
transition: 0.5s ease;
}
.community:hover div {
background-image: url('img/communityReverse.png');
}
<div class="col-lg-3 community">
<div style="background-image: url('img/community.png')"></div>
<h4>Lorem ipsum dolor</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
.community:hover div{ ... } seems not working, but for example .community:hover h4{ font-size: 30px; } ok, no problem. I cant see what is wrong
You had an issue on your CSS, because you were trying to nest the div inside a class that wasn't declared before (.reasons). Aside from that, you should declare the .community class inside the nested div, so the image will be separated on the code (better view and easier to deal with), then, just make the :hover event apply to the class, so whenever the mouse enters the area, it'll trigger the event and change the background.
Here goes a Snippet for better view of the code and how it works :
.community div {
width: 100%;
height: 99px;
margin: 10px auto 5px auto;
background-image: url("http://www.f-covers.com/cover/cute-baby-kitten-facebook-cover-timeline-banner-for-fb.jpg");
background-repeat: no-repeat;
background-size: contain;
transition: all 0.5s ease;
}
.community:hover div {
background-image: url("https://www.freewebheaders.com/wordpress/wp-content/gallery/cats/lovely-american-shorthair-kitten-website-header.jpg");
}
<div class="col-lg-3 community">
<div></div>
<h4>Lorem ipsum dolor</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
By the way, you don't have to specify a nested class when just wanting to work with general styles, as .community is nested as sibling with .col-lg-3, you can use either to change inner styles as I did in the Snippet above.
you check this code you are working with wrong code
.community div:hover
{
background-image: url('img/communityReverse.png');
}
you need to use !important in your code otherwise you have done well
.reasons .col-lg-3 div {
width: 99px;
height: 99px;
margin: 10px auto 5px auto;
background-size: 99px 99px;
background-repeat: no-repeat;
transition: 0.5s ease;
}
.community:hover div {
background-image: url('img/communityReverse.png') !important;
}
<div class="col-lg-3 community">
<div style="background-image: url('img/community.png')"></div>
<h4>Lorem ipsum dolor</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
Have you tried !important ?
.community:hover div {
background-image: url('img/communityReverse.png')!important;
}
I might just be really tired but I can't for the life of me figure out why display: inline-block isn't working to make the parent's width adjust to the size of it's contents. I've tried searching for other solutions but every resource I've found says adding inline-block to the parent should do the trick.
In the example below, I am trying to make the blue square only extend to the edge of the green square, and then ultimately center the contents via margin: 0 auto;:
#intro {
height: 400px;
background-color: red;
}
.slide-txt {
display: inline-block;
width: 30%;
background-color: lime;
}
.slide-box {
display: inline-block;
margin: 0 auto;
background-color: blue;
}
<section id="intro" class="image-slider">
<div class="container" id="intro-slide">
<div class="slide-box">
<img src="http://www.jkoffset.com/assets/images/Packaging1.jpg" alt="same-box-slide" width="150px">
<div class="slide-txt">
<h1 class="title">Headline <span>Goes Here</span></h1>
<div class="caption"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a class="btn" href="#">
Learn More
</a>
</div>
</div>
</div>
</div>
</section>
https://jsfiddle.net/eam0mk47/
Using width:30%; in the div child (.slide-txt) will make the parent div expand to fill the other 70%, so to avoid that and make it adjust according to content you need to use px instead of % in the div child.
In that red #intro is a div with the class .container ... this element has padding left and right via bootstrap.
Just remove that padding:
https://jsfiddle.net/eam0mk47/1/
#intro .container {
padding: 0px;
}
Or don't use that class there.
I have a simple page where the all the content (<h1>, <h2>, <p>, etc.) is contained within a <div>, in order to have the same width.
I like the way the body text looks and want to keep it that way, but I'd like to add a background image to the heading. It should start from the very top of the page (and window, in my case) and end at the baseline of the last line of the heading itself, while also extending in width from the left side of the window to its right. In the following image I illustrated the desired layout. Below it, I've drawn the html hierarchy that I've attempted.
In fact, I've already tried creating a child of <h1> with
width: 100vw;
position: relative;
left: 50%;
transform: translate(-50%);
but:
Since the page has z-index: -1;, for some weird bug I can't click on links with relative positioning
I'd prefer not to use vw unites because of browser support.
I still can't manage to extend the background to the top.
The font size of <h1> and its margins are defined in pixels, as you see, but the page still behaves dynamically because as I resize the window, the number of lines of <h1> increases.
HTML
<div class="page">
<h1>Heading</h1>
<h2>Section 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
CSS
body {
height: 100%;
width: 100%;
margin:0px;
}
.page {
font-size: 20px;
width: 90%;
max-width: 70ch;
padding: 50px 5%;
margin: auto;
z-index: -1;
}
h1 {
font-size: 30px;
margin-top: 0;
margin-bottom: 10px;
}
h2 {
font-size: 22px;
margin-bottom: 26px;
}
p {margin-bottom: 24px;}
JS Fiddle
Two suggestions:
Separate the h1 and the rest of the body in two different divs. Apply the background to the first div.
<div class="background-here">
<div class="page">
<h1>Heading</h1>
</div>
</div>
<div class="page">
<h2>Section 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
Or you could just apply the background to the body and use background-repeat: repeat-x or bakcground-size: cover. But it depends on how the image was designed.
I want the byline to appear just below the image.
I am trying to use the right, left, etc properties in relation to the relative property, but the span moves left of the image.
What is the mistake in my code?
<section id="manchanabele">
<img id="club" alt="club" src="images/club.jpg">
<p id="lorem">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. nisi ut aliquip ex ea commodo consequat.
<span id="byline">by: Lorem Ipsum</span>
</p>
</section>
section#manchanabele {
background: #C8C8C8;
}
#club {
float: right;
width: 75px;
height: 75px;
}
p#lorem {
background: #A0A0A0;
}
span#byline {
position: relative;
float: right;
}
You are structuring your DOM in a wrong way, you should wrap the elements you want to float in a single container. I will provide you the code which will result you in something like below
Here, in the code below, I will explain you related to the image above, the black border container is .wrap, the one which is having green border is the paragraph, which is p, the red on is the container which you are floating to the right which is .right_float and the nested elements inside red element is your img and span respectively.
For example
<div class="wrap">
<p>Hello</p>
<div class="right_float">
<img src="#" />
<span>Hello</span>
</div>
</div>
.wrap {
overflow: hidden; /* Clears float */
}
.wrap p {
float: left;
width: /*Some fixed width*/
}
.wrap .right_float {
float: right;
width: /* Some fixed width */
}
.wrap .right_float span {
display: block;
}
Note, if you don't care about the older versions, especially IE, I would recommend you to use a self clearing parent class
.clear:after {
clear: both;
display: table;
content: "";
}
Now, you can call the above class on your parent element holding floated elements, and you don't have to use overflow: hidden;
You could keep the byline aligned with the image by wrapping the elements in a container such as a DIV.
HTML:
<section id="manchanabele">
<div id="align">
<img id="club" alt="club" src="images/club.jpg">
<span id="byline">by: Lorem Ipsum</span>
</div>
<p id="lorem">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. nisi ut aliquip ex ea commodo consequat.
</p>
</section>
CSS:
section#manchanabele {
background: #C8C8C8;
}
#align {
float:right;
width:75px;
}
#club {
width: 75px;
height: 75px;
}
p#lorem {
background: #A0A0A0;
}
N.B. You may want to consider using classes rather the IDs if you need to use this layout several times for similar content.
Use this markup:
<article>
<div class="clearfix">
<img src="http://lorempixel.com/70/70" alt="a random image" class="thumb" >
<p>The quick brown fox jumps over all the messy markup and writes a new one.</p>
</div>
<footer>By The Fox</footer>
</article>
Fiddle: http://jsfiddle.net/C5GkH/1/
or if you need the image and the byline always one below the other keeping a blank sidebar on the right follow the advice of #Mr. Alien
Try to clear:both; after the image.
Like so
<section id="manchanabele">
<img id="club" alt="club" src="images/club.jpg">
<div style="clear:both;></div>
<p id="lorem">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. nisi ut aliquip ex ea commodo consequat.
<span id="byline">by: Lorem Ipsum</span>
</p>
</section>
Also avoid floating inline elements. Better if you wrapped that image with a div and then floated the div.