Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 21 days ago.
Improve this question
I want to have text on the left side of the useres screen and on the right side and Image. Look at the prototype i provided![enter image description here][1]
I can't find a solution pls help
I cant upload images, but heres a link to it
https://photos.app.goo.gl/97ZLoYcLBsVsRnjc6
I tried to do it with floats. But it didnt work out, since the button would just be way to far away from the text. The Image shouldt take away any space, it should display on the right side
We can use flex in this case
Refer CSS flex for further changes >> CSS Flex
* {
padding: 0;
margin: 0
}
.container {
display: flex;
justify-content: space-around;
align-items:center;
background-color: black;
color: white;
height:100vh
}
.container-button {
border: none;
background-color: white;
color: black;
padding: 0px 20px;
}
.container-img {
height: 100px;
width: 200px;
}
<div class="container">
<div class="container-text">
<h2>Hello World</h2>
<h4>This is some Text</h4>
<button class="container-button">button</button>
</div>
<img class="container-img" src="https://via.placeholder.com/200x100/FFFFFF/000000">
</div>
You can do something like this:
.container{
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
}
.container-right-side img{
margin-right: 2rem;
max-width: 60vw;
width: 100%;
}
.container-left-side{
margin-left: 2rem;
}
#media screen and (min-width: 0px) and (max-width: 600px){
.container{
flex-direction: column;
}
.container-left-side{
margin-left: 0;
}
}
<div class="container">
<div class="container-left-side">
<h2>Hello World</h2>
<h4>This is Some text</h4>
<button>button</button>
</div>
<div class="container-right-side">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
</div>
</div>
You can use something like this:
.container {
display: flex;
justify-content: space-between;
padding: 70px;
background-color: black;
}
.text {
display: flex;
flex-direction: column;
justify-content: center;
/* align-items: center; */
width: 50%;
padding: 50px;
color: white;
}
.image {
width: 50%;
}
img {
width: 100%;
height: auto;
border: 1px solid white;
}
button {
max-width: 100px;
}
<div class="container">
<div class="text">
<h1>Hello World</h1>
<p>This is Some Text</p>
<button>Button</button>
</div>
<div class="image">
<img src="https://via.placeholder.com/300 " alt="Image">
</div>
</div>
Related
My footer is in fixed position and I am seeing the same view on every device. I also want to fix the LinkedIn logo in white div and orange div above it. So that my website will have same view on every device. but I am not to fix them. Can anyone please help?. I have been trying from last 2 weeks.
I am not able to add my codes here. so attaching the same in screenshot
html code
css code
This how my website currently looks like//i.stack.imgur.com/VNVDN.jpg
This is how I want my website to look like//i.stack.imgur.com/VNVDN.jpg
Actually I made an easy template of what you need. It is pretty simple so I am sure that you will get the point. Please ask me whatever you want.
HTML
<div class="footer-wrapper">
<div class="orange-container">
</div>
<div class="social-container">
<img src="#">
</div>
<div class="black-container">
<p>text text text</p>
<p>text text text</p>
</div>
</div>
CSS
.footer-wrapper {
width: 100%;
height: 100px;
margin: 0px;
padding: 0px;
position: relative;
bottom: 0;
}
.orange-container {
width: 100%;
height: 40px;
background: orange;
}
.social-container {
width:100%;
display: flex;
justify-content: center;
}
.social-container img {
background: red;
width: 30px;
height: 30px;
}
.black-container {
width: 100%;
background: black;
padding-top: 1rem;
color: white;
display: flex;
justify-content: center;
flex-direction: column;
}
.black-container p {
text-align: center;
margin: 0;
}
It is better way to use display:flex or display:grid when you want to center something. Padding is used to make small spaces. Also with the display flex or grid you can easily handle the responsive view of your website pretty easy.
Please I am also advising you to check how to make your questions good Click Here
I hope my answer will be helpful for you, and again if not, don't hesitate to ask anything :)
You can use flexbox. And assign to the main part flex-grow.
* {
padding: 0px;
margin: 0px;
}
.w {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 100vh;
}
.header {
background: orange;
padding: 5px;
}
.main {
flex-grow: 1;
}
.footer {
background: black;
height: 40px;
text-align: center;
color: white;
padding: 5px;
}
<div class="w">
<div class="header">header</div>
<div class="main">main</div>
<div class="footer">footer</div>
</div>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I would like to build a "grid"/"table" using flexbox which has 2 rows and 2 columns. In the two items of the left column I want the text to be aligned to the left while in the two items of the right column I want the text to be centered. As easy as it seems to be, I cannot figure out how to achieve this goal using flexbox. I would be very delighted if someone could provide a small example on how to do this.
* {
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: grid;
place-items: center;
}
.flex {
display: flex;
}
.container {
position: relative;
width: 350px;
height: 350px;
border: 1px solid red;
}
.column {
position: relative;
width: 100%;
height: 100%;
padding: 2rem;
display: flex;
flex-direction: column;
background-color: pink;
}
.column:nth-child(2) {
background-color: coral;
}
.column:nth-child(2) .box {
text-align: center;
/* if you also want to align text vertically center */
/* display: grid;
place-items: center; */
}
.column .box {
width: 100%;
height: 100%;
background-color: lightgreen;
}
.column .box:not(:first-of-type) {
margin-top: 2rem;
}
<div class="container flex">
<div class="column">
<div class="box">
aligned left
</div>
<div class="box">
aligned left
</div>
</div>
<div class="column">
<div class="box">
aligned center
</div>
<div class="box">
aligned center
</div>
</div>
</div>
If you also want to align text vertically center add the below mentioned code inside .box.
/* grid method */
display: grid;
place-items: center;
/* flex method */
display: flex;
align-items: center;
justify-content: center;
CSS:
.container {
display: flex;
width: 200px;
height: 200px;
border: 1px solid red;
flex-wrap: wrap;
box-sizing:border-box
}
.container div {
width: 50%;
height: 100px;
border: 1px solid green;
box-sizing:border-box
}
.container .box1,
.container .box3{
text-align: left
}
.container .box2,
.container .box4{
text-align: center
}
HTML:
<div class="container">
<div class="box1">sample text</div>
<div class="box2">sample text</div>
<div class="box3">sample text</div>
<div class="box4">sample text</div>
</div>
I've provided the html and css. The is modified by the script.js file which is why it's empty. I want the text to appear at the center even when screen width is reduced. Please help.
HTML:
<section id="page1">
<div class="welcome">
<div class="box">
<img class="mypic" src="img/me.jpg" alt="" srcset="" />
<h1 id="welcomeText1"></h1>
</div>
</div>
</section>
CSS:
#page1, #page2, #page3, #page4 {
min-height: 100vh;
}
.box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-left: 2rem;
}
.mypic {
width: 15rem;
height: 15rem;
border-radius: 500px;
}
I've provided screenshots below.
Absolute beginner here. =)
At normal width
On decreasing width
When you do justify-content: center; it will only align the div/element which is the child of your flexbox.
But to align the text/content in that particular element you need to use text-align: center;
If I correctly understand, you just need to add CSS property to welcomeText1:
#page1, #page2, #page3, #page4 {
min-height: 100vh;
}
.box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 2rem;
margin-left: 2rem;
}
.mypic {
width: 15rem;
height: 15rem;
border-radius: 500px;
}
#welcomeText1{
text-align: center;
border: 3px solid green;
}
<section id="page1">
<div class="welcome">
<div class="box">
<img class="mypic" src="img/me.jpg" alt="" srcset="" />
<h1 id="welcomeText1">Welcome to stackoverflow <br> Welcome</h1>
</div>
</div>
</section>
(I had you a border to show you)
You can use text-align: center for the text.
#welcomeText1 {
text-align: center;
}
Or if you want to keep the text in that structure, you could decrease the font size when using small screens with media queries.
#welcomeText1 {
font-size: 1.4rem;
}
#media (max-width: 720px) {
#welcomeText1 {
font-size: 1.2rem;
}
}
I made 2 divs inside container div, and I gave them the element inline block, I wanted them to be side by side. like 1 > 2, not on top of each other.
they look great in my screen size (24inch)
but once the screen size is going down, instead of getting smaller the divs will lay on top of each other
could you help me making them responsive?
html
<div class="exampleboxcontainermainpage">
<div class="exampleboxmainpage">
<h1>create social media Buttons with html and css</h1>
<br>
<div class="socialmediacontainer">
</div>
<br />
<br />
<br />
<br />
<br />
<br>
</div>
<div class="exampleboxmainpage2">
<div class="exampleinsideboxmainpage">
<pre class="prettyprint default">
<!-- Start of showing code -->
<xmp>
<div class="socialmediacontainer">
</div>
</xmp>
<!-- !!!!! End of showing Code !!!!!-->
</pre>
</div>
<button onclick="window.location.href = 'tryyourselfcodes/howto_howto_social_button.php'; " style="left:30px;" class="buttontest">
Try yourself >>
</button>
</div>
</div>
css
.exampleboxcontainermainpage{
padding-left:100px;
}
.exampleboxmainpage {
background-color: #f3f4fa;
border-style: unset;
/* padding: 23px; */
text-align: center;
width: 800px;
height: 400px;
position:relative;
display: inline-block;
bottom:24px;
}
.exampleboxmainpage2 {
background-color: #f3f4fa;
border-style: unset;
padding: 31px;
text-align: center;
width: 900px;
height: 400px;
position:relative;
display: inline-block;
}
.exampleboxmainpage h3 {
padding-bottom: 10px;
display: inline-block;
}
.examplebox button {
display: inline-block;
text-align: center;
}
.exampleinsideboxmainpage {
background-color: black;
text-align: center;
width: 700px;
display: inline-block;
border-style: unset;
}
.exampleinsideboxmainpage p {
font-family: "Roboto", sans-serif;
font-size: 20px;
color: white;
overflow-wrap: break-word;
display: inline-block;
}
Welcome to SO!
Try to use flex as its responsive and easy to use
And on break-screen(below 767px mobile) i just change its direction to
column from row
* {
box-sizing: border-box;
}
.container {
display: flex;
width: 100%;
flex-flow: row wrap;
}
[class*="box--"] {
display: flex;
margin: .25rem;
height: 2rem;
padding: .25rem;
color: white;
}
.box--half {
background: blue;
flex: 1 1 30%;
}
#media all and (max-width: 767px) {
.container{
flex-direction: column;
}
}
<div class="container">
<div class="box--half">1</div>
<div class="box--half">2</div>
</div>
Read more about flex here
If you resist to use inline display instead advanced one like flex or grid you can use media queries to show your div under each other in smaller screen, for example I use 800px for breakpoint. You can use display: block:
.container>div {
display: inline-block;
width: 200px;
height: 200px;
background: gray;
text-align: center;
line-height: 200px;
}
#media all and (max-width: 800px) {
.container>div {
display: block
}
}
<div class="container">
<div>Content 1</div>
<div>Content 2</div>
</div>
how can I make this container responsive so the text and the img automatically become block elements. I tried it out with flex direction but for someway it doesnt work. Can someone correct my code if necessary and suggest me a media query rule for the responsive design
<div class="top">
<h1>Welcome</h1>
<div class="portrait">
<img src="https://pixy.org/images/placeholder.png" alt="">
<h2>XXXXXXXXXX</h2>
</div>
</div>
.top h1{
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: black;
height: 20vw;
margin-top: 0;
font-size: 5vw;
color: white;
text-shadow: 5px 5px rgb(142, 135, 136);
}
.top img {
width: 20vw;
}
thanks in advance
I think this is what you are after. display: flex; is very powerful property and useful when it comes to take up rest of the space and centering.
Modification
here is a demo, I would not suggest this approach with using max-width as it's not "mobile-first". But if this is what you want for this project then ok.
.container {
display: flex;
flex-direction: row;
background-color: deepskyblue;
}
#img {
width: 140px;
height: 140px;
}
#text {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: deeppink;
min-height: 100px;
}
#media screen and (max-width: 700px) {
.container {
flex-direction: column;
}
#img {
width: 100%;
height: auto;
}
}
.container {
display: flex;
background-color: deepskyblue;
}
#img {
width: 140px;
height: 140px;
}
#text {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: deeppink;
}
<div class="container">
<img id="img" src="https://www.archlinux.org/static/vector_tux.864e6cdcc23e.png" />
<div id="text">text on the left, next to the img</div>
</div>
Ok, well so here it is if I understood well what you are trying to accomplish. Correct me or update your question if I am wrong!
#img{
width: 200px;
height: 150px;
float: left;
}
#text{
overflow: hidden;
}
<div class="container">
<img id="img" src="https://www.archlinux.org/static/vector_tux.864e6cdcc23e.png"/>
<div id="text">text on the left, next to the img</div>
</div>