I have a few elements which will contain a fixed size image and some text of variable length below, one nasty behaviour I noticed when texts are larger than the text container height where the div element grows but doesn't push down elements displayed below (Body has flex display with direction column) so that would be the preferable outcome right?
This is what I'm talking about: https://imgur.com/a/MjwOxXX
Notice how the upper section is taking space from the lower section by overlapping over it instead of the whole container growing and pushing down the lower section.
This is my code:
body{display:flex; flex-direction:column; height:auto; font-family:Roboto Slab; position:relative; scroll-bahaviour:smooth;}
*{box-sizing:border-box; margin:0; padding:0;}
a{text-decoration:none;}
.squared_maincontainer{width:100%; height:auto; display:flex; flex-direction:column;}
.squared_title{width:100%; height:100px; display:flex; justify-content:center; align-items:center; font-size:37px; font-weight:500; color:rgba(0,0,0,0.8);}
.squared_contents_container{width:100%; height:auto; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap;}
.squared_content_container{width:32%; height:auto; display:flex; flex-direction:column; margin:10px 0px;}
.squared_content_image{width:100%; height:260px; outline:1px solid rgba(0, 0, 0, 0.3); background-repeat:no-repeat; background-size:cover;}
.squared_content_texts_container{width:100%; height:145px; display:flex; flex-direction:column; padding:10px; position:relative;}
.squared_content_texts_title{ width:100%; font-weight:500; font-size:17px; color:var(--main_color); margin-bottom:10px;}
.squared_content_texts_description{width:100%; height:auto; font-weight:500; oveflow:hidden; font-size:14px; color:rgba(0, 0, 0, 0.9); margin-bottom:10px;}
.squared_content_texts_link{width:100%; font-size:14px; color:var(--main_color); font-weight:400; text-align:right; marin-top:auto;}
.menu_maincontainer{width:100%; height:auto; display:flex; flex-direction:column;}
.menu_title{width:100%; height:100px; display:flex; justify-content:center; align-items:center; font-size:37px; font-weight:500; color:rgba(0,0,0,0.8);}
.menu_contents_container{width:100%; height:auto; display:flex; justify-content:space-around; flex-wrap:wrap;}
.menu_content_image_container{width:32%; height:280px; box-shadow:3px 3px 3px rgba(0,0,0,0.1); background-size:cover; position:relative; }
.menu_content_texts_container{width:100%; height:auto; position:absolute; bottom:0px; left:0px; background-color:rgba(0,0,0,0.7); display:flex; flex-direction:column; padding:10px;}
.menu_content_texts_title{font-size:18px; font-weight:400; color:var(--main_color);}
.menu_content_texts_description{font-size:15px; font-weight:400; color:white;}
<div class="squared_maincontainer push" style="">
<span class="squared_title" style="">Eventos</span>
<div class="squared_contents_container" style="">
<a href="" class="squared_content_container" style="">
<div class="squared_content_image" style="background-image:url('img/dogs22.jpg');"></div>
<div class="squared_content_texts_container" style=" ">
<span class="squared_content_texts_title" style="">When our dog is afraid of men</span>
<span class="squared_content_texts_description" style="">One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend doesn’t live up One common dog fear is that of men — but is it normal and can it be fixed? One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend doesn’t live up One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend doesn’t live up to...</span>
<span class="squared_content_texts_link" style="">Read More</span>
</div>
</a>
<a href="" class="squared_content_container" style="">
<div class="squared_content_image" style="background-image:url('img/dogs12.jpg');"></div>
<div class="squared_content_texts_container" style=" ">
<span class="squared_content_texts_title" style="">When our dog is afraid of men</span>
<span class="squared_content_texts_description" style="">One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend doesn’t live up to...</span>
<span class="squared_content_texts_link" style="">Read More</span>
</div>
</a>
<a href="" class="squared_content_container" style="">
<div class="squared_content_image" style="background-image:url('img/dogs2.jpg');"></div>
<div class="squared_content_texts_container" style="">
<span class="squared_content_texts_title" style="">When our dog is afraid of men</span>
<span class="squared_content_texts_description" style="">One common dog fear is that of men — but is it normal and can it be fixed? We look at the causes and solutions for when Man’s Best Friend doesn’t live up to...</span>
<span class="squared_content_texts_link" style="">Read More</span>
</div>
</a>
</div>
</div>
<div class="menu_maincontainer push" style="">
<a class="menu_title" href="" style="">Título de sección</a>
<div class="menu_contents_container" style="">
<div class="menu_content_image_container" style="background-image:url('img/dogs32.jpg');">
<div class="menu_content_texts_container" style="">
<a class="menu_content_texts_title" href="" style="">Titulo</a>
<a class="menu_content_texts_description" href="" style="">Descripción del titulo</a>
</div>
</div>
<div class="menu_content_image_container" style="background-image:url('img/dogs30.jpg');">
<div class="menu_content_texts_container" style="">
<a class="menu_content_texts_title" href="" style="">Titulo</a>
<a class="menu_content_texts_description" href="" style="">Descripción del titulo</a>
</div>
</div>
<div class="menu_content_image_container" style="background-image:url('img/dogs22.jpg');">
<div class="menu_content_texts_container" style="">
<a class="menu_content_texts_title" href="" style="">Titulo</a>
<a class="menu_content_texts_description" href="" style="">Descripción del titulo</a>
</div>
</div>
</div>
</div>
I have reviewed your code and I noticed the .squared_content_texts_container class fixes the description text height to 145px. This is why when the height of the first box grew it didn't adjust the height of the parent div.
Try removing the 145px height from the .squared_content_texts_container class, or setting the min-height to 145px instead.
Then, the three flex boxes will vertically align in the middle but if you want them to be top-aligned, you must use the align-self: flex-start; styling on the .squared_content_container class.
Please see this jsFiddle with the result.
https://jsfiddle.net/katerynas/d3n5ksps/
.squared_content_texts_container{
width:100%;
min-height:145px;
display:flex;
flex-direction:column;
padding:10px;
position:relative;
}
.squared_content_container{
width:32%;
height:auto;
display:flex;
flex-direction:column;
margin:10px 0px;
align-self: flex-start;
}
Related
There a few HTML elements that I want to put in a line. This is the code I have used.
<input type = "text" className="search" placeholder="Search"></input>
<a href="/">
<img src="logo.svg"></img>
<h3>NameOfTheWebsite</h3>
</a>
SignIn
SignOut
But the output for this code is like this.
I want to put those elements in the same line and the logo should be top of the website name. How do I achieve this?
FlexBox is a really useful thing in such situations. In the following snippet, I have used some flexboxes just to get you familiar with it. But this is something that you should definitely master and use in your CSS layouts. MDN Web docs have a really great tutorial for that.
.home-page{
display:flex;
margin:15px;
}
.controls{
display:flex;
justify-content:space-between;
align-items:center;
}
.signing-buttons{
display:flex;
}
.signing-buttons a{
margin:5px;
padding:10px;
border:2px solid red;
border-radius:4px;
}
<a class="home-page" href="/">
<h3>NameOfTheWebsite</h3>
<img src="logo.svg"></img>
</a>
<div class="controls">
<input type = "text" className="search" placeholder="Search"></input>
<div class="signing-buttons">
SignIn
SignOut
</div>
</div>
You can use flexbox to achieve this. Just a minimalistic example to illustrate my point is shown below. You can control how much space each item will occupy and a lot of other things.
.row {
display:flex;
}
.search {
flex:1;
border:1px solid black
}
.name {
flex:1;
border:1px solid black
}
<div class='row'>
<div class='search'>Search Box</div>
<div class = 'name'>Name</div>
</div>
<div class='row'>Next line</>
I'm trying to center (align horizontally) a button on my email template. Here is my current code:
<p class="product-link" style="text-align:left; width:60%; display:inline-block; vertical-align:middle;">
<span>
<a style="color:#000000; background:#F4D079; padding:10px 15px; display:inline-block; margin-bottom:10px; text-decoration:none; border-radius:5px; font-size:14px;" href="https://www.amazon.com/review/review-your-purchases/ref=?_encoding=UTF8&asins=[[PRODUCT_ASIN]]">Share your opinion</a>
</span>
<br>
</p>
I know this is an amateur question and I apologize, I've tried a million things and haven't gotten anything to work.
Removed unnecessary styles (width:60%; display:inline-block;),and added style to center the button(text-align: center;).
<p class="product-link" style="text-align: center;vertical-align:middle;">
<span><a style="color:#000000; background:#F4D079; padding:10px 15px; display:inline-block; margin-bottom:10px; text-decoration:none; border-radius:5px; font-size:14px;" href="https://www.amazon.com/review/review-your-purchases/ref=?_encoding=UTF8&asins=[[PRODUCT_ASIN]]">Share your opinion</a></span><br>
<script type="text/javascript">
</script>
</p>
Set the parent element to display block and the button to margin-left and margin-right auto :)
I tried several things but I am out of luck. I need to build a button containing an image and text over a button background image. Also, clicking anywhere inside the button should redirect to a page, for example, google.com. This is how the button should look like
The challenge I am having is that when the button text changes or when the screen size changes, the alignment of the image and the text gets messed up. I want to wrap the button text if it is too large. How do I wrap the button text and still align everything correctly? Also, I want the button width to be the same as I have to build multiple buttons of the same size with varied texts and images. Thank you so much. A quicker solution will be appreciated as I am anxious to see what I am doing wrong. Here is the code I have so far: JSFiddle
<a href="https://www.google.com" style="color: white !important; background-color: #7FFF00;padding: 25px;width: 50px;">
<span style="margin-bottom: 5%;">
<img src="http://placehold.it/30x30" height:100%; style="display: inline-block;" width="30" height="30" />
<span style="display: inline-block;">
<b><font size ="2" color="BLACK" face="Arial">CLICK ON THE IMAGE TO VIEW MORE DETAILS ABOUT THE ITEM </font> </b>
</span>
</span>
</a>
img{
width:30px;
height:30px;
}
a{
text-decoration:none;
color:black;}
#img{
float:left;
}
#img,#text{
display:inline;
}
#main{
margin-top:20px;
width:250px;
border:2px solid black;
border-radius:10px;
background:yellowgreen;
}
#container{
margin:15px;
}
div.clickable {
position:relative;
}
div.clickable #mainlink {
position:absolute;
width:100%;
height:100%;
}
<div class="clickable">
<a href="www.google.com" id="mainlink">
<div id="main">
<div id="container">
<div id="img">
<img src="http://oer.nios.ac.in/wiki/images/thumb/4/47/Thumpsup.png/200px-Thumpsup.png"/>
</div>
<div id="text">
<span>Click on the image to view more about the item</span>
</div>
</div>
</div>
</a>
</div>
this is my first question and I hope I would get some help here.
I have made this HTML page that has 5 DIV's mainly:
Header
Content
Footer
Content contains
Left
Right
The Left and Right Div's float on Left and right respectively.When I put something content div with an H1 tag the div's get somewhat disorted and I get a approx. 10px space between the header and content section, somewhat like this:
Disorted
However the original one should be:
Original
<body>
<a target="_blank"><div id="main" >
<div id="header" >
<a style="color:#000000" href="home.html">Home</a>
<a style="color:#000000" href="about.html">about</a>
<a style="color:#000000" href="Our customers.html">Our Customers</a>
<a style="color:#000000" href="Career.html">Careers</a>
<a style="color:#000000" href="Contact us.html">Contact us</a>
</div>
<div id="content">
<div id="left" ></div>
<div id="right" ></div>
Home
</div>
<div id="footer">
<a style="color:#FFFFFF" href="home.html">Privacy Policy</a>|
<a style="color:#FFFFFF" href="Feedback.html">Feedback</a>|
<a style="color:#FFFFFF" href="disclaimer.html">Disclaimer</a>|
<a style="color:#FFFFFF" href="Manadatory.html">Manadatory Disclosure</a>|
<a style="color:#FFFFFF" href="sitemap.html">Site Map</a>|
</div>
</div></body>
Here is my CSS Code:
#main
{
height:900px;
background-color:#000000;
}
#header
{
height:100px;
background-color:#00FF00;
padding:70px;
padding-right:70px;
font-size:30px;
text-align:center;
background-image:url(Images/text3.jpg);
padding: 50px;
}
#content
{
height:700px;
background-color:#FFFFFF;
}
#left
{
float:left;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#right
{
float:right;
height:700px;
background-color:#FF0000;
width:150px;
background-image:url(Images/navbar2.jpg);
}
#footer
{
padding:50px;
padding-right:70px;
font-size:20px;
text-align:center;
height:100px;
background-image:url(Images/footer.jpg);
}
Fixing position of the div's using position hasn't helped. Thanks for any help in advance :)
Right click and inspect element on your browser and check the divs. You should see what's happening to it. Most likely it will be some default styling that's giving some margins. That's why most people use some kind of reset.css as a clean base. I imagine the default css is applying margins to the <p> and <h1> tags.
Maybe try adding something like:
h1 {
margin:0;
}
Obviously you could specify only certain margins rather than all or .content h1{} to just apply styling to the headers within the content block.
I am trying to create a simple menu using the following html setup:
<div class="container">
<div class="container-cell">
<a href="play.html">
<div class="menu-option no-margintop">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_1.png"/>
</div>
<div class="menu-text"><span>Play</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_3.png"/>
</div>
<div class="menu-text"><span>Highscore</span></div>
</div>
</a>
<a href="index.html">
<div class="menu-option">
<div class="play-icon">
<span class="helper"></span><img src="./img/icon_2.png"/>
</div>
<div class="menu-text"><span>FAQ</span></div>
</div>
</a>
</div>
</div>
In the process of creating this, I made a switch from hard pixels to percentages. Whereas the pixel version of setting hights works, it does not seem to work in percentages. The hight for one particular class, menu-option, does not seem to get picked up by the browser.
I have been searching for a while, and the only solutions I came across, was setting a height to both the body and html (100%). I have also set a height to any of the container-elements.
See css below:
html, body{
height:100%;
}
.container {
display:table;
width:100%;
height:70%;
}
.container-cell {
display:table-cell;
vertical-align: middle;
height:100%;
}
.menu-option{
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Why is the browser not picking up on the height in percentage and how can make it use the height in percentage?
Add display: inline-block; to your menu-option class for the height property to work. Something like this:
.menu-option{
display: inline-block;
width:90%;
margin-left:5%;
border-radius:10px;
background-color:rgba(17,23,28,0.2);
height:6.94%;
margin-top:5%;
font-size:150%;
}
Here's a jsfiddle of the above: https://jsfiddle.net/AndrewL32/e0d8my79/17/