Full width element exceeding parent's width - but with a max-width - html

I using this setup to make hero elements exceed to full page width:
Html:
main {
max-width: 600px;
margin: 0 auto;
}
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
<main>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempor...</p>
<figure class="full-width">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/hero.jpg" alt="">
<figcaption>Some text.</figcaption>
</figure>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempor...</p>
</main>
But I would like to set a max-width, so if the screen is more than, say, 2000px, then stop making the "full-width" element full width, but instead just 2000px wide and centered (and still exceeding the parent element's width). How can I achieve this?
I tried with:
#media (min-width: 2000px) {
.full-width {
max-width: 2000px;
}
}
but it just pushed the element to one side.
JsFiddle here.

This happnes because of margines. You can just use,
.full-width{
width: 100%,
margin: 0px
}
And also use
Padding : 0px
In parent if needed.

You could use display: flex property in order to handle the alignment:
main {
max-width: 600px;
margin: 0 auto;
display: flex;
flex-direction: column;
align-items: center;
}
.full-width {
width: 100vw;
position: relative;
}
#media (min-width: 2000px) {
.full-width {
max-width: 2000px;
}
}
img {
width: 100%;
}

Related

Image crops upon resizing the browser

I created a simple slideshow, but upon resizing the browser. Images get cropped. I tried all different ways, but couldn't make it.
Here is a sample of html code:
<div class="carousel">
<i class="fas fa-chevron-left" id="prevBtn"></i>
<i class="fas fa-chevron-right" id="nextBtn"></i>
<div class="carousel-inner">
<div class="slide-item">
<div class="caption">
<h1>First Slide</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit.</p>
</div>
<img src="https://www.w3schools.com/bootstrap4/ny.jpg" width="100%" alt="">
</div>
</div>
...
</div>
here is the css code:
.carousel {
position: relative;
width: 992px;
height: 400px;
margin: 0 auto;
padding: 0;
overflow: hidden;
.carousel-inner {
display: flex;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0px auto;
.slide-item {
position: relative;
display: inline-block;
flex-direction: column;
justify-content: center;
text-align: center;
align-items: center;
img {
width: 992px;
// height: 400px;
}
...
#media (max-width: 576px) {
.container,
.carousel,
.carousel-inner,
.slide-item {
max-width: 540px;
}
}
#media (min-width: 576px) {
.container,
.carousel,
.carousel-inner,
.slide-item {
max-width: 540px;
}
}
The slideshow looks fine in bigger screens but as we shrink down the size of browser images get cropped. Here is a codepen. I hope someone can solve it here, Thank you.
Try max-width: 100% in mobile
#media (max-width: 576px) {
.container,
.carousel,
.carousel-inner,
.slide-item {
max-width: 100%;
}
DEMO HERE

Div position of "button" depends on content height

I'm working on the sidebar where we have a logo at the top and some bottom div. The middle div "content" has overflow: scroll and contains paragraph(s). So what I need... If I have only one paragraph (or two p) the button div should be positioned absolutely at the bottom of the content and if I have more paragraphs which have a bigger height than "content" div so then the button div will have position static (so will be scrollable).
And I need it only by CSS. Is it possible?
We need IE11+ support.
<div class="sidebar">
<div class="logo">logo</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam tempor egestas ornare. Suspendisse potenti. Integer non euismod nulla. Quisque pretium est sit amet congue rhoncus.</p>
<div class="button">
Button
</div>
</div>
<div class="bottom"></div>
</div>
.sidebar {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 300px;
background-color: grey;
}
.logo {
position: absolute;
width: 100%;
height: 55px;
background-color: red;
}
.bottom {
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background-color: green;
}
.content {
position: absolute;
top: 55px;
bottom: 100px;
overflow-y: scroll;
}
.button {
display: inline-block;
padding: 1em 0 1em;
text-align: center;
width: 100%;
border-radius: 50px;
background-color: white;
}
You can use flexbox. Add this to your CSS:
.content {
display:flex;
flex-wrap: wrap;
}
.button {
align-self: flex-end;
}
That will render the button always at the end of the content div.

How to make text in responsive circle <div> responsive as well

I have dealt with this problem for some days now and it's making me crazy, I want the text inside the circle to move in the same position inside the cirkle div when I make the screen smaller, as illustrated in the picture.
If you have any tips please share!
CSS Code and Html Code:
.circleBase {
border-radius: 50%;
}
.contact-circle {
margin-top: 29%;
margin-left: 4%;
position: fixed;
width: 23%;
height: auto;
padding-top: 23%;
background-color: rgba(255, 86, 86, 0.2);
}
#contact-text {
top: 20%;
bottom: 20%;
left: 18%;
font-size: auto;
position: absolute;
text-align: center;
width: 60%;
opacity: 1;
}
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
</p>
</div>
</div>
Use another method to center the text. Here is an idea with flex:
.circleBase {
border-radius: 50%;
}
.contact-circle {
position: fixed;
width: 23%;
height: auto;
padding-top: 23%;
background-color: rgba(255, 86, 86, 0.2);
}
#contact-text {
top: 0;
position: absolute;
bottom: 0;
left: 10%;
right: 10%;
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center
}
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
</p>
</div>
</div>
Responsive web site - #media (min-width:450px) and (max-width:900px) { css style }
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</div>
</div>
Css #media Example
.circleBase {
height:800px;
width:800px;
}
#media (max-width:479px) {
.circleBase {
height: 400px;
width:400px;
}
}

Setting a div to be the same height as an image

Essentially this is what I'm getting...
While this is what I want.
I have the image height and width set up like this...
#content img{
padding: 3%;
width: 60%;
height: 50%;
float: left;
}
With %s as I want it to be responsive and all. So the exact height of the image in px I can't really tell.
When I try to set up the same dimensions for the gray box, it only fills up with what is in it as you can see.
#text{
padding: 3%;
margin-right: 3%;
margin-top: 3%;
width: 37%;
height: 50%;
float: left;
background-color: #333333;
color: #FFFFFF;
}
Anyway on how to go about this? I'm also starting to think the problem may be I'm trying to make it responsive incorrectly.
Thanks in advance.
EDIT: Here is the HTML
<div id="content">
<img src="projectphotos/1.jpg">
<span class="arrows" style="float: right;"><i class="fa fa-angle-`double-right fa-3x"></i></span>`
<div id="text">
Test
</div>
</div>
You can use Flexbox
body, html {margin: 0; padding: 0}
.content {
display: flex;
}
.text {
background: #333333;
color: white;
flex: 1;
margin: 10px;
}
.image {
flex: 2;
margin: 10px;
}
img {
width: 100%;
vertical-align: top;
}
<div class="content">
<div class="image">
<img src="http://placehold.it/900x450">
</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil, id.</div>
</div>
just add display: flex to #content and remove the float: left from both.

Flexbox Item in Chrome have wrong height if vertical scrollbar is visible

It seems that Google Chrome does not take into account vertical scrollbars of an Flex item first time Flexbox container is rendered.
This is how it look like after page just loaded:
This is how it looks like after changing width of a container a little.
IE10, IE11 and FF does take into account the scrollbars.
Here is the codepen.
HTML:
<div class="subj">
<div>
Lorem ipsum dolor sit amet, ...
</div>
<div>
Lorem ipsuxm dolor sit amet, ...
</div>
<div>
Lorem ipsum dolor sit amet, ...
Lorem ipsum dolor sit amet, ...
</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.subj {
width: 400px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.subj > :nth-child(1) {
background: #f88;
flex: 0 0 auto;
}
.subj > :nth-child(2) {
background: #8f8;
flex: 0 0 auto;
overflow: auto;
white-space: nowrap;
position: relative;
border: 5px solid #f8f;
}
.subj > :nth-child(3) {
background: #88f;
flex: 1 1 auto;
overflow: auto;
}
Is there a way to tell Chrome to respect scrollbars?
I don't know what is casing this issue unfortunately.
But a simple fix is setting the correct height.
On the subj css rule
.subj > :nth-child(2)
add:
overflow:scroll;