TechQA.

How to margin div inside other div?

1.8k views Asked by Ruslan Lomov At 2015-06-23T14:50:17+00:00 23 June 2015 at 14:50 2025-12-19T16:52:44+00:00

html body,simple form with table and two divs inside(login and table):

<body>
    <div id="container">
        <form>
            <div class="login">
                <div class="table">
                    <table class="userInput">
                        <tr>
                            <td><input type="text" placeholder="Username" id="username"
                                name="login"></td>
                        </tr>
                        <tr>
                            <td><input type="submit" value="submit"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
    </div>
</body>

My css:

html,body {
    margin: 0;
    padding: 0;
    height: 100%;
}

table.userInput {
    margin-top: 15%;
    width: 100%;
    height: 100%;
}

div#container {
    background: pink;
    height: 100%;
}

div.login {
    background-color: black;
    margin-top: 15%;
    margin-left: auto;
    margin-right: auto;
    height: 10%;
    width: 10%;
    padding: 10px;
}

div.table {
    width: 100%;
    height: 100%;
    background-color: grey;
}

Need my div class="table" after margin-top:15% of table class="userInput" visible with grey background but after offset i can see black color of login div class="login". How to make it grey with margin-top?enter image description here

html css styling
Original Q&A
2

There are 2 answers

1
Raźnyy Raźnyy On 2015-06-23T15:13:12+00:00 23 June 2015 at 15:13 BEST ANSWER

If i understand your question well i suggest you to change

padding:10px;

to

padding-top:10px;

and increase width of <div class='login'> element

EDIT

Your image change almost everything , please check this fiddle : SOLUTION

Only thing i change is remove margin-top:15%; and replace it with padding-top:15%; so i can add background-color:grey; to table.userInput element.

Looks like in your image. Let me know if it helps :)

3
AndrewH AndrewH On 2015-06-23T15:10:14+00:00 23 June 2015 at 15:10

Change margin-top: 15%; to padding-top: 15%;

table.userInput {
    padding-top: 15%;
    width: 100%;
    height: 100%;
}

Based on your picture I think this is what you want.

top padding

http://jsfiddle.net/7j8z3v3w/

Related Questions in HTML

  • How to store a date/time in sqlite (or something similar to a date)
  • How to use custom font during html to pdf conversion?
  • Storing the preferred font-size in localStorage
  • mp4 embedded videos within github pages website not loading
  • Scrimba tutorial was working, suddenly stopped even trying the default
  • Is there any way to glow this bulb image like a real light bulb
  • With non-graphical maps in Leaflet, zoomDelta doesn't work
  • What can I do to improve my coding on both html and css
  • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
  • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
  • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
  • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
  • Storing selected language in localStorage
  • Fences (parenthesis, braces) in HTML and MathML
  • Understanding Scroll Anchoring Behavoir

Related Questions in CSS

  • How to use custom font during html to pdf conversion?
  • Storing the preferred font-size in localStorage
  • mp4 embedded videos within github pages website not loading
  • Is there any way to glow this bulb image like a real light bulb
  • What can I do to improve my coding on both html and css
  • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
  • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
  • How to increase quality of mathjax output?
  • Hover animation resetting( seemingly reverting back to original CSS and then again to hover)when moving mouse horizontaly accross a part of an element
  • Storing selected language in localStorage
  • How to clip grid cell and provide scroll as well?
  • KeyboardAvoidingView makes a messy the flexbox
  • Rotate an object around another object in javascript
  • Understanding Scroll Anchoring Behavoir
  • how to use only block layout in this css code?

Related Questions in STYLING

  • Changing colours of items in FortuneItem in FortuneBar the flutter_fortune_wheel not possible?
  • Unable to click and hover on buttons through Overlay
  • ESlint Plugin That Enforces Function Parameter Names
  • Overriding Mat-Form-Field default Styling
  • Want to change Emotion styled functions based on routing or component rendered
  • How to change the custom border color on Material UI textfield when focused and error classes are on?
  • Anyone has advice on how to go about creating a background color change hover event using tailwind?
  • Inherit Maui.SplashTheme and customize it in MAUI app
  • How to change the background of PrimeNG's p-card component after ngAfterViewInit?
  • Background image not displaying when applied via class with embedded CSS
  • How do I set inline-size in an svg that contains text?
  • MUI React remove outline border on focus
  • styling not working for react-native-wheel-pick
  • Stylex error: adding variables to stylex styling doesnt work
  • Data Labels are being overlapped in a horizontal series Apex Bar chart

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Math
  • Aftereffectstemplates