I'm trying to create a banner that has two buttons on it:
.banner {
width: 100%;
display: flex;
flex-direction: column;
margin-top: -4%;
}
.banner img {
width: 100%;
/*image is 1232x317 by default and defines the size of the banner*/
}
.banner-buttons {
display: flex;
flex-direction: row;
margin-left: 6.2%;
position: absolute;
top: 10%;
}
.banner button {
display: flex;
font-size: 200%;
border: none;
border-radius: 5px;
font-weight: bold;
align-items: center;
padding: 5px 15px;
}
<div class="banner">
<img src="https://picsum.photos/1200/300">
<div class="banner-buttons">
<button>Assistir</button>
<button>Mais Informações</button>
</div>
</div>
but the problem is, the height of the buttons change based on the viewport, destroying the banner, how can I position it without ruining it?
I would personally avoid absolute positioning and use background image to create the layers.
You can set a min height on your banner if you desire.
I would also use em and media queries to reduce the font size when the screen resolution is smaller.
.banner {
background:url(https://picsum.photos/1200/300);
padding:10px;
}
.banner-buttons {
display: flex;
justify-content:center;
align-items: center;
}
.banner button {
font-size: 2em;
border: none;
border-radius: 5px;
font-weight: bold;
padding: 5px 15px;
margin:5px;
}
<div class="banner">
<div class="banner-buttons">
<button>Assistir</button>
<button>Mais Informações</button>
</div>
</div>
Actually what solved for me was adding position: relative to .banner, now the buttons are displayed at the exact same position at every screen size.
Related
Need to center this text in this way:
Basically, the top part to the left and the bottom part to the right, but with a bit of overlap.
How can I do that in HTML/CSS?
You can center the text vertically by using the centering with transform technique. Then the text should be separated into two lines and aligned to left/right plus a small negative margin so it overflows outside of the circle.
div {
height: 130px;
width: 130px;
background: lightblue;
position: relative;
border-radius: 50%;
}
p {
position: absolute;
top: 50%;
transform: translateY(-50%);
margin: 0;
width: 100%;
}
span {
display: block;
}
span:first-of-type {
text-align: left;
margin-left: -7px;
}
span:last-of-type {
text-align: right;
margin-right: -7px;
}
<div>
<p>
<span>La crèativitè</span>
<span>est contagieuse</span>
</p>
</div>
Simply use 2 elements for those 2 lines and add a margin-left to the second element:
.logo p {
margin: 0;
}
.logo p:nth-of-type(2) {
margin-left: 3.5em;
}
/* for demonstration purpose only */
html {
font-size: 40px;
font-family: Arial;
}
<div class="logo">
<p>La crèativitè</p>
<p>est contagieuse</p>
</div>
Another entirely different (and more complicated) approach is to use flex-box. It requires you to use containers and to know the principles of flex-box. But once you know what you're doing, it becomes fairly simple to center things inside of other things.
If you need somewhere to practice flex-box with simple games, you can visit https://flexboxfroggy.com/.
.container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: gray;
}
.logo {
width: 200px;
height: 200px;
background-color: maroon;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
p {
font-size: 20px;
}
#p1 {
align-self: flex-start;
}
#p2 {
align-self: flex-end;
}
<div class="container">
<div class="logo">
<p id="p1">La crèativitè</p>
<p id="p2"> est contagieuse</p>
</div>
</div>
Bonne Chance!
I am trying to make a div level with the bottom of a portion of a picture where the full picture extends past where I need it to be.
Example of what I am talking about. I have tried absolute positioning, but I am afraid of responsiveness once I do the mobile and widescreen versions. It also didn't work when I tried it. I tried changing the heights of the divs, but I am not sure if it is truly level. This is my first project, and any help would be greatly appreciated!
Here is the HTML:
<div class="type-and-hand-lettering">
<div class="type-and-hand-lettering-container">
<div class="three">03</div>
<div class="three-content">
<h3>type and hand-lettering</h3>
<p>
I can help you make your type flow nice and look flawless.
</p>
</div>
</div>
<img
src="/assets/type-and-hand-lettering.png"
alt="type and hand lettering"
/>
</div>
Here is the SCSS:
.type-and-hand-lettering {
display: grid;
grid-template-columns: 1fr 1.5fr;
// grid-gap: 1rem;
align-items: center;
margin-top: 100px;
margin-right: 5rem;
margin-left: 5rem;
margin-bottom: 150px;
&-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
height: 100%;
.three {
color: $primary-color;
font-size: 15px;
font-family: $lust;
width: 100%;
&-content {
width: 100%;
h3 {
color: #02281b;
font-size: 40px;
font-family: $lust;
}
p {
color: #02281b;
font-size: 15px;
font-family: $roboto;
}
}
}
}
}
img {
width: 100%;
}
If you want to avoid absolute positioning , you can use the
transform: translateY(-amountOfRemsYouWannaMoveTheElementUp);
So, I want this picture in the middle of the screen. slightly above the middle of the page. it works for other screen sizes but for this size 1024px it only stays at the top of the screen unless I use bottom: (some px height); but all of my other pages don't need it. I was wondering if anyone knew a way to move this to the middle of the screen but slightly higher than the exact middle of the screen without for example bottom: 140px. if not that fine also can someone show me how to optimize this I know my code is sloppy and can use some work and can be better equipped to handle different sizes of pages. 1024 or 2000px for example. Thank you
#media only screen and (max-device-width: 1024px){
#logo {
position: relative;
bottom: 700px;
}
#logo img{
position: relative;
width: 9%;
height: auto;
bottom: -20px;
}
#header_size{
width: 70%;
height: auto;
margin-left: auto;
margin-right: auto;
}
#border{
border-radius: 30px;
border: 10px;
border-color: black;
border-style: double;
width: 100%;
height: 100%;
}
.right_and_margin {
margin:0 auto;
width: 40%;
height: 20%;
}
.forum_styling{
height: 55px;
width: 600px;
font-size: 25pt;
}
p {
font-size: 22pt;
font-weight: bold;
color: white;
margin-top: 5%;
}
}
<div class="right_and_margin">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg/250px-Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg
" alt="Image" id="border">
<p>Thank you for the help</p>
</div>
if i correctly understand you here is a solution. In flexbox we trust :)
html,
body {
height: 100%;
margin: 0;
}
.right_and_margin {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
<div class="right_and_margin">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg/250px-Foster_Reservoir_%28Linn_County%2C_Oregon_scenic_images%29_%28linnDA0050a%29.jpg" alt="Image" id="border">
<p>Thank you for the help</p>
</div>
Have a look at flexbox for horizontal and vertical alignment. Should be simple to add the following properties to the right element for your needs:
display: flex;
justify-content: center;
align-content: center;
Ressource: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
So I want to build a simple event box, to replace the default one in a calendar (react-big-calendar for reference, but I don't think it matters)
I would like to make it as responsive as possible, but I have started with a very static box, which corresponds to what I would like to see on a big screen.
Simple fiddle
.container {
width: 200px;
height: 200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding: 2px;
}
.event-slot-start-time {
font-size: 0.75em;
vertical-align: top;
position: absolute;
top: 0;
left: 0;
}
.event-slot-end-time {
font-size: 0.75em;
float: left;
vertical-align: bottom;
position: absolute;
bottom: 0;
left: 0;
}
.event-slot-label {
font-size: 1em;
top: 8px;
right: 5px;
position: absolute;
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
My goal is to have a 'centered, eventually slightly to the right' label,
and two small indications on the left that correspond to the start and end of the event.
I have tried using flexbox, coming from other StackOverflow answers, and it does seem to be able to do that somehow, but I have not managed to display the three elements properly. Any insight on a clean solution to achieve this result?
The simplest with the existing markup is to use Flexbox with column direction on the 2 date values and then position the label absolute using transform
.container {
width: 200px;
height:200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding:2px;
display: flex;
flex-direction: column;
}
.event-slot-start-time,
.event-slot-end-time {
font-size: 0.75em;
flex-grow: 1; /* share the vertical space equal */
}
.event-slot-label {
position:absolute;
font-size: 1em;
top: 50%;
left: calc(50% + 10px); /* adjust px value for horiz. offset */
transform: translate(-50%,-50%); /* vert./hor. center the label */
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
If you want a good responsive solution, use Flexbox all the way, here with a wrapper for the date's
.container {
width: 200px;
height:200px;
background-color: #dddddd;
margin: 20px;
padding: 5px;
}
.event-slot-component {
width: 100%;
min-height: 30px;
position: relative;
background-color: #64a7DD;
border: 5px;
border-radius: 3px;
padding:2px;
display: flex;
}
.event-slot-time {
display: flex;
flex-direction: column;
}
.event-slot-start-time,
.event-slot-end-time {
font-size: 0.75em;
flex-grow: 1; /* share the vertical space equal */
}
.event-slot-label {
flex-grow: 1; /* fill the remaining horizontal space */
font-size: 1em;
display: flex;
align-items: center; /* vertical center the label text */
justify-content: center; /* horizontal center the label text */
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-time">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
You would need to nest your flexboxes. That's what's so wonderful about it!
To explain, what I did was created three wrappers.
One to hold the entire event.
One to hold your event times.
One to hold the status.
We used flex box to butt the event times and status-wrapper against each other. The event times only take up as much space as the text utilizes (plus a little padding). The status wrapper takes up 100% of its usable space.
Then status wrapper is set to flex box using the justify-content and align-items properties. This centers the status.
The status text container is used in the same way to center the status text itself.
.event-wrapper {
background-color: #eee;
display: flex;
}
.event-times-wrapper {
background-color: skyblue;
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.status-wrapper {
width:100%;
display: flex;
align-items:center;
justify-content: center;
}
.status-text {
height: 100%;
display:flex;
align-items: center;
padding-left: 1rem;
padding-right: 1rem;
background-color: tomato;
}
<article class="event-wrapper">
<div class="event-times-wrapper">
<p class="event-start">9:00a</p>
<p class="event-end">10:00a</p>
</div>
<div class="status-wrapper">
<div class="status-text">Busy</div>
</div>
</article>
As OP requested later, a sample without special containers.
.container {
background-color: #eee;
position: relative;
width: 100vw;
height:6rem;
}
.event-slot-component div {
font-family: sans-serif;
color: white;
background-color: skyblue;
height:3rem;
float:left;
padding-left: 1rem;
padding-right: 1rem;
width:10%;
display:flex;
align-items:center;
justify-content:center;
}
.event-slot-component div:nth-child(2) {
background-color:red;
position:absolute;
bottom:0;
left: 0;
}
.event-slot-component div:last-of-type {
margin-left:25%;
background-color: tomato;
float:left;
height: 6rem;
}
<div class="container">
<div class="event-slot-component">
<div class="event-slot-start-time">17h</div>
<div class="event-slot-end-time">21h</div>
<div class="event-slot-label">Occupied Slot</div>
</div>
</div>
I've managed to use the preceding <span> method of centering items, which is all well, except for one little tiny issue illustrated in this image: http://imgur.com/UoKFW6P
how do i fix this? here is my css and html:
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (min-width:600px) {
.O1-3 {
height: inherit;
width: 33.3%;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>
There are multiple methods of centering in css, but without a definitive height, you're confined to a just few methods. Here are a few techniques I put together and commented out for you to take a look at: https://jsfiddle.net/73mtxgcc/3/
There are other techniques such as using flex or using display:table, but I find those, personally, either sloppy or not quite supported enough. As well, if you have something relative to the window, then you can always also use
.element{
display: inline-block;
margin: 0 auto;
}
with .element being the parent of the content you'd like to center.
If you have any more questions, or if you need any further clarifications, then please don't hesitate to ask!
You want to give all three columns the same padding with auto width, to get the text to be evenly spaced, then the wrapper centers the entire group. You get same amount of space on each side of the group, and then equal spacing in-between, so the center column ends up not being in the exact center of the page, but it has a very balanced visual effect for the page as a whole. You still need some adjustments with break-points though, I added one.
#wrapper {
width: auto;
height: inherit;
min-height: 100%;
}
.O1-3 {
padding: 1em;
color: white;
width: auto;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
#media screen and (min-width:600px) {
.O1-3 {
padding: 2em;
height: inherit;
}
}
#media screen and (min-width:1000px) {
.O1-3 {
padding: 5em;
}
}
When it comes to formatting HTML content with CSS, you should really use Flexbox. It is becoming really popular and is widely supported. In the code below, I have added a display: flex; property to your #wrapper. This creates a flex-box out of the wrapper. From there, I added a flex-direction of row, which will automatically format it's three child elements horizontally. In the media query, I have changed the flex-direction property so that the wrapper's child elements are formatted vertically.
-- Hope this helps.
<html>
<head>
<style>
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
display: flex;
flex-direction: row;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
text-align: center;
font-family: myfirstfont;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (max-width:600px) {
.O1-3 {
height: inherit;
width: 100%
margin: auto;
}
#wrapper {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>