just a simple question i am stuck with. i am playing around with some html and css, i would like to create a page with content box in the centre of the page and two images of arrows on either side of the content box. now thats not hard at all, the issue is i am using position: absolute; so if i change the window size the elements go nuts..
my html:
<div id= "left_side">
<img id="leftArrow" src="images/lefta.png"/>
</div>
<div id="right_side">
<img id="rightArrow" src="images/righta.png"/>
</div>
<div id="content">
<p>something</p>
<p>more something</p>
</div>
and my css looks like this:
#left_side {
border: black solid 1px;
position: absolute;
left: 0;
width: 10em;
text-align: center;
margin: 65px;
border-radius: 8px 8px 8px 8px;
}
#right_side {
border: black solid 1px;
position: absolute;
right: 0;
width: 10em;
text-align: center;
margin: 65px 210px 0px 0px ;
border-radius: 8px 8px 8px 8px;
}
#content {
background-color: white;
width: 500px;
margin: 15px 320px 15px 320px;
padding: 30px;
border:5px;
border-radius: 8px 8px 8px 8px;
}
what can i change so that the side images/buttons are relative to the content box at all times no matter what the screen size. i was thinking of nesting them in a bigger box but is that the best practice or am i going off on the wrong foot all together. sorry for the simple question, i am new to this and positioning always kills me.
thanks in advance
I normally use two wrapper divs to center anything inside them (no absolute style). CSS:
.couter
{
position: relative;
left: 50%;
float: left;
}
.cinner
{
position: relative;
left: -50%;
}
And use like:
<div class="couter">
<div class="cinner">
<div id= "left_side">
<img id="leftArrow" src="images/lefta.png"/>
</div>
<div id="right_side">
<img id="rightArrow" src="images/righta.png"/>
</div>
<div id="content">
<p>something</p>
<p>more something</p>
</div>
</div>
</div>
If you want the content to expand when the page expands, this is how you could do that:
http://jsfiddle.net/VKBTy/
Also, I would use a container box with position:relative.
I have created a jsfiddle for you with a possible solution.
http://jsfiddle.net/simonweston/MuTEn/
HTML:
<div id= "left_side">
LEFT
</div>
<div id="content">
<p>something</p>
<p>more something</p>
</div>
<div id="right_side">
RIGHT
</div>
CSS:
#left_side {
border: black solid 1px;
float: left;
width: 10em;
text-align: center;
border-radius: 8px 8px 8px 8px;
}
#right_side {
border: black solid 1px;
float: left;
width: 10em;
text-align: center;
border-radius: 8px 8px 8px 8px;
}
#content {
background-color: red;
float: left;
width: 100px;
border:5px;
border-radius: 8px 8px 8px 8px;
}
The layout which you need can be brought in a very simpler way..
I have modified your css as
#left_side {float:left;width:100px;padding:10px;}
#right_side {float:left;width:100px;padding:10px;}
#content {width:500px;float:left;background:blue;}
.clear{clear:both;}
and your HTML as
<div id= "left_side">
<img id="leftArrow" src="images/lefta.png"/>
</div>
<div id="content">
<p>something</p>
<p>more something</p>
</div>
<div id="right_side">
<img id="rightArrow" src="images/righta.png"/>
</div>
<div class="clear"></div>
Please use this code to check whether you got your requirement right..
Related
Hi I am designing a blog site using pure html and css and I have some design in mind. Currently it looks like before graph and I would like to achieve after graph. Right now all these classes are in inline-block and I do not want to change the dom structure. Please refer to this code snippet for implementation:
https://jsfiddle.net/yueeee/vb1we2tk/4/
.container {
padding: 10px 40px;
padding-left: 0px;
width: 100%;
height: 100%;
}
.meta {
position: relative;
display:inline-block;
height: 100%;
width: 10%;
max-width: 200px; /*in large resolution dont always want width to be 12%*/
margin-right: 40px;
/* background-color: transparent; */
padding: 0px 10px;
text-align: right;
vertical-align:top; /*always align to the top of container*/
}
.content {
width: 30%;
display:inline-block;
padding: 20px 30px;
background-color: white;
position: relative;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
vertical-align:top; /*always align to the top of container*/
}
<div class="container">
<div class="meta">
<div class="time">
<p>2020/12/09<br>22:18:35</p>
</div>
<div class="tag">
<p>tag1</p>
<p>tag2</p>
</div>
</div>
<div class="content post">
<div class="text">
<h2> title </h2>
<p>content<br>content<br>content<br>content<br>content<br>
</p>
</div>
</div>
</div>
The difficulty I met is how do I set metadata's height equals to content. I checked solution on setting container as table and metadata/ content as table-cell. However, it would cause some other styling issue so I still want to keep everything as inline-block. The other way I am thinking is to set the height of metadata equal to container. It failed because container does not height attribute. I tried something like setting height = 100% cause I do not want a stable height but also did not work.
Need your advice.
Before:
After:
The best choice in these cases is to use the flex property. I added some Properties to both the .container and .meta selectors and deleted some, act like code to get the desired result.
.container {
display: flex;
padding: 10px 40px;
padding-left: 0px;
width: 100%;
height: 100%;
}
.meta {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 10%;
margin-right: 40px;
padding: 0px 10px;
text-align: right;
}
.content {
width: 30%;
display:inline-block;
padding: 20px 30px;
background-color: white;
position: relative;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<div class="container">
<div class="meta">
<div class="time">
<p>2020/12/09<br>22:18:35</p>
</div>
<div class="tag">
<p>tag1</p>
<p>tag2</p>
</div>
</div>
<div class="content post">
<div class="text">
<h2> title </h2>
<p>content<br>content<br>content<br>content<br>content<br>
</p>
</div>
</div>
</div>
This is my website: http://audunhilden.tk/projects/temp/#,
you can see my text box to the left, thats 3 divs. Can anyone help me to get another one on the same line? I cant get it to work, would be great if anyone coded a easier one too.
Not able to share my HTML or CSS,
Cant paste my CSS for some reason, you´re able to see it here:
http://audunhilden.tk/projects/temp/info.css
Here's a simple example. I did not use any of your css, as the html and those things are missing, but hopefully this can get you going:
CSS:
.container {
position: relative;
width: 500px;
background: red;
overflow: hidden; /*To get your parent to respect the floated divs*/
}
.one, .two, .three {
position: relative;
width: 33.33333333333333%; /*Because you only have 3 elements (100 divided by 3)*/
height: 100px;
float: left; /*To get them next to each other if all else fails*/
background: green;
}
HTML:
<div class="container">
<div class="one">
Div One
</div>
<div class="two">
Div Two
</div>
<div class="three">
Div Three
</div>
</div>
EDIT:
I tried to replicate your website to what I think you are trying to explain :).
Here's a quick screenshot:
Please see this HTML and CSS to replicate the image above :):
<!DOCTYPE html>
<html>
<head>
<title>Cocos - Audun Hilden</title>
<style>
body {
font-family: 'Roboto', sans-serif;
background: #36536B;
}
header {
background: #FFFFFF;
color: #919191;
padding: 15px;
line-height: 30px;
max-width: calc(770px - 30px);
border-radius: 3px;
margin: auto;
}
.container {
max-width: 770px;
margin: auto;
margin-top: 15px;
overflow: hidden;
}
.left, .right {
float: left;
overflow: hidden;
border-radius: 3px;
margin-right: 10px;
max-width: calc(50% - 5px);
}
.right {
margin-right: 0px;
}
.left-header, .right-header {
background: #58C5B3;
font-size: 10px;
padding: 15px;
color: #FFFFFF;
}
.left-text, .right-text {
background: #FFFFFF;
padding: 5px;
font-size: 15px;
}
</style>
</head>
<body>
<header>
FORSIDEN
</header>
<div class="container">
<div class="left">
<div class="left-header">
BORDER-LEFT
</div>
<div class="left-text">
One two three four
</div>
</div>
<div class="right">
<div class="right-header">
BORDER-RIGHT
</div>
<div class="right-text">
One two three four five six seven
</div>
</div>
</div>
</body>
</html>
Take some time to look at the HTML and CSS to try figure out what is going on. Once you understand, you'll never forget!
It's important to note that your doctype is also invalid. Try using <!DOCTYPE html>. Your code is all over the place too. You have html code outside of the body. The style tag should be inside the head tag, but ideally you should be using a stylesheet.
I just added display: inline; to the #tekst-sett div id in the css
and added acontainer to both inputs as you requested.
<div id="cont">
<div id="tekst-sett">
Insert text pls
</div>
<div id="tekst-sett">
Insert text pls
</div>
</div>
#tekst-sett {
padding-left: 3px;
padding-right: 3px;
padding-bottom: 3px;
background-color: #ffffff;
border-left: 1px solid #c2c2c2;
border-right: 1px solid #c2c2c2;
border-bottom: 1px solid #c2c2c2;
border-radius: 0 0 5px 5px;
position: relative;
width: 24%;
font-size: 15px;
display: inline;
}
is that what you meant?
You can Use the concept of Flex to achieve this. Here is the small example of what you are expecting
#main{
display:flex;
justify-content:space-around;
}
#sub1,#sub2{
width:100px;
height:100px;
border:1px solid;
}
<div id="main">
<div id="sub1">
</div>
<div id="sub2">
</div>
</div>
I think you should use floats, and maybe do a little research it will be easier next time if you solve it yourself!
I recommend you this article, maybe it will help you some further project:
https://css-tricks.com/all-about-floats/
I am working on trying to make a chat app and need chat bubbles to tightly fit around their content. It works alright for text, but when I have an image in the bubble it gets problematic. Here is the HTML that I am using
<div class="fromMe msgBubble">
<img src="{{image.location}}" style="width:50%;">
<br>
<span class="msgDate">2011-01-26 01:52:16</span>
</div>
<div class="clearfix"></div>
However, when I load the image I have a whole bunch of padding off to the side of the image, and the div doesn't tightly wrap around the image. It looks like this:
http://imgur.com/R3j7yO2
UPDATE: I posted a JS Fiddle with the code and CSS.
https://jsfiddle.net/dw9aek2y/
How can I tight fit the chat bubble div around the picture?
Thanks!
Remove width and add max-width and every thing will be fine
#messageBubbleArea {
font: 14px Arial;
margin-top: 20px;
padding: 0 10px;
width: 99%;
}
.fromMe::before {
border-bottom: 9px solid #0b93f6;
border-right: 9px solid rgba(0, 0, 0, 0);
bottom: 0;
content: "";
position: absolute;
right: -8px;
}
*::after, *::before {
box-sizing: border-box;
}
.fromMe {
background-color: #0b93f6;
border-radius: 8px 8px 0;
color: white;
float: right;
margin-left: auto;
text-align: right;
}
.fromThem, .fromMe {
clear: both;
margin-top: 20px;
max-width: 80%;
padding: 5px 9px;
position: relative;
}
<div id="messageBubbleArea">
<div class="fromMe msgBubble">Hey babe<br>
<span class="msgDate">2011-01-26 00:09:30</span>
</div>
<div class="clearfix"></div>
<div class="fromMe msgBubble">
<img style=" max-width:200px;" src="http://images.clipartpanda.com/rainbow-clip-art-rainbow.gif"><br>
<span class="msgDate">2011-01-26 01:52:16</span>
</div>
<div class="clearfix"></div>
</div>
I would like to split my div tag up in two. But I am not quite sure how to do it. It looks like this now:
And I would like that there is a header in the div tag with a color for a headline. It should look like this:
But how can I split up like that?
Best Regards Julie
HTML and CSS:
#container {
width: 100%;
}
body {
background-color:rgb(48,48,48);
}
.topbar {
width: 100%;
height: 50px;
background-color: red;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
.latestnumbers {
float: left;
height: 600px;
width: 50px;
padding: 25px;
border: 2px solid #FFECB3;
margin: 20px;
background-color:rgba(116,116,116,0.3);
}
.hotnumbers {
float: left;
height: 600px;
width: 50px;
padding: 25px;
border: 2px solid #FFECB3;
margin: 20px;
background-color:rgba(116,116,116,0.3);
}
.coldnumbers {
float: left;
height: 600px;
width: 50px;
padding: 25px;
border: 2px solid #FFECB3;
margin: 20px;
background-color:rgba(116,116,116,0.3);
}
.numberheader {
height 100px;
background-color: red;
position: absolute;
top: 80px;
left: 30px;
right: 0;
width: 100px;
height: 50px;
}
.content {
float: left;
height:50px;
width:700px;
padding: 25px;
border: 2px solid navy;
margin: 20px;
background-color: red;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/my_script.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css\placing.css">
<title>Numbers</title>
</head>
<body>
<div id="container">
<div class="topbar">
<p>Topbar</p>
</div>
<div class="latestnumbers" id="show">
<div class="numberheader">
<p>Tal</p>
</div>
</div>
<div class="content">
<p>Enter The Number</p>
<form id="myForm" action="select.php" method="post">
<input type="number" name="numbervalue">
<button id="sub">Save</button>
</form>
<span id="result"></span>
</div>
<div class="hotnumbers">
<p>test</p>
</div>
<div class="coldnumbers">
<p>test</p>
</div>
</div>
</body>
</html>
EDITED:
I have just tried to position the div tag now, and it is position in the middle now. But the code for the position is pretty messy, isn't it?
Try this, I think this was what you meant right?
https://jsfiddle.net/54d4tbtc/
It didn't look that good because of the width's
.content {
float: left;
height: 50px;
width: 300px;
padding: 25px;
border: 2px solid navy;
margin: 20px;
background-color: red;
}
I would make two divs, and wrap one inside the other like this:
<div class="topbar"></div>
<div class="outer">
<div class="inner">
<p>words</p>
</div>
</div>
when combined with this type of CSS:
.inner{
width:100%;
height: 150px;
background-color: #FFECB3;
word-wrap: break-word;
text-align: center;
}
.inner p{
padding-top: 10px;
}
it should work fine. Not sure what .talraekkeheader does in your CSS, but if it was planned for this .inner div then you may not need it after doing this.
NB. I added the word-wrap styling to .inner to avoid the overflow of text that you put in the div. I added padding to the paragraph text within the element for aesthetics mainly, as you don't want text to close to the top of the div.
body {
margin: 0;
width: 100%;
background-color: #292929;
}
.holder {
width: 66%;
height: 330px;
background-color: #412A22;
position: relative;
-webkit-box-shadow: 2px 2px 2px 0px #000000;
-moz-box-shadow: 2px 2px 2px 0px #000000;
box-shadow: 2px 2px 2px 0px #000000;
display: inline-block;
}
.holder:before {
content: '';
position: absolute;
top: 0; left: 0;
border-top: 50px solid #292929;
border-right: 50px solid #412A22;
width: 0;
}
.sidething {
float: left;
width: 100px;
display: block;
}
<div class="main">
<div class="holder">
<div class="holder-imgs">
</div>
<div class="contact">
</div>
</div>
<img class="sidething" src="Layer%203.png">
</div>
This is my css and html and what i basicly need is to center both image and div in the middle of the page. Here is what it looks like with image: http://imgur.com/IROUUk2
Thanks in advance
Why not do something simple like this:
<center>
<div class="main">
<div class="holder">
<div class="holder-imgs">
</div>
<div class="contact">
</div>
</div>
<img class="sidething" src="Layer%203.png">
</div>
</center>
Simple HTML - should do the trick!
Or, if you're main 'holder' div will only contain text, you could add the following property to the 'holder' div css:
text-align: center;
You might find this site useful!
Hope this helps and best of luck!